major-mode-dedication
major-mode-dedication copied to clipboard
Dedicate an emacs major mode to a particular emacs window
- major-mode-dedication
This package lets you dedicate a major mode to a particular emacs window. Any time some elisp uses =display-buffer= or =show-buffer-other-window= to show a buffer with that major mode, that buffer will appear in its dedicated window. This fixes virtually all cases where windows might ordinarily pop up somewhere unexpected when using facilities like help, rgrep, compilation, and so on.
You can dedicate multiple major modes to the same window, and all appropriate buffers will appear in that window (one at a time...). And you can dedicate the same major mode to multiple windows, in which case a sensible window will be chosen each time.
And being based on major mode rather than particular buffer, it can also be useful for things like [[https://github.com/Wilfred/ag.el][ag-mode]] or shell mode (which pop up multiple buffers, all with the same major mode).
** installation
Clone the github repo. Then, in your .emacs, set up =load-path=, =require= the package, and call =mmd-install= (this package isn't a minor mode) to set it up. Something like:
: (add-to-list 'load-path "~/github/major-mode-dedication") : (require 'major-mode-dedication) : (mmd-install)
=mmd-install= tries to set up a special major-mode-dedication keymap with the prefix =C-x D=. If this key combo is already used, it does nothing, in which case I'm afraid you're on your own.
** use (interactive)
When you've got a buffer of a particular mode displayed in a window where you like it, do =M-x mmd-set-major-mode-window-dedication=, or =C-x D D=. This will dedicate that window to buffers with that major mode. (To remove the dedication, use a prefix argument - =C-u C-x D D=.)
To associate a window with buffers of some other major mode, use =M-x mmd-set-major-mode-window-dedication-by-name=, or =C-x D N=. Select the mode from the list (major-mode-dedication will try to find all functions that look like they might be major modes), or enter the name by hand.
You can "dedicate" a window to more than one major mode - this just means multiple types of buffer will appear in the same window, each one hiding the one that was previously shown there.
You can use =M-x mmd-show-major-mode-window-dedication=, or =C-x D S=, to show the current window's major mode dedication as a message.
** use (elisp)
Call =mmd-add-major-mode-window-dedication=, and =mmd-remove-major-mode-window-dedication= to adjust the current window's major modes list. Both take a major mode name and a window, and add (or remove) the major mode to the window's list.
Call =mmd-reset-major-mode-window-dedication= to clear the current window's major modes list.
These are intended for use in functions that set up some kind of standard window arrangement.
** open issues
-
If you pop up a buffer that's dedicated to a window in another frame, and that frame is obscured, you don't see anything. There must be something better that could be done.
-
Probably many others that I haven't found yet/have just become used to...