Author: Alp Aker
Updated:
A minor mode for frame-relative buffer lists
Locales extends Emacs's buffer menu so that it understands a distinction between those buffers that "belong" to a frame and those that do not. The buffer menu can be toggled between a list of all buffers and a list of only buffers that are local to a frame. Buffers can be added to and removed from the frame-local buffer list from within or outside the buffer menu. The criteria for which buffers belong to a frame can be customized. Installation ============ Put this file in your load path and put: (require 'locales) in your .emacs. To toggle locales mode on and off, use the command `locales-mode'. To turn it on automatically when starting Emacs, put: (locales-mode t) in your .emacs. Usage ===== Locales operates fairly transparently. By default a new buffer-menu initially lists only buffers local to the selected frame (we call this "local mode"). By typing `a' one can toggle between listing only local buffers and listing all buffers (we call the latter "global mode"). In global mode, there is a fourth column in the buffer menu after the C, R, M columns: the L column. Buffers local to the current frame are indicated with an `o' in this column (this indicator bit can be changed via `Buffer-menu-local-bit'). In local mode, the fourth column is suppressed. The variable `Buffer-menu-open-in-global-mode' can be used to control whether the buffer menu opens in local or global mode. All commands available in the default buffer menu are still available, including sorting by buffer name, buffer size, etc., or toggling files-only. In addition to toggling between local and global modes, two other new commands are available in the buffer menu. By typing `]' a file can be marked as to be added to the local buffer list. By typing `[' a file can be marked as to be removed from the local buffer list. As with other actions in the buffer menu, these changes take effect when `Buffer-menu-execute' is called. When a buffer is made non-local, it is removed from any windows on the current frame displaying it and replaced with another frame-local buffer. Buffers can also be made non-local outside the buffer menu. The command `locales-make-non-local' can be called interactively to remove a buffer from the local buffer list; when called with no argument, it acts on the current buffer. Locales does not, by default, bind this command to any key-sequence. To bind it to, e.g, C-c [, add the following two forms to your .emacs: (add-hook 'locales-mode-on-hook (global-set-key [(control ?c) ?\[] 'locales-make-non-local)) (add-hook 'locales-mode-off-hook (global-set-key [(control ?c) ?\[] 'undefined)) Criteria That Control the Local Buffer List =========================================== The association between buffers and frames is dynamic: if a buffer is selected on a frame, then it is considered to be local to the frame. (Note, then, that a buffer can be local to more than one frame.) In addition, several other criteria can be used to control the membership of a frame's local buffer list: o If `locales-include-scratch' is non-nil, then *scratch* always belongs to the local buffer list. o If `locales-include-displayed-buffers' is non-nil, then buffers that are merely displayed on a frame are considered to be local to the frame, even if they have not been selected. o Three variables control which buffers are local to a newly created frame: - `locales-new-frames-inherit': If non-nil, a new frame's local buffer list includes (at least) the buffers that were local to the frame from which the new frame was created. - `locales-include-new-buffers': If non-nil, and the command that creates a new frame also creates new buffers, the new buffers belong to the new frame. (This applies only to buffers that are created *after* the new frame is created.) - `locales-include-init-buffer': If non-nil, then the buffer that is current when the command creating a new frame is called will belong to the new frame. If nil, it will not--unless locales-new-frames-inherit is non-nil. (NB: If the buffer in question is displayed on the new frame when the frame-creating command terminates, it will still belong to the new frame's local list.) Compatibility with Other Features ================================= Locales is compatible with buff-menu+, as long as buff-menu+ is loaded first. Locales does not touch the buffer-list or buried-buffer-list frame parameters, nor change the results of any call to the function `buffer-list'. (There is one exception to this rule: If the buffer menu is automatically displayed on another frame [e.g., when `pop-up-frames' is non-nil], then the frame used to display the buffer menu has its buffer-list and buried-buffer-list set to those of the frame from which the buffer-menu command is called.) The package sets each frame's buffer predicate so that `other-buffer' will prefer buffers local to the frame; if another buffer predicate is present when the package is enabled, locales saves that predicate and uses it as well. If you wish to access a frame's local buffer list directly for some purpose, it is recommended that you use the list returned by the function `locales-buffer-list'; don't use the value of the locales-buffer-list frame parameter. The latter can contain internal buffers (buffers whose names starts with a space) and dead buffers; it is not guaranteed to respect `locales-include-scratch'; and its order is meaningless. The list returned by `locales-buffer-list' will contain only live, non-internal buffers, include *scratch* if necessary, and be sorted stably by selection order on the current frame.