Even if the automatic generation of the buffer menu is a bit complicated the method to add menu items to the buffer menu is quite simple.
Just add them with
menu-mode is loaded. The general scheme is:
(easy-menu-add-item nil '("Buffers") ITEM)
ITEM stands for the item you want to add (see the doc for easy-menu-define for the syntax of
The interpretation of the menu entries you specified in your question is a bit difficult.
I interpret these entries as follows:
- Open new window below current buffer: Split the selected window, select the lower window of the split, and find a file in that window.
- Split window: This is pretty clear:
- Close current buffer:
The following lisp code demonstrates adding menu items to the buffer menu according to your specification (as I interpret it).
You can copy-paste the code into your init file.
(declare-function find-file-window-below-selected "ext: ")
(easy-menu-add-item nil '("Buffers") ["Find file below selected window" find-file-window-below-selected t])
(easy-menu-add-item nil '("Buffers") ["Split window" split-window t])
(easy-menu-add-item nil '("Buffers") ["Kill buffer" kill-buffer t])))
(defun find-file-window-below-selected (filename &optional wildcards)
"Like `find-file' with args FILENAME and WILDCARDS.
Split window before vertically and display the new file buffer in the
(interactive (find-file-read-args "Find file in new window: "
(find-file filename wildcards))
Last but not least a short motivation why this method works:
The buffer menu commands are listed in the variable
That list is populated by the function
menu-bar-update-buffers if it is not set yet.
menu-bar-buffers-menu-command-entries is appended to
menu-bar-buffers-menu-command-entries is not copied but just appended.
Therefore items which you define via
easy-menu-add-item at the end of
global-buffers-menu-map end up in
The value of
menu-bar-buffers-menu-command-entries is set when
menu-bar-update-buffers is called at loading
menu-bar.el[c]?. It is not reset afterwards and always appended to the automatically generated buffer menu.