2

I've been using Elfeed for some time, and I like it very much. However, there is one small thing I'd like to adjust. When leaving the search window (with elfeed-search-quit-window bound to q in the mode map), Elfeed leaves a trail of open buffers: *elfeed-search*, *elfeed-log* and myfeeds.org (I use elfeed-org).

I like the behavior of org-agenda-exit which checks if any files visited by the agenda have been modified, if so offers to save them, and otherwise kills them. As it turns out, this is performed by the function org-release-buffers in org.el, so I tried to adapt it for my purposes.

As I don't have a list of buffers, as Org Agenda does, I tried to use rmh-elfeed-org-files which is rather a list of files, so I employ file-name-nondirectory to get the corresponding buffer name.

My unsuccessful attempt is the following:

(defun my/elfeed-search-quit-and-kill-buffers ()
  "Save the database, then kill elfeed buffers, asking the user
for confirmation when needed."
  (interactive)
  (elfeed-db-save)
  (let (buf)
    (dolist (file rmh-elfeed-org-files)
      (setq buf (file-name-nondirectory file))
      (when (and (buffer-modified-p buf)
         file
         (y-or-n-p (format "Save file %s? " file)))
    (with-current-buffer buf (save-buffer)))
      (kill-buffer buf)))
  (kill-buffer "*elfeed-log*")
  (kill-buffer (current-buffer)))

As this is intended to be bound to the elfeed-search-mode-map the last (kill-buffer (current-buffer)) kills *elfeed-search*.

But this fails with a Wrong type argument: bufferp, "myfeeds.org" error.

What am I doing wrong?

  • 1
    If you have a buffer-name, rather than an object buffer, and if you need the latter, then you can convert the buffer-name to an object buffer with get-buffer. E.g., (get-buffer "myfeeds.org") will return the object buffer. Some functions have the ability to use either form; however, your error message is telling you that a string buffer name is not what is sought. I don't use elfeed, but if I had to guess, I would guess ... (setq buf (get-buffer (file-name-nondirectory file))) assuming that (file-name-nondirectory file) will give you the string name for the buffer. – lawlist Oct 21 '18 at 0:10
  • 1
    @lawlist Coincidentally, I had figured that out just a couple of minutes ago. (Out of luck, I admit). I just got it to work with (setq buf (get-file-buffer file)). Still, thank you for your comment. And an answer of yours in these lines would be welcome and accepted. – gusbrs Oct 21 '18 at 0:18
0

As @lawlist explained in his/her comment, Emacs distinguishes the buffer's name from the buffer itself. And (file-name-nondirectory file) got me the buffer's name, not the object. Things worked fine when this was corrected with (setq buf (get-file-buffer file)). In full:

(defun my/elfeed-search-quit-and-kill-buffers ()
  "Save the database, then kill elfeed buffers, asking the user
for confirmation when needed."
  (interactive)
  (elfeed-db-save)
  (let (buf)
    (dolist (file rmh-elfeed-org-files)
      (setq buf (get-file-buffer file))
      (when (and (buffer-modified-p buf)
             file
             (y-or-n-p (format "Save file %s? " file)))
        (with-current-buffer buf (save-buffer)))
      (kill-buffer buf)))
  (kill-buffer "*elfeed-log*")
  (kill-buffer (current-buffer)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.