0

I have a lisp function that relies on other-buffer which refers to buffer-list. Calling previous-buffer on a window does not update the buffer-list so it breaks the function.

How do make it so previous-buffer updates buffer-list?

reference

edit

I have the following lisp function that toggles to eshell with current directory set to the file I am viewing and from eshell back to the previous file.

(defun eshell-here ()
  "Go to eshell and set current directory to the buffer's directory.
   If already on eshell, go to last buffer"
  (interactive)
  (if (equal major-mode 'eshell-mode)
      (switch-to-buffer (other-buffer (current-buffer) nil))
    (let ((dir (file-name-directory (or (buffer-file-name)
                                       default-directory))))
      (eshell)
      (if (not (equal (expand-file-name (concat (eshell/pwd) "/"))
                      (expand-file-name dir)))
          (progn
            (eshell/pushd ".")
            (cd dir)
            (goto-char (point-max))
            (eshell-kill-input)
            (eshell-send-input))))))

(global-set-key (kbd "<f1>") 'eshell-here)

The call to other-buffer relies on the most recently viewed buffer which is stored in the buffer-list.

previous-buffer and next-buffer does not update the buffer-list so I lose the ability to get back to the file I was viewing from eshell.

The solution I have come up with is to call switch-to-buffer after previous-buffer/next-buffer to indirectly update the buffer list.

Do you think there is a better solution?

  • Please specify what you mean by "does not update the buffer-list" and, more importantly, what you would want to happen instead. What is the ultimate behavior that you want? So far, this looks like an X Y problem. – Drew May 3 '17 at 13:37
  • @Drew I would like to be able to get back to the buffer I was viewing with previous-buffer along with the call to other-buffer. – Kevin May 4 '17 at 2:06
0

Seems buffer-list cannot be directly manipulated so modified previous-buffer to call (switch-to-buffer (buffer-name)) to indirectly update the buffer-list.

  • Note that if you only care about interactive calls to previous-buffer then you should remap the bindings for that command to a new custom command which does what you want. e.g. (define-key KEYMAP [remap previous-buffer] 'my-previous-buffer) – phils May 3 '17 at 12:43

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.