Emacs: Split window with different buffer
It’s common to split windows while working in emacs. By default, whenever we
split windows in emacs the newly created window will also have the same
buffer(same buffer in two windows). So it is always needed
to change to another buffer by
C-x b after splitting it.
We can customize it by little elisp code as below.
put the below code in either
~/.emacs file or
init.el file in
All this code does is pretty straight forward.
lexical-let needs common lisp libraries.
(eval-when-compile (require 'cl)) does.
'split-function' is an argument which will be default elisp split function.
(funcall s-f) we call the default split function then using
(set-window-buffer)elisp function we change the buffer of newly
(next-window) with different buffer
Also rebind the default split keys
C-x3(vertical) to our
new custom split function.
'split-window-horizontally' are default
elisp split functions which we pass as argument to our new custom split
I got this code from here (I am not elisp master. Well! atleast not yet 😜). Thanks to Purcell. In fact his .emacs.d is well organised and very good resource to learn how to customize emacs and he is also helpful via mail 😊.
I also found this tutorial is very helpful in getting started on Emacs lisp.
Happy hacking emacs!! 👍✌.