In Emacs how can I go back to the last buffer I was editing in ELisp?

  • 1
    Can you give a little context about what you're trying to do? There are a bunch of different ways to do what you want but they depend on the bigger picture... – Joe Casadonte Dec 20 '10 at 18:51

If you changed the buffer in ELisp code, the proper way to go back to the previous buffer is to use save-excursion or save-current-buffer:

;; do stuff in buffer1
  (set-buffer "buffer2")
  ;; do stuff in buffer2
;; more stuff in buffer1

In Emacs you would type Ctrl-x b to do that, so to find the Elisp function, type Ctrl-h k followed by Ctrl-x b and you'll get:

[...] (switch-to-buffer BUFFER-OR-NAME &optional NORECORD)

Make BUFFER-OR-NAME current and display it in selected window. BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil. Return the buffer switched to. [...]

which should do what you want ;)

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.