Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs buffer shown after closing a buffer

Tags:

emacs

How can I modify the way emacs picks which buffer to show after closing a buffer?

When I have multiple columns showing the same buffer, and then open another file in one of the buffers and then close the newly opened buffer, it doesn't switch back to the previous buffer, but to another buffer.

I'll try to explain with an example:

  • Start with a new emacs at *scratch*
  • C-x 2 (split into two columns)
  • C-x C-f 1 (find file 1)
  • C-x o (switch to other frame)
  • C-x b 1 (find file 1)
  • C-x C-f 2 (find file 2)
  • C-x k (kill buffer)

Now it switches to scratch but I would like it to show 1 in both windows again, is it possible to make emacs behave this way?

like image 803
Puppe Avatar asked May 20 '11 05:05

Puppe


1 Answers

This may not be a direct answer to your question, but it might help.

Emacs manages its buffer list, including deciding which buffer gets displayed when you kill one (via kill-buffer). I haven't looked into how it's done, but the documentation is "out there". Lots of people have created custom buffer-stack management magic to change the way emacs does things, maybe some of them are based on bayesian analysis, or whatever. You can imagine the possibilities.

I've never looked into changing the way emacs manages its buffers. Instead I just bind other-window and switch-to-buffer to easy keystrokes (C-x o, C-x b) and I get really good at using them.

you could create a simple function for what you want: it should destroys all other windows, then split the window so that the current buffer is displayed in both. Luckily, emacs has functions that do exactly those things.

(defun cheeso-show-buffer-two-windows ()
  "Close all other windows; then split, and show the current
buffer in both windows."
  (interactive)
  (delete-other-windows)
  (split-window-vertically))

Bind that to a keystroke, and badda-bing, you're there. This is a vertical split - the windows are displayed in a vertical stack. If you want it horizontally split (the windows are side-by-side), then replace ... well, you know.

like image 200
Cheeso Avatar answered Dec 13 '22 05:12

Cheeso