I would like to obtain a list of files that ask me at the end of emacs, "Are you okay with any changes?"

Asked 2 years ago, Updated 2 years ago, 105 views

"Save file XXXXXX (OPTIONS)" will be displayed at the end of emacs when the file is not edited and saved."Rather than confirming whether to save or not by displaying them one by one, I thought, ""I would like to check this list in advance and kill it as it is if necessary."""

Can I list the files (buffers that are visiting) that ask me if I want to save at the end and do various operations (at least select that buffer)?

emacs

2022-09-30 17:10

2 Answers

Is it like this?

 (defun user/buffer-needs-save-p (buffer)
  "Return non-nil if the visited-file BUFFER is still modified."
  (and (buffer-file-name buffer)
       (buffer-modified-p buffer))

;; process unsaved buffers
(dolist(b(buffer-list))
  (when (user/buffer-needs-save-pb)
    ...))

Looking at the Emacs source code (1, 2), elisp did not seem to provide a function to determine if it needs to be saved.


2022-09-30 17:10

"Based on @kosh's answer, I tried ""list display"" and it was as follows." (The keybind is not good enough, but for now.)

 (defun user/buffer-needs-save-p (buffer)
  "Return non-nil if the visited-file BUFFER is still modified."
  (and (buffer-file-name buffer)
       (buffer-modified-p buffer))

;; process unsaved buffers

(defun modified-buffer-list()
  (interactive)
  (let(ret)
    (dolist(b(buffer-list))
      (when (user/buffer-needs-save-pb)
        (setqret(consbret)))
    (switch-to-buffer (list-buffers-noselect nil ret)))


2022-09-30 17:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.