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

link|improve this question

65% accept rate
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
feedback

2 Answers

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
(save-excusion
  (set-buffer "buffer2")
  ;; do stuff in buffer2
  )
;; more stuff in buffer1
link|improve this answer
feedback

In emacs you would do "Ctrl-x b" to do that, so to find the Elisp function, do "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 ;)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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