1994-12-23 17:58:46 +00:00
|
|
|
;;; msb.el --- Customizable buffer-selection with multiple menus.
|
1996-01-14 07:34:30 +00:00
|
|
|
|
2001-01-29 21:23:13 +00:00
|
|
|
;; Copyright (C) 1993, 94, 95, 97, 98, 99, 2000, 2001
|
|
|
|
;; Free Software Foundation, Inc.
|
1996-01-14 07:34:30 +00:00
|
|
|
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Author: Lars Lindberg <Lars.G.Lindberg@capgemini.se>
|
1999-07-23 22:57:32 +00:00
|
|
|
;; Maintainer: FSF
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Created: 8 Oct 1993
|
1998-02-15 16:45:52 +00:00
|
|
|
;; Lindberg's last update version: 3.34
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Keywords: mouse buffer menu
|
1996-01-14 07:34:30 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
1994-12-23 17:58:46 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
1996-01-14 07:34:30 +00:00
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
1994-12-23 17:58:46 +00:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
1996-01-14 07:34:30 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
1996-01-14 07:34:30 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Purpose of this package:
|
|
|
|
;; 1. Offer a function for letting the user choose buffer,
|
|
|
|
;; not necessarily for switching to it.
|
1999-05-31 14:49:05 +00:00
|
|
|
;; 2. Make a better mouse-buffer-menu. This is done as a global
|
|
|
|
;; minor mode, msb-mode.
|
1994-12-23 17:58:46 +00:00
|
|
|
;;
|
|
|
|
;; Customization:
|
1994-12-24 16:47:58 +00:00
|
|
|
;; Look at the variable `msb-menu-cond' for deciding what menus you
|
|
|
|
;; want. It's not that hard to customize, despite my not-so-good
|
|
|
|
;; doc-string. Feel free to send me a better doc-string.
|
1994-12-23 17:58:46 +00:00
|
|
|
;; There are some constants for you to try here:
|
|
|
|
;; msb--few-menus
|
|
|
|
;; msb--very-many-menus (default)
|
1998-02-15 16:45:52 +00:00
|
|
|
;;
|
1994-12-24 16:47:58 +00:00
|
|
|
;; Look at the variable `msb-item-handling-function' for customization
|
|
|
|
;; of the appearance of every menu item. Try for instance setting
|
|
|
|
;; it to `msb-alon-item-handler'.
|
1997-12-22 02:26:17 +00:00
|
|
|
;;
|
1994-12-24 16:47:58 +00:00
|
|
|
;; Look at the variable `msb-item-sort-function' for customization
|
|
|
|
;; of sorting the menus. Set it to t for instance, which means no
|
1994-12-23 17:58:46 +00:00
|
|
|
;; sorting - you will get latest used buffer first.
|
|
|
|
;;
|
1994-12-24 16:47:58 +00:00
|
|
|
;; Also check out the variable `msb-display-invisible-buffers-p'.
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;; Known bugs:
|
1995-01-09 22:16:23 +00:00
|
|
|
;; - Files-by-directory
|
1995-02-24 09:12:56 +00:00
|
|
|
;; + No possibility to show client/changed buffers separately.
|
1998-02-15 16:45:52 +00:00
|
|
|
;; + All file buffers only appear in a file sub-menu, they will
|
1995-02-24 09:12:56 +00:00
|
|
|
;; for instance not appear in the Mail sub-menu.
|
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Future enhancements:
|
|
|
|
|
|
|
|
;;; Thanks goes to
|
1995-02-24 09:12:56 +00:00
|
|
|
;; Mark Brader <msb@sq.com>
|
|
|
|
;; Jim Berry <m1jhb00@FRB.GOV>
|
|
|
|
;; Hans Chalupsky <hans@cs.Buffalo.EDU>
|
|
|
|
;; Larry Rosenberg <ljr@ictv.com>
|
|
|
|
;; Will Henney <will@astroscu.unam.mx>
|
|
|
|
;; Jari Aalto <jaalto@tre.tele.nokia.fi>
|
|
|
|
;; Michael Kifer <kifer@sbkifer.cs.sunysb.edu>
|
|
|
|
;; Gael Marziou <gael@gnlab030.grenoble.hp.com>
|
|
|
|
;; Dave Gillespie <daveg@thymus.synaptics.com>
|
|
|
|
;; Alon Albert <alon@milcse.rtsg.mot.com>
|
|
|
|
;; Kevin Broadey, <KevinB@bartley.demon.co.uk>
|
|
|
|
;; Ake Stenhof <ake@cadpoint.se>
|
1999-08-16 04:04:27 +00:00
|
|
|
;; Richard Stallman <rms@gnu.org>
|
1995-02-24 09:12:56 +00:00
|
|
|
;; Steve Fisk <fisk@medved.bowdoin.edu>
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1999-07-28 16:46:30 +00:00
|
|
|
;; This version turned into a global minor mode and subsequently
|
|
|
|
;; hacked on by Dave Love.
|
1994-12-23 17:58:46 +00:00
|
|
|
;;; Code:
|
|
|
|
|
1999-07-28 16:46:30 +00:00
|
|
|
(eval-when-compile (require 'cl))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;;;
|
1994-12-24 16:47:58 +00:00
|
|
|
;;; Some example constants to be used for `msb-menu-cond'. See that
|
|
|
|
;;; variable for more information. Please note that if the condition
|
|
|
|
;;; returns `multi', then the buffer can appear in several menus.
|
1994-12-23 17:58:46 +00:00
|
|
|
;;;
|
|
|
|
(defconst msb--few-menus
|
|
|
|
'(((and (boundp 'server-buffer-clients)
|
|
|
|
server-buffer-clients
|
|
|
|
'multi)
|
|
|
|
3030
|
|
|
|
"Clients (%d)")
|
|
|
|
((and msb-display-invisible-buffers-p
|
|
|
|
(msb-invisible-buffer-p)
|
|
|
|
'multi)
|
|
|
|
3090
|
|
|
|
"Invisible buffers (%d)")
|
|
|
|
((eq major-mode 'dired-mode)
|
|
|
|
2010
|
|
|
|
"Dired (%d)"
|
|
|
|
msb-dired-item-handler
|
|
|
|
msb-sort-by-directory)
|
|
|
|
((eq major-mode 'Man-mode)
|
|
|
|
4090
|
|
|
|
"Manuals (%d)")
|
|
|
|
((eq major-mode 'w3-mode)
|
|
|
|
4020
|
|
|
|
"WWW (%d)")
|
2000-08-15 11:19:13 +00:00
|
|
|
((or (memq major-mode
|
|
|
|
'(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode))
|
|
|
|
(memq major-mode '(mh-letter-mode mh-show-mode mh-folder-mode))
|
|
|
|
(memq major-mode
|
|
|
|
'(gnus-summary-mode message-mode gnus-group-mode
|
|
|
|
gnus-article-mode score-mode gnus-browse-killed-mode)))
|
1994-12-23 17:58:46 +00:00
|
|
|
4010
|
|
|
|
"Mail (%d)")
|
|
|
|
((not buffer-file-name)
|
|
|
|
4099
|
|
|
|
"Buffers (%d)")
|
|
|
|
('no-multi
|
|
|
|
1099
|
|
|
|
"Files (%d)")))
|
|
|
|
|
|
|
|
(defconst msb--very-many-menus
|
|
|
|
'(((and (boundp 'server-buffer-clients)
|
|
|
|
server-buffer-clients
|
|
|
|
'multi)
|
|
|
|
1010
|
|
|
|
"Clients (%d)")
|
|
|
|
((and (boundp 'vc-mode) vc-mode 'multi)
|
|
|
|
1020
|
|
|
|
"Version Control (%d)")
|
|
|
|
((and buffer-file-name
|
|
|
|
(buffer-modified-p)
|
|
|
|
'multi)
|
|
|
|
1030
|
|
|
|
"Changed files (%d)")
|
|
|
|
((and (get-buffer-process (current-buffer))
|
|
|
|
'multi)
|
|
|
|
1040
|
|
|
|
"Processes (%d)")
|
|
|
|
((and msb-display-invisible-buffers-p
|
|
|
|
(msb-invisible-buffer-p)
|
|
|
|
'multi)
|
|
|
|
1090
|
1997-12-22 02:26:17 +00:00
|
|
|
"Invisible buffers (%d)")
|
1994-12-23 17:58:46 +00:00
|
|
|
((eq major-mode 'dired-mode)
|
|
|
|
2010
|
|
|
|
"Dired (%d)"
|
|
|
|
;; Note this different menu-handler
|
|
|
|
msb-dired-item-handler
|
|
|
|
;; Also note this item-sorter
|
|
|
|
msb-sort-by-directory)
|
|
|
|
((eq major-mode 'Man-mode)
|
1998-02-15 16:45:52 +00:00
|
|
|
5030
|
1994-12-23 17:58:46 +00:00
|
|
|
"Manuals (%d)")
|
|
|
|
((eq major-mode 'w3-mode)
|
1998-02-15 16:45:52 +00:00
|
|
|
5020
|
1994-12-23 17:58:46 +00:00
|
|
|
"WWW (%d)")
|
2000-08-15 11:19:13 +00:00
|
|
|
((or (memq major-mode
|
|
|
|
'(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode))
|
|
|
|
(memq major-mode '(mh-letter-mode mh-show-mode mh-folder-mode))
|
|
|
|
(memq major-mode '(gnus-summary-mode message-mode gnus-group-mode
|
|
|
|
gnus-article-mode score-mode
|
1994-12-23 17:58:46 +00:00
|
|
|
gnus-browse-killed-mode)))
|
1998-02-15 16:45:52 +00:00
|
|
|
5010
|
1994-12-23 17:58:46 +00:00
|
|
|
"Mail (%d)")
|
|
|
|
;; Catchup for all non-file buffers
|
|
|
|
((and (not buffer-file-name)
|
|
|
|
'no-multi)
|
1998-02-15 16:45:52 +00:00
|
|
|
5099
|
1994-12-23 17:58:46 +00:00
|
|
|
"Other non-file buffers (%d)")
|
|
|
|
((and (string-match "/\\.[^/]*$" buffer-file-name)
|
|
|
|
'multi)
|
|
|
|
3090
|
|
|
|
"Hidden Files (%d)")
|
|
|
|
((memq major-mode '(c-mode c++-mode))
|
|
|
|
3010
|
|
|
|
"C/C++ Files (%d)")
|
|
|
|
((eq major-mode 'emacs-lisp-mode)
|
|
|
|
3020
|
|
|
|
"Elisp Files (%d)")
|
|
|
|
((eq major-mode 'latex-mode)
|
|
|
|
3030
|
|
|
|
"LaTex Files (%d)")
|
|
|
|
('no-multi
|
|
|
|
3099
|
|
|
|
"Other files (%d)")))
|
|
|
|
|
|
|
|
;; msb--many-menus is obsolete
|
|
|
|
(defvar msb--many-menus msb--very-many-menus)
|
|
|
|
|
|
|
|
;;;
|
|
|
|
;;; Customizable variables
|
|
|
|
;;;
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defgroup msb nil
|
|
|
|
"Customizable buffer-selection with multiple menus."
|
|
|
|
:prefix "msb-"
|
|
|
|
:group 'mouse)
|
|
|
|
|
|
|
|
(defun msb-custom-set (symbol value)
|
|
|
|
"Set the value of custom variables for msb."
|
|
|
|
(set symbol value)
|
1999-07-23 22:57:32 +00:00
|
|
|
(if (and (featurep 'msb) msb-mode)
|
1998-02-15 16:45:52 +00:00
|
|
|
;; wait until package has been loaded before bothering to update
|
|
|
|
;; the buffer lists.
|
1999-07-23 22:57:32 +00:00
|
|
|
(msb-menu-bar-update-buffers t)))
|
1998-02-15 16:45:52 +00:00
|
|
|
|
|
|
|
(defcustom msb-menu-cond msb--very-many-menus
|
|
|
|
"*List of criteria for splitting the mouse buffer menu.
|
|
|
|
The elements in the list should be of this type:
|
|
|
|
(CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLING-FN ITEM-SORT-FN).
|
|
|
|
|
|
|
|
When making the split, the buffers are tested one by one against the
|
1999-05-31 14:49:05 +00:00
|
|
|
CONDITION, just like a Lisp cond: When hitting a true condition, the
|
1998-02-15 16:45:52 +00:00
|
|
|
other criteria are *not* tested and the buffer name will appear in the
|
|
|
|
menu with the menu-title corresponding to the true condition.
|
|
|
|
|
|
|
|
If the condition returns the symbol `multi', then the buffer will be
|
|
|
|
added to this menu *and* tested for other menus too. If it returns
|
|
|
|
`no-multi', then the buffer will only be added if it hasn't been added
|
|
|
|
to any other menu.
|
|
|
|
|
|
|
|
During this test, the buffer in question is the current buffer, and
|
|
|
|
the test is surrounded by calls to `save-excursion' and
|
|
|
|
`save-match-data'.
|
|
|
|
|
|
|
|
The categories are sorted by MENU-SORT-KEY. Smaller keys are on top.
|
|
|
|
nil means don't display this menu.
|
|
|
|
|
|
|
|
MENU-TITLE is really a format. If you add %d in it, the %d is
|
|
|
|
replaced with the number of items in that menu.
|
|
|
|
|
|
|
|
ITEM-HANDLING-FN, is optional. If it is supplied and is a function,
|
|
|
|
than it is used for displaying the items in that particular buffer
|
|
|
|
menu, otherwise the function pointed out by
|
|
|
|
`msb-item-handling-function' is used.
|
|
|
|
|
|
|
|
ITEM-SORT-FN, is also optional.
|
|
|
|
If it is not supplied, the function pointed out by
|
|
|
|
`msb-item-sort-function' is used.
|
|
|
|
If it is nil, then no sort takes place and the buffers are presented
|
|
|
|
in least-recently-used order.
|
|
|
|
If it is t, then no sort takes place and the buffers are presented in
|
|
|
|
most-recently-used order.
|
|
|
|
If it is supplied and non-nil and not t than it is used for sorting
|
|
|
|
the items in that particular buffer menu.
|
|
|
|
|
|
|
|
Note1: There should always be a `catch-all' as last element, in this
|
|
|
|
list. That is an element like (t TITLE ITEM-HANDLING-FUNCTION).
|
|
|
|
Note2: A buffer menu appears only if it has at least one buffer in it.
|
|
|
|
Note3: If you have a CONDITION that can't be evaluated you will get an
|
|
|
|
error every time you do \\[msb]."
|
|
|
|
:type `(choice (const :tag "long" :value ,msb--very-many-menus)
|
2000-05-18 18:41:46 +00:00
|
|
|
(const :tag "short" :value ,msb--few-menus)
|
|
|
|
(sexp :tag "user"))
|
1998-02-15 16:45:52 +00:00
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
|
|
|
|
|
|
|
(defcustom msb-modes-key 4000
|
|
|
|
"The sort key for files sorted by mode."
|
|
|
|
:type 'integer
|
|
|
|
:set 'msb-custom-set
|
1998-04-20 03:35:05 +00:00
|
|
|
:group 'msb
|
|
|
|
:version "20.3")
|
1998-02-15 16:45:52 +00:00
|
|
|
|
|
|
|
(defcustom msb-separator-diff 100
|
1994-12-23 17:58:46 +00:00
|
|
|
"*Non-nil means use separators.
|
1997-12-22 02:26:17 +00:00
|
|
|
The separators will appear between all menus that have a sorting key
|
1998-02-15 16:45:52 +00:00
|
|
|
that differs by this value or more."
|
|
|
|
:type '(choice integer (const nil))
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
(defvar msb-files-by-directory-sort-key 0
|
1997-12-22 02:26:17 +00:00
|
|
|
"*The sort key for files sorted by directory.")
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-max-menu-items 15
|
1994-12-23 17:58:46 +00:00
|
|
|
"*The maximum number of items in a menu.
|
1997-12-22 02:26:17 +00:00
|
|
|
If this variable is set to 15 for instance, then the submenu will be
|
1998-02-15 16:45:52 +00:00
|
|
|
split up in minor parts, 15 items each. Nil means no limit."
|
|
|
|
:type '(choice integer (const nil))
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-max-file-menu-items 10
|
1994-12-23 17:58:46 +00:00
|
|
|
"*The maximum number of items from different directories.
|
|
|
|
|
1994-12-24 16:47:58 +00:00
|
|
|
When the menu is of type `file by directory', this is the maximum
|
1996-01-04 23:45:49 +00:00
|
|
|
number of buffers that are clumped together from different
|
1994-12-23 17:58:46 +00:00
|
|
|
directories.
|
|
|
|
|
1995-01-09 22:16:23 +00:00
|
|
|
Set this to 1 if you want one menu per directory instead of clumping
|
|
|
|
them together.
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
If the value is not a number, then the value 10 is used."
|
|
|
|
:type 'integer
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-most-recently-used-sort-key -1010
|
|
|
|
"*Where should the menu with the most recently used buffers be placed?"
|
|
|
|
:type 'integer
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-display-most-recently-used 15
|
1994-12-23 17:58:46 +00:00
|
|
|
"*How many buffers should be in the most-recently-used menu.
|
1998-02-15 16:45:52 +00:00
|
|
|
No buffers at all if less than 1 or nil (or any non-number)."
|
|
|
|
:type 'integer
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
|
|
|
|
|
|
|
(defcustom msb-most-recently-used-title "Most recently used (%d)"
|
|
|
|
"*The title for the most-recently-used menu."
|
|
|
|
:type 'string
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1997-12-22 02:26:17 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(defvar msb-horizontal-shift-function '(lambda () 0)
|
1997-12-22 02:26:17 +00:00
|
|
|
"*Function that specifies how many pixels to shift the top menu leftwards.")
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-display-invisible-buffers-p nil
|
1994-12-23 17:58:46 +00:00
|
|
|
"*Show invisible buffers or not.
|
|
|
|
Non-nil means that the buffer menu should include buffers that have
|
1998-02-15 16:45:52 +00:00
|
|
|
names that starts with a space character."
|
|
|
|
:type 'boolean
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
(defvar msb-item-handling-function 'msb-item-handler
|
|
|
|
"*The appearance of a buffer menu.
|
|
|
|
|
|
|
|
The default function to call for handling the appearance of a menu
|
1994-12-24 16:47:58 +00:00
|
|
|
item. It should take to arguments, BUFFER and MAX-BUFFER-NAME-LENGTH,
|
1994-12-23 17:58:46 +00:00
|
|
|
where the latter is the max length of all buffer names.
|
1995-01-09 22:16:23 +00:00
|
|
|
|
|
|
|
The function should return the string to use in the menu.
|
|
|
|
|
1997-12-22 02:26:17 +00:00
|
|
|
When the function is called, BUFFER is the current buffer. This
|
|
|
|
function is called for items in the variable `msb-menu-cond' that have
|
|
|
|
nil as ITEM-HANDLING-FUNCTION. See `msb-menu-cond' for more
|
1994-12-23 17:58:46 +00:00
|
|
|
information.")
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defcustom msb-item-sort-function 'msb-sort-by-name
|
1994-12-23 17:58:46 +00:00
|
|
|
"*The order of items in a buffer menu.
|
1997-12-22 02:26:17 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
The default function to call for handling the order of items in a menu
|
1997-12-22 02:26:17 +00:00
|
|
|
item. This function is called like a sort function. The items look
|
|
|
|
like (ITEM-NAME . BUFFER).
|
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
ITEM-NAME is the name of the item that will appear in the menu.
|
|
|
|
BUFFER is the buffer, this is not necessarily the current buffer.
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
Set this to nil or t if you don't want any sorting (faster)."
|
|
|
|
:type '(choice (const msb-sort-by-name)
|
|
|
|
(const :tag "Newest first" t)
|
|
|
|
(const :tag "Oldest first" nil))
|
|
|
|
:set 'msb-custom-set
|
2000-08-15 11:19:13 +00:00
|
|
|
:group 'msb)
|
1998-02-15 16:45:52 +00:00
|
|
|
|
|
|
|
(defcustom msb-files-by-directory nil
|
1999-05-31 14:49:05 +00:00
|
|
|
"*Non-nil means that files should be sorted by directory.
|
|
|
|
This is instead of the groups in `msb-menu-cond'."
|
1998-02-15 16:45:52 +00:00
|
|
|
:type 'boolean
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
2000-11-03 22:29:27 +00:00
|
|
|
(defcustom msb-after-load-hook nil
|
|
|
|
"Hook run after the msb package has been loaded."
|
1998-02-15 16:45:52 +00:00
|
|
|
:type 'hook
|
|
|
|
:set 'msb-custom-set
|
|
|
|
:group 'msb)
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;;;
|
|
|
|
;;; Internal variables
|
|
|
|
;;;
|
|
|
|
|
|
|
|
;; The last calculated menu.
|
|
|
|
(defvar msb--last-buffer-menu nil)
|
|
|
|
|
|
|
|
;; If this is non-nil, then it is a string that describes the error.
|
|
|
|
(defvar msb--error nil)
|
|
|
|
|
|
|
|
;;;
|
1995-01-09 22:16:23 +00:00
|
|
|
;;; Some example function to be used for `msb-item-handling-function'.
|
1994-12-23 17:58:46 +00:00
|
|
|
;;;
|
|
|
|
(defun msb-item-handler (buffer &optional maxbuf)
|
|
|
|
"Create one string item, concerning BUFFER, for the buffer menu.
|
|
|
|
The item looks like:
|
|
|
|
*% <buffer-name>
|
1994-12-24 16:47:58 +00:00
|
|
|
The `*' appears only if the buffer is marked as modified.
|
|
|
|
The `%' appears only if the buffer is read-only.
|
1994-12-23 17:58:46 +00:00
|
|
|
Optional second argument MAXBUF is completely ignored."
|
|
|
|
(let ((name (buffer-name))
|
|
|
|
(modified (if (buffer-modified-p) "*" " "))
|
|
|
|
(read-only (if buffer-read-only "%" " ")))
|
|
|
|
(format "%s%s %s" modified read-only name)))
|
|
|
|
|
|
|
|
|
|
|
|
(eval-when-compile (require 'dired))
|
|
|
|
|
1994-12-24 16:47:58 +00:00
|
|
|
;; `dired' can be called with a list of the form (directory file1 file2 ...)
|
|
|
|
;; which causes `dired-directory' to be in the same form.
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb--dired-directory ()
|
|
|
|
(cond ((stringp dired-directory)
|
|
|
|
(abbreviate-file-name (expand-file-name dired-directory)))
|
|
|
|
((consp dired-directory)
|
|
|
|
(abbreviate-file-name (expand-file-name (car dired-directory))))
|
|
|
|
(t
|
1994-12-24 16:47:58 +00:00
|
|
|
(error "Unknown type of `dired-directory' in buffer %s"
|
1994-12-23 17:58:46 +00:00
|
|
|
(buffer-name)))))
|
|
|
|
|
|
|
|
(defun msb-dired-item-handler (buffer &optional maxbuf)
|
|
|
|
"Create one string item, concerning a dired BUFFER, for the buffer menu.
|
|
|
|
The item looks like:
|
|
|
|
*% <buffer-name>
|
1994-12-24 16:47:58 +00:00
|
|
|
The `*' appears only if the buffer is marked as modified.
|
|
|
|
The `%' appears only if the buffer is read-only.
|
1994-12-23 17:58:46 +00:00
|
|
|
Optional second argument MAXBUF is completely ignored."
|
|
|
|
(let ((name (msb--dired-directory))
|
|
|
|
(modified (if (buffer-modified-p) "*" " "))
|
|
|
|
(read-only (if buffer-read-only "%" " ")))
|
|
|
|
(format "%s%s %s" modified read-only name)))
|
|
|
|
|
|
|
|
(defun msb-alon-item-handler (buffer maxbuf)
|
|
|
|
"Create one string item for the buffer menu.
|
|
|
|
The item looks like:
|
|
|
|
<buffer-name> *%# <file-name>
|
1994-12-24 16:47:58 +00:00
|
|
|
The `*' appears only if the buffer is marked as modified.
|
|
|
|
The `%' appears only if the buffer is read-only.
|
|
|
|
The `#' appears only version control file (SCCS/RCS)."
|
1994-12-23 17:58:46 +00:00
|
|
|
(format (format "%%%ds %%s%%s%%s %%s" maxbuf)
|
|
|
|
(buffer-name buffer)
|
|
|
|
(if (buffer-modified-p) "*" " ")
|
|
|
|
(if buffer-read-only "%" " ")
|
|
|
|
(if (and (boundp 'vc-mode) vc-mode) "#" " ")
|
|
|
|
(or buffer-file-name "")))
|
|
|
|
|
|
|
|
;;;
|
1995-01-09 22:16:23 +00:00
|
|
|
;;; Some example function to be used for `msb-item-sort-function'.
|
1994-12-23 17:58:46 +00:00
|
|
|
;;;
|
|
|
|
(defun msb-sort-by-name (item1 item2)
|
1999-05-31 14:49:05 +00:00
|
|
|
"Sort the items ITEM1 and ITEM2 by their `buffer-name'.
|
|
|
|
An item looks like (NAME . BUFFER)."
|
1994-12-23 17:58:46 +00:00
|
|
|
(string-lessp (buffer-name (cdr item1))
|
|
|
|
(buffer-name (cdr item2))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun msb-sort-by-directory (item1 item2)
|
1999-05-31 14:49:05 +00:00
|
|
|
"Sort the items ITEM1 and ITEM2 by directory name. Made for dired.
|
1994-12-23 17:58:46 +00:00
|
|
|
An item look like (NAME . BUFFER)."
|
1997-12-22 02:26:17 +00:00
|
|
|
(string-lessp (save-excursion (set-buffer (cdr item1))
|
|
|
|
(msb--dired-directory))
|
|
|
|
(save-excursion (set-buffer (cdr item2))
|
|
|
|
(msb--dired-directory))))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;;;
|
|
|
|
;;; msb
|
|
|
|
;;;
|
|
|
|
;;; This function can be used instead of (mouse-buffer-menu EVENT)
|
|
|
|
;;; function in "mouse.el".
|
1997-12-22 02:26:17 +00:00
|
|
|
;;;
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb (event)
|
|
|
|
"Pop up several menus of buffers for selection with the mouse.
|
|
|
|
This command switches buffers in the window that you clicked on, and
|
|
|
|
selects that window.
|
|
|
|
|
1994-12-24 16:47:58 +00:00
|
|
|
See the function `mouse-select-buffer' and the variable
|
|
|
|
`msb-menu-cond' for more information about how the menus are split."
|
1994-12-23 17:58:46 +00:00
|
|
|
(interactive "e")
|
1995-02-24 09:12:56 +00:00
|
|
|
(let ((old-window (selected-window))
|
1994-12-23 17:58:46 +00:00
|
|
|
(window (posn-window (event-start event))))
|
1995-02-24 09:12:56 +00:00
|
|
|
(unless (framep window) (select-window window))
|
|
|
|
(let ((buffer (mouse-select-buffer event)))
|
|
|
|
(if buffer
|
|
|
|
(switch-to-buffer buffer)
|
|
|
|
(select-window old-window))))
|
1994-12-23 17:58:46 +00:00
|
|
|
nil)
|
|
|
|
|
|
|
|
;;;
|
|
|
|
;;; Some supportive functions
|
|
|
|
;;;
|
|
|
|
(defun msb-invisible-buffer-p (&optional buffer)
|
|
|
|
"Return t if optional BUFFER is an \"invisible\" buffer.
|
|
|
|
If the argument is left out or nil, then the current buffer is considered."
|
|
|
|
(and (> (length (buffer-name buffer)) 0)
|
|
|
|
(eq ?\ (aref (buffer-name buffer) 0))))
|
|
|
|
|
1997-12-22 02:33:25 +00:00
|
|
|
(defun msb--strip-dir (dir)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Strip one hierarchy level from the end of DIR."
|
1998-01-23 06:42:27 +00:00
|
|
|
(file-name-directory (directory-file-name dir)))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
;; Create an alist with all buffers from LIST that lies under the same
|
1997-12-22 02:26:17 +00:00
|
|
|
;; directory will be in the same item as the directory string.
|
1997-12-22 06:06:54 +00:00
|
|
|
;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K BUFFER-K+1...)) ...)
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb--init-file-alist (list)
|
|
|
|
(let ((buffer-alist
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Make alist that looks like
|
|
|
|
;; ((PATH-1 BUFFER-1) (PATH-2 BUFFER-2) ...)
|
|
|
|
;; sorted on PATH-x
|
2000-08-15 11:19:13 +00:00
|
|
|
(sort
|
|
|
|
(apply #'nconc
|
|
|
|
(mapcar
|
|
|
|
(lambda (buffer)
|
|
|
|
(let ((file-name (expand-file-name
|
|
|
|
(buffer-file-name buffer))))
|
|
|
|
(when file-name
|
|
|
|
(list (cons (msb--strip-dir file-name) buffer)))))
|
|
|
|
list))
|
|
|
|
(lambda (item1 item2)
|
|
|
|
(string< (car item1) (car item2))))))
|
1998-02-11 04:20:09 +00:00
|
|
|
;; Now clump buffers together that have the same path
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Make alist that looks like
|
1994-12-24 16:47:58 +00:00
|
|
|
;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K)) ...)
|
1994-12-23 17:58:46 +00:00
|
|
|
(let ((path nil)
|
1997-12-22 02:26:17 +00:00
|
|
|
(buffers nil))
|
|
|
|
(nconc
|
2000-08-15 11:19:13 +00:00
|
|
|
(apply
|
|
|
|
#'nconc
|
|
|
|
(mapcar (lambda (item)
|
|
|
|
(cond
|
|
|
|
((equal path (car item))
|
|
|
|
;; The same path as earlier: Add to current list of
|
|
|
|
;; buffers.
|
|
|
|
(push (cdr item) buffers)
|
|
|
|
;; This item should not be added to list
|
|
|
|
nil)
|
|
|
|
(t
|
|
|
|
;; New path
|
|
|
|
(let ((result (and path (cons path buffers))))
|
|
|
|
(setq path (car item))
|
|
|
|
(setq buffers (list (cdr item)))
|
|
|
|
;; Add the last result the list.
|
|
|
|
(and result (list result))))))
|
|
|
|
buffer-alist))
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Add the last result to the list
|
1994-12-23 17:58:46 +00:00
|
|
|
(list (cons path buffers))))))
|
|
|
|
|
1997-12-22 02:26:17 +00:00
|
|
|
(defun msb--format-title (top-found-p path number-of-items)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Format a suitable title for the menu item."
|
1999-07-28 16:46:30 +00:00
|
|
|
(format (if top-found-p "%s... (%d)" "%s (%d)")
|
|
|
|
(abbreviate-file-name path) number-of-items))
|
1997-12-22 02:26:17 +00:00
|
|
|
|
1998-02-11 04:20:09 +00:00
|
|
|
;; Variables for debugging.
|
|
|
|
(defvar msb--choose-file-menu-list)
|
|
|
|
(defvar msb--choose-file-menu-arg-list)
|
1997-12-22 02:26:17 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb--choose-file-menu (list)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Choose file-menu with respect to directory for every buffer in LIST."
|
1998-02-11 04:20:09 +00:00
|
|
|
(setq msb--choose-file-menu-arg-list list)
|
1994-12-23 17:58:46 +00:00
|
|
|
(let ((buffer-alist (msb--init-file-alist list))
|
|
|
|
(final-list nil)
|
|
|
|
(max-clumped-together (if (numberp msb-max-file-menu-items)
|
|
|
|
msb-max-file-menu-items
|
|
|
|
10))
|
|
|
|
(top-found-p nil)
|
|
|
|
(last-path nil)
|
1998-02-15 16:45:52 +00:00
|
|
|
first rest path buffers old-path)
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Prepare for looping over all items in buffer-alist
|
|
|
|
(setq first (car buffer-alist)
|
|
|
|
rest (cdr buffer-alist)
|
|
|
|
path (car first)
|
|
|
|
buffers (cdr first))
|
2000-08-15 11:19:13 +00:00
|
|
|
(setq msb--choose-file-menu-list (copy-sequence rest))
|
1997-12-22 02:26:17 +00:00
|
|
|
;; This big loop tries to clump buffers together that have a
|
|
|
|
;; similar name. Remember that buffer-alist is sorted based on the
|
|
|
|
;; path for the buffers.
|
1994-12-23 17:58:46 +00:00
|
|
|
(while rest
|
|
|
|
(let ((found-p nil)
|
|
|
|
(tmp-rest rest)
|
1997-12-22 02:26:17 +00:00
|
|
|
result
|
1994-12-23 17:58:46 +00:00
|
|
|
new-path item)
|
|
|
|
(setq item (car tmp-rest))
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Clump together the "rest"-buffers that have a path that is
|
|
|
|
;; a subpath of the current one.
|
1994-12-23 17:58:46 +00:00
|
|
|
(while (and tmp-rest
|
|
|
|
(<= (length buffers) max-clumped-together)
|
|
|
|
(>= (length (car item)) (length path))
|
1999-08-16 11:29:58 +00:00
|
|
|
;; `completion-ignore-case' seems to default to t
|
|
|
|
;; on the systems with case-insensitive file names.
|
1999-07-30 09:42:37 +00:00
|
|
|
(eq t (compare-strings path 0 nil
|
1999-08-16 11:29:58 +00:00
|
|
|
(car item) 0 (length path)
|
|
|
|
completion-ignore-case)))
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq found-p t)
|
1997-12-22 02:26:17 +00:00
|
|
|
(setq buffers (append buffers (cdr item))) ;nconc is faster than append
|
|
|
|
(setq tmp-rest (cdr tmp-rest)
|
|
|
|
item (car tmp-rest)))
|
1994-12-23 17:58:46 +00:00
|
|
|
(cond
|
|
|
|
((> (length buffers) max-clumped-together)
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Oh, we failed. Too many buffers clumped together.
|
|
|
|
;; Just use the original ones for the result.
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq last-path (car first))
|
1997-12-22 02:26:17 +00:00
|
|
|
(push (cons (msb--format-title top-found-p
|
|
|
|
(car first)
|
|
|
|
(length (cdr first)))
|
|
|
|
(cdr first))
|
|
|
|
final-list)
|
1995-01-09 22:16:23 +00:00
|
|
|
(setq top-found-p nil)
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq first (car rest)
|
1997-12-22 02:26:17 +00:00
|
|
|
rest (cdr rest)
|
|
|
|
path (car first)
|
1994-12-23 17:58:46 +00:00
|
|
|
buffers (cdr first)))
|
|
|
|
(t
|
1997-12-22 02:26:17 +00:00
|
|
|
;; The first pass of clumping together worked out, go ahead
|
|
|
|
;; with this result.
|
1994-12-23 17:58:46 +00:00
|
|
|
(when found-p
|
|
|
|
(setq top-found-p t)
|
|
|
|
(setq first (cons path buffers)
|
|
|
|
rest tmp-rest))
|
1997-12-22 02:26:17 +00:00
|
|
|
;; Now see if we can clump more buffers together if we go up
|
|
|
|
;; one step in the file hierarchy.
|
1998-02-15 16:45:52 +00:00
|
|
|
;; If path isn't changed by msb--strip-dir, we are looking
|
|
|
|
;; at the machine name component of an ange-ftp filename.
|
|
|
|
(setq old-path path)
|
1997-12-22 02:33:25 +00:00
|
|
|
(setq path (msb--strip-dir path)
|
1994-12-23 17:58:46 +00:00
|
|
|
buffers (cdr first))
|
1998-02-15 16:45:52 +00:00
|
|
|
(if (equal old-path path)
|
|
|
|
(setq last-path path))
|
1994-12-23 17:58:46 +00:00
|
|
|
(when (and last-path
|
|
|
|
(or (and (>= (length path) (length last-path))
|
1999-08-16 11:29:58 +00:00
|
|
|
(eq t (compare-strings
|
|
|
|
last-path 0 nil path 0
|
|
|
|
(length last-path)
|
|
|
|
completion-ignore-case)))
|
1994-12-23 17:58:46 +00:00
|
|
|
(and (< (length path) (length last-path))
|
1999-08-16 11:29:58 +00:00
|
|
|
(eq t (compare-strings
|
|
|
|
path 0 nil last-path 0 (length path)
|
|
|
|
completion-ignore-case)))))
|
1997-12-22 02:26:17 +00:00
|
|
|
;; We have reached the same place in the file hierarchy as
|
|
|
|
;; the last result, so we should quit at this point and
|
|
|
|
;; take what we have as result.
|
|
|
|
(push (cons (msb--format-title top-found-p
|
|
|
|
(car first)
|
|
|
|
(length (cdr first)))
|
|
|
|
(cdr first))
|
|
|
|
final-list)
|
1995-01-09 22:16:23 +00:00
|
|
|
(setq top-found-p nil)
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq first (car rest)
|
1997-12-22 02:26:17 +00:00
|
|
|
rest (cdr rest)
|
|
|
|
path (car first)
|
|
|
|
buffers (cdr first)))))))
|
|
|
|
;; Now take care of the last item.
|
1998-02-15 16:45:52 +00:00
|
|
|
(when first
|
|
|
|
(push (cons (msb--format-title top-found-p
|
|
|
|
(car first)
|
|
|
|
(length (cdr first)))
|
|
|
|
(cdr first))
|
|
|
|
final-list))
|
1995-01-09 22:16:23 +00:00
|
|
|
(setq top-found-p nil)
|
1994-12-23 17:58:46 +00:00
|
|
|
(nreverse final-list)))
|
|
|
|
|
|
|
|
(defun msb--create-function-info (menu-cond-elt)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Create a vector from an element MENU-COND-ELT of `msb-menu-cond'.
|
|
|
|
This takes the form:
|
|
|
|
\]BUFFER-LIST-VARIABLE CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLER SORTER)
|
|
|
|
See `msb-menu-cond' for a description of its elements."
|
1994-12-23 17:58:46 +00:00
|
|
|
(let* ((list-symbol (make-symbol "-msb-buffer-list"))
|
|
|
|
(tmp-ih (and (> (length menu-cond-elt) 3)
|
|
|
|
(nth 3 menu-cond-elt)))
|
|
|
|
(item-handler (if (and tmp-ih (fboundp tmp-ih))
|
|
|
|
tmp-ih
|
|
|
|
msb-item-handling-function))
|
|
|
|
(tmp-s (if (> (length menu-cond-elt) 4)
|
|
|
|
(nth 4 menu-cond-elt)
|
|
|
|
msb-item-sort-function))
|
|
|
|
(sorter (if (or (fboundp tmp-s)
|
|
|
|
(null tmp-s)
|
1994-12-24 16:47:58 +00:00
|
|
|
(eq tmp-s t))
|
2000-08-15 11:19:13 +00:00
|
|
|
tmp-s
|
1994-12-23 17:58:46 +00:00
|
|
|
msb-item-sort-function)))
|
|
|
|
(when (< (length menu-cond-elt) 3)
|
1999-05-31 14:49:05 +00:00
|
|
|
(error "Wrong format of msb-menu-cond"))
|
1994-12-23 17:58:46 +00:00
|
|
|
(when (and (> (length menu-cond-elt) 3)
|
|
|
|
(not (fboundp tmp-ih)))
|
|
|
|
(signal 'invalid-function (list tmp-ih)))
|
|
|
|
(when (and (> (length menu-cond-elt) 4)
|
|
|
|
tmp-s
|
|
|
|
(not (fboundp tmp-s))
|
1994-12-24 16:47:58 +00:00
|
|
|
(not (eq tmp-s t)))
|
1994-12-23 17:58:46 +00:00
|
|
|
(signal 'invalid-function (list tmp-s)))
|
1994-12-24 16:47:58 +00:00
|
|
|
(set list-symbol ())
|
1994-12-23 17:58:46 +00:00
|
|
|
(vector list-symbol ;BUFFER-LIST-VARIABLE
|
|
|
|
(nth 0 menu-cond-elt) ;CONDITION
|
|
|
|
(nth 1 menu-cond-elt) ;SORT-KEY
|
|
|
|
(nth 2 menu-cond-elt) ;MENU-TITLE
|
|
|
|
item-handler ;ITEM-HANDLER
|
|
|
|
sorter) ;SORTER
|
|
|
|
))
|
|
|
|
|
|
|
|
;; This defsubst is only used in `msb--choose-menu' below. It was
|
1998-02-15 16:45:52 +00:00
|
|
|
;; pulled out merely to make the code somewhat clearer. The indentation
|
1994-12-23 17:58:46 +00:00
|
|
|
;; level was too big.
|
|
|
|
(defsubst msb--collect (function-info-vector)
|
|
|
|
(let ((result nil)
|
|
|
|
(multi-flag nil)
|
|
|
|
function-info-list)
|
|
|
|
(setq function-info-list
|
|
|
|
(loop for fi
|
|
|
|
across function-info-vector
|
|
|
|
if (and (setq result
|
|
|
|
(eval (aref fi 1))) ;Test CONDITION
|
|
|
|
(not (and (eq result 'no-multi)
|
|
|
|
multi-flag))
|
|
|
|
(progn (when (eq result 'multi)
|
|
|
|
(setq multi-flag t))
|
1995-01-09 22:16:23 +00:00
|
|
|
t))
|
1994-12-23 17:58:46 +00:00
|
|
|
collect fi
|
|
|
|
until (and result
|
|
|
|
(not (eq result 'multi)))))
|
|
|
|
(when (and (not function-info-list)
|
|
|
|
(not result))
|
|
|
|
(error "No catch-all in msb-menu-cond!"))
|
|
|
|
function-info-list))
|
|
|
|
|
|
|
|
(defun msb--add-to-menu (buffer function-info max-buffer-name-length)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Add BUFFER to the menu depicted by FUNCTION-INFO.
|
|
|
|
All side-effects. Adds an element of form (BUFFER-TITLE . BUFFER)
|
|
|
|
to the buffer-list variable in function-info."
|
1994-12-23 17:58:46 +00:00
|
|
|
(let ((list-symbol (aref function-info 0))) ;BUFFER-LIST-VARIABLE
|
|
|
|
;; Here comes the hairy side-effect!
|
|
|
|
(set list-symbol
|
|
|
|
(cons (cons (funcall (aref function-info 4) ;ITEM-HANDLER
|
|
|
|
buffer
|
|
|
|
max-buffer-name-length)
|
|
|
|
buffer)
|
|
|
|
(eval list-symbol)))))
|
1997-12-22 02:26:17 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(defsubst msb--choose-menu (buffer function-info-vector max-buffer-name-length)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Select the appropriate menu for BUFFER."
|
|
|
|
;; This is all side-effects, folks!
|
|
|
|
;; This should be optimized.
|
1994-12-23 17:58:46 +00:00
|
|
|
(unless (and (not msb-display-invisible-buffers-p)
|
|
|
|
(msb-invisible-buffer-p buffer))
|
|
|
|
(condition-case nil
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buffer)
|
1994-12-24 16:47:58 +00:00
|
|
|
;; Menu found. Add to this menu
|
2000-03-24 20:45:10 +00:00
|
|
|
(dolist (info (msb--collect function-info-vector))
|
|
|
|
(msb--add-to-menu buffer info max-buffer-name-length)))
|
1994-12-23 17:58:46 +00:00
|
|
|
(error (unless msb--error
|
|
|
|
(setq msb--error
|
|
|
|
(format
|
1994-12-24 16:47:58 +00:00
|
|
|
"In msb-menu-cond, error for buffer `%s'."
|
1994-12-23 17:58:46 +00:00
|
|
|
(buffer-name buffer)))
|
1996-01-29 23:17:49 +00:00
|
|
|
(error "%s" msb--error))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
(defun msb--create-sort-item (function-info)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Return (SORT-KEY TITLE . BUFFER-LIST) or nil if the buffer-list is empty."
|
1994-12-23 17:58:46 +00:00
|
|
|
(let ((buffer-list (eval (aref function-info 0))))
|
|
|
|
(when buffer-list
|
|
|
|
(let ((sorter (aref function-info 5)) ;SORTER
|
|
|
|
(sort-key (aref function-info 2))) ;MENU-SORT-KEY
|
|
|
|
(when sort-key
|
1997-12-22 02:26:17 +00:00
|
|
|
(cons sort-key
|
1994-12-23 17:58:46 +00:00
|
|
|
(cons (format (aref function-info 3) ;MENU-TITLE
|
|
|
|
(length buffer-list))
|
|
|
|
(cond
|
|
|
|
((null sorter)
|
|
|
|
buffer-list)
|
1994-12-24 16:47:58 +00:00
|
|
|
((eq sorter t)
|
1994-12-23 17:58:46 +00:00
|
|
|
(nreverse buffer-list))
|
|
|
|
(t
|
|
|
|
(sort buffer-list sorter))))))))))
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defun msb--aggregate-alist (alist same-predicate sort-predicate)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Return ALIST as a sorted, aggregated alist.
|
|
|
|
|
|
|
|
In the result all items with the same car element (according to
|
|
|
|
SAME-PREDICATE) are aggregated together. The alist is first sorted by
|
|
|
|
SORT-PREDICATE.
|
|
|
|
|
|
|
|
Example:
|
2000-03-24 20:45:10 +00:00
|
|
|
\(msb--aggregate-alist
|
1999-07-23 22:57:32 +00:00
|
|
|
'((a . a1) (a . a2) (b . b1) (c . c3) (a . a4) (a . a3) (b . b3) (b . b2))
|
|
|
|
(function string=)
|
|
|
|
(lambda (item1 item2)
|
|
|
|
(string< (symbol-name item1) (symbol-name item2))))
|
|
|
|
results in
|
2000-03-24 20:45:10 +00:00
|
|
|
\((a a1 a2 a4 a3) (b b1 b3 b2) (c c3))"
|
1998-02-15 16:45:52 +00:00
|
|
|
(when (not (null alist))
|
|
|
|
(let (result
|
|
|
|
same
|
|
|
|
tmp-old-car
|
|
|
|
tmp-same
|
|
|
|
(first-time-p t)
|
|
|
|
old-car)
|
|
|
|
(nconc
|
2000-08-15 11:19:13 +00:00
|
|
|
(apply #'nconc
|
|
|
|
(mapcar
|
|
|
|
(lambda (item)
|
1998-02-15 16:45:52 +00:00
|
|
|
(cond
|
|
|
|
(first-time-p
|
|
|
|
(push (cdr item) same)
|
|
|
|
(setq first-time-p nil)
|
|
|
|
(setq old-car (car item))
|
|
|
|
nil)
|
|
|
|
((funcall same-predicate (car item) old-car)
|
|
|
|
(push (cdr item) same)
|
|
|
|
nil)
|
|
|
|
(t
|
|
|
|
(setq tmp-same same
|
|
|
|
tmp-old-car old-car)
|
|
|
|
(setq same (list (cdr item))
|
|
|
|
old-car (car item))
|
|
|
|
(list (cons tmp-old-car (nreverse tmp-same))))))
|
|
|
|
(sort alist (lambda (item1 item2)
|
2000-08-15 11:19:13 +00:00
|
|
|
(funcall sort-predicate (car item1) (car item2))))))
|
1998-02-15 16:45:52 +00:00
|
|
|
(list (cons old-car (nreverse same)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(defun msb--mode-menu-cond ()
|
|
|
|
(let ((key msb-modes-key))
|
|
|
|
(mapcar (lambda (item)
|
|
|
|
(incf key)
|
|
|
|
(list `( eq major-mode (quote ,(car item)))
|
|
|
|
key
|
|
|
|
(concat (cdr item) " (%d)")))
|
1999-05-31 14:49:05 +00:00
|
|
|
(sort
|
1998-02-15 16:45:52 +00:00
|
|
|
(let ((mode-list nil))
|
2000-03-24 20:45:10 +00:00
|
|
|
(dolist (buffer (cdr (buffer-list)))
|
|
|
|
(save-excursion
|
|
|
|
(set-buffer buffer)
|
|
|
|
(when (and (not (msb-invisible-buffer-p))
|
|
|
|
(not (assq major-mode mode-list)))
|
|
|
|
(push (cons major-mode mode-name)
|
|
|
|
mode-list))))
|
1998-02-15 16:45:52 +00:00
|
|
|
mode-list)
|
|
|
|
(lambda (item1 item2)
|
|
|
|
(string< (cdr item1) (cdr item2)))))))
|
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb--most-recently-used-menu (max-buffer-name-length)
|
1999-07-23 22:57:32 +00:00
|
|
|
"Return a list for the most recently used buffers.
|
|
|
|
It takes the form ((TITLE . BUFFER-LIST)...)."
|
1995-01-09 22:16:23 +00:00
|
|
|
(when (and (numberp msb-display-most-recently-used)
|
|
|
|
(> msb-display-most-recently-used 0))
|
1995-02-24 09:12:56 +00:00
|
|
|
(let* ((buffers (cdr (buffer-list)))
|
|
|
|
(most-recently-used
|
1994-12-23 17:58:46 +00:00
|
|
|
(loop with n = 0
|
1995-02-24 09:12:56 +00:00
|
|
|
for buffer in buffers
|
1994-12-23 17:58:46 +00:00
|
|
|
if (save-excursion
|
|
|
|
(set-buffer buffer)
|
|
|
|
(and (not (msb-invisible-buffer-p))
|
|
|
|
(not (eq major-mode 'dired-mode))))
|
|
|
|
collect (save-excursion
|
|
|
|
(set-buffer buffer)
|
|
|
|
(cons (funcall msb-item-handling-function
|
|
|
|
buffer
|
|
|
|
max-buffer-name-length)
|
|
|
|
buffer))
|
|
|
|
and do (incf n)
|
1995-01-09 22:16:23 +00:00
|
|
|
until (>= n msb-display-most-recently-used))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(cons (if (stringp msb-most-recently-used-title)
|
|
|
|
(format msb-most-recently-used-title
|
|
|
|
(length most-recently-used))
|
|
|
|
(signal 'wrong-type-argument (list msb-most-recently-used-title)))
|
|
|
|
most-recently-used))))
|
|
|
|
|
|
|
|
(defun msb--create-buffer-menu-2 ()
|
|
|
|
(let ((max-buffer-name-length 0)
|
|
|
|
file-buffers
|
|
|
|
function-info-vector)
|
|
|
|
;; Calculate the longest buffer name.
|
2000-03-24 20:45:10 +00:00
|
|
|
(dolist (buffer (buffer-list))
|
|
|
|
(when (or msb-display-invisible-buffers-p
|
|
|
|
(not (msb-invisible-buffer-p)))
|
|
|
|
(setq max-buffer-name-length
|
|
|
|
(max max-buffer-name-length (length (buffer-name buffer))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Make a list with elements of type
|
|
|
|
;; (BUFFER-LIST-VARIABLE
|
|
|
|
;; CONDITION
|
|
|
|
;; MENU-SORT-KEY
|
|
|
|
;; MENU-TITLE
|
|
|
|
;; ITEM-HANDLER
|
|
|
|
;; SORTER)
|
|
|
|
;; Uses "function-global" variables:
|
|
|
|
;; function-info-vector
|
|
|
|
(setq function-info-vector
|
|
|
|
(apply (function vector)
|
|
|
|
(mapcar (function msb--create-function-info)
|
1998-02-15 16:45:52 +00:00
|
|
|
(append msb-menu-cond (msb--mode-menu-cond)))))
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Split the buffer-list into several lists; one list for each
|
1994-12-24 16:47:58 +00:00
|
|
|
;; criteria. This is the most critical part with respect to time.
|
2000-03-24 20:45:10 +00:00
|
|
|
(dolist (buffer (buffer-list))
|
|
|
|
(cond ((and msb-files-by-directory
|
|
|
|
(buffer-file-name buffer)
|
|
|
|
;; exclude ange-ftp buffers
|
|
|
|
;;(not (string-match "\\/[^/:]+:"
|
|
|
|
;; (buffer-file-name buffer)))
|
|
|
|
)
|
|
|
|
(push buffer file-buffers))
|
|
|
|
(t
|
|
|
|
(msb--choose-menu buffer
|
|
|
|
function-info-vector
|
|
|
|
max-buffer-name-length))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(when file-buffers
|
|
|
|
(setq file-buffers
|
1998-02-15 16:45:52 +00:00
|
|
|
(mapcar (lambda (buffer-list)
|
|
|
|
(cons msb-files-by-directory-sort-key
|
|
|
|
(cons (car buffer-list)
|
|
|
|
(sort
|
|
|
|
(mapcar (function
|
|
|
|
(lambda (buffer)
|
|
|
|
(cons (save-excursion
|
|
|
|
(set-buffer buffer)
|
|
|
|
(funcall msb-item-handling-function
|
|
|
|
buffer
|
|
|
|
max-buffer-name-length))
|
|
|
|
buffer)))
|
|
|
|
(cdr buffer-list))
|
|
|
|
(function
|
|
|
|
(lambda (item1 item2)
|
|
|
|
(string< (car item1) (car item2))))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(msb--choose-file-menu file-buffers))))
|
|
|
|
;; Now make the menu - a list of (TITLE . BUFFER-LIST)
|
1995-01-09 22:16:23 +00:00
|
|
|
(let* (menu
|
1994-12-23 17:58:46 +00:00
|
|
|
(most-recently-used
|
|
|
|
(msb--most-recently-used-menu max-buffer-name-length))
|
1997-12-22 02:26:17 +00:00
|
|
|
(others (nconc file-buffers
|
1994-12-23 17:58:46 +00:00
|
|
|
(loop for elt
|
1995-01-09 22:16:23 +00:00
|
|
|
across function-info-vector
|
|
|
|
for value = (msb--create-sort-item elt)
|
|
|
|
if value collect value))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq menu
|
|
|
|
(mapcar 'cdr ;Remove the SORT-KEY
|
|
|
|
;; Sort the menus - not the items.
|
|
|
|
(msb--add-separators
|
|
|
|
(sort
|
|
|
|
;; Get a list of (SORT-KEY TITLE . BUFFER-LIST)
|
|
|
|
;; Also sorts the items within the menus.
|
|
|
|
(if (cdr most-recently-used)
|
|
|
|
(cons
|
|
|
|
;; Add most recent used buffers
|
|
|
|
(cons msb-most-recently-used-sort-key
|
|
|
|
most-recently-used)
|
|
|
|
others)
|
|
|
|
others)
|
1998-02-15 16:45:52 +00:00
|
|
|
(lambda (elt1 elt2)
|
|
|
|
(< (car elt1) (car elt2)))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Now make it a keymap menu
|
|
|
|
(append
|
|
|
|
'(keymap "Select Buffer")
|
|
|
|
(msb--make-keymap-menu menu)
|
|
|
|
(when msb-separator-diff
|
1997-12-22 02:26:17 +00:00
|
|
|
(list (list 'separator "--")))
|
|
|
|
(list (cons 'toggle
|
1994-12-23 17:58:46 +00:00
|
|
|
(cons
|
|
|
|
(if msb-files-by-directory
|
2000-08-15 11:19:13 +00:00
|
|
|
"*Files by type*"
|
|
|
|
"*Files by directory*")
|
|
|
|
'msb--toggle-menu-type)))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
(defun msb--create-buffer-menu ()
|
|
|
|
(save-match-data
|
|
|
|
(save-excursion
|
|
|
|
(msb--create-buffer-menu-2))))
|
|
|
|
|
|
|
|
(defun msb--toggle-menu-type ()
|
1999-07-23 22:57:32 +00:00
|
|
|
"Multi purpose function for selecting a buffer with the mouse."
|
1994-12-23 17:58:46 +00:00
|
|
|
(interactive)
|
|
|
|
(setq msb-files-by-directory (not msb-files-by-directory))
|
1998-02-11 04:20:09 +00:00
|
|
|
;; This gets a warning, but it is correct,
|
|
|
|
;; because this file redefines menu-bar-update-buffers.
|
1999-07-23 22:57:32 +00:00
|
|
|
(msb-menu-bar-update-buffers t))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
|
|
|
(defun mouse-select-buffer (event)
|
|
|
|
"Pop up several menus of buffers, for selection with the mouse.
|
|
|
|
Returns the selected buffer or nil if no buffer is selected.
|
|
|
|
|
1995-01-09 22:16:23 +00:00
|
|
|
The way the buffers are split is conveniently handled with the
|
1994-12-24 16:47:58 +00:00
|
|
|
variable `msb-menu-cond'."
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Popup the menu and return the selected buffer.
|
|
|
|
(when (or msb--error
|
|
|
|
(not msb--last-buffer-menu)
|
|
|
|
(not (fboundp 'frame-or-buffer-changed-p))
|
|
|
|
(frame-or-buffer-changed-p))
|
|
|
|
(setq msb--error nil)
|
|
|
|
(setq msb--last-buffer-menu (msb--create-buffer-menu)))
|
1995-01-09 22:16:23 +00:00
|
|
|
(let ((position event)
|
|
|
|
choice)
|
1994-12-23 17:58:46 +00:00
|
|
|
(when (and (fboundp 'posn-x-y)
|
|
|
|
(fboundp 'posn-window))
|
|
|
|
(let ((posX (car (posn-x-y (event-start event))))
|
|
|
|
(posY (cdr (posn-x-y (event-start event))))
|
1995-01-09 22:16:23 +00:00
|
|
|
(posWind (posn-window (event-start event))))
|
1994-12-23 17:58:46 +00:00
|
|
|
;; adjust position
|
|
|
|
(setq posX (- posX (funcall msb-horizontal-shift-function))
|
|
|
|
position (list (list posX posY) posWind))))
|
1995-02-24 21:26:05 +00:00
|
|
|
;; This `sit-for' magically makes the menu stay up if the mouse
|
1996-01-04 23:45:49 +00:00
|
|
|
;; button is released within 0.1 second.
|
1995-02-24 21:26:05 +00:00
|
|
|
(sit-for 0 100)
|
|
|
|
;; Popup the menu
|
1995-01-09 22:16:23 +00:00
|
|
|
(setq choice (x-popup-menu position msb--last-buffer-menu))
|
1994-12-23 17:58:46 +00:00
|
|
|
(cond
|
1995-01-09 22:16:23 +00:00
|
|
|
((eq (car choice) 'toggle)
|
|
|
|
;; Bring up the menu again with type toggled.
|
|
|
|
(msb--toggle-menu-type)
|
|
|
|
(mouse-select-buffer event))
|
|
|
|
((and (numberp (car choice))
|
|
|
|
(null (cdr choice)))
|
2000-08-15 11:19:13 +00:00
|
|
|
(let ((msb--last-buffer-menu (nthcdr 3 (assq (car choice)
|
|
|
|
msb--last-buffer-menu))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(mouse-select-buffer event)))
|
1995-01-09 22:16:23 +00:00
|
|
|
((while (numberp (car choice))
|
|
|
|
(setq choice (cdr choice))))
|
|
|
|
((and (stringp (car choice))
|
|
|
|
(null (cdr choice)))
|
|
|
|
(car choice))
|
1995-01-12 06:59:56 +00:00
|
|
|
((null choice)
|
|
|
|
choice)
|
1995-01-09 22:16:23 +00:00
|
|
|
(t
|
|
|
|
(error "Unknown form for buffer: %s" choice)))))
|
1998-02-15 16:45:52 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
;; Add separators
|
|
|
|
(defun msb--add-separators (sorted-list)
|
2000-08-15 11:19:13 +00:00
|
|
|
(if (or (not msb-separator-diff)
|
|
|
|
(not (numberp msb-separator-diff)))
|
|
|
|
sorted-list
|
1994-12-23 17:58:46 +00:00
|
|
|
(let ((last-key nil))
|
2000-08-15 11:19:13 +00:00
|
|
|
(apply #'nconc
|
|
|
|
(mapcar
|
|
|
|
(lambda (item)
|
|
|
|
(cond
|
|
|
|
((and msb-separator-diff
|
|
|
|
last-key
|
|
|
|
(> (- (car item) last-key)
|
|
|
|
msb-separator-diff))
|
|
|
|
(setq last-key (car item))
|
|
|
|
(list (cons last-key 'separator)
|
|
|
|
item))
|
|
|
|
(t
|
|
|
|
(setq last-key (car item))
|
|
|
|
(list item))))
|
|
|
|
sorted-list)))))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1995-01-09 22:16:23 +00:00
|
|
|
(defun msb--split-menus-2 (list mcount result)
|
|
|
|
(cond
|
|
|
|
((> (length list) msb-max-menu-items)
|
|
|
|
(let ((count 0)
|
|
|
|
sub-name
|
|
|
|
(tmp-list nil))
|
|
|
|
(while (< count msb-max-menu-items)
|
|
|
|
(push (pop list) tmp-list)
|
|
|
|
(incf count))
|
2000-08-15 11:19:13 +00:00
|
|
|
(setq tmp-list (nreverse tmp-list))
|
|
|
|
(setq sub-name (concat (car (car tmp-list)) "..."))
|
|
|
|
(push (nconc (list mcount sub-name
|
|
|
|
'keymap sub-name)
|
|
|
|
tmp-list)
|
|
|
|
result))
|
1995-01-09 22:16:23 +00:00
|
|
|
(msb--split-menus-2 list (1+ mcount) result))
|
|
|
|
((null result)
|
|
|
|
list)
|
|
|
|
(t
|
|
|
|
(let (sub-name)
|
|
|
|
(setq sub-name (concat (car (car list)) "..."))
|
2000-08-15 11:19:13 +00:00
|
|
|
(push (nconc (list mcount sub-name 'keymap sub-name)
|
|
|
|
list)
|
|
|
|
result))
|
1995-01-09 22:16:23 +00:00
|
|
|
(nreverse result))))
|
|
|
|
|
1998-02-15 16:45:52 +00:00
|
|
|
(defun msb--split-menus (list)
|
|
|
|
(if (and (integerp msb-max-menu-items)
|
|
|
|
(> msb-max-menu-items 0))
|
|
|
|
(msb--split-menus-2 list 0 nil)
|
|
|
|
list))
|
1995-01-09 22:16:23 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(defun msb--make-keymap-menu (raw-menu)
|
|
|
|
(let ((end (cons '(nil) 'menu-bar-select-buffer))
|
|
|
|
(mcount 0))
|
|
|
|
(mapcar
|
1998-02-15 16:45:52 +00:00
|
|
|
(lambda (sub-menu)
|
1999-05-31 14:49:05 +00:00
|
|
|
(cond
|
1998-02-15 16:45:52 +00:00
|
|
|
((eq 'separator sub-menu)
|
|
|
|
(list 'separator "--"))
|
|
|
|
(t
|
2000-08-15 11:19:13 +00:00
|
|
|
(let ((buffers (mapcar (lambda (item)
|
|
|
|
(cons (buffer-name (cdr item))
|
|
|
|
(cons (car item) end)))
|
1998-02-15 16:45:52 +00:00
|
|
|
(cdr sub-menu))))
|
|
|
|
(nconc (list (incf mcount) (car sub-menu)
|
|
|
|
'keymap (car sub-menu))
|
|
|
|
(msb--split-menus buffers))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
raw-menu)))
|
|
|
|
|
1999-07-23 22:57:32 +00:00
|
|
|
(defun msb-menu-bar-update-buffers (&optional arg)
|
|
|
|
"A re-written version of `menu-bar-update-buffers'."
|
1994-12-23 17:58:46 +00:00
|
|
|
;; If user discards the Buffers item, play along.
|
|
|
|
(when (and (lookup-key (current-global-map) [menu-bar buffer])
|
|
|
|
(or (not (fboundp 'frame-or-buffer-changed-p))
|
|
|
|
(frame-or-buffer-changed-p)
|
|
|
|
arg))
|
1995-02-24 09:12:56 +00:00
|
|
|
(let ((frames (frame-list))
|
1994-12-23 17:58:46 +00:00
|
|
|
buffers-menu frames-menu)
|
|
|
|
;; Make the menu of buffers proper.
|
|
|
|
(setq msb--last-buffer-menu (msb--create-buffer-menu))
|
|
|
|
(setq buffers-menu msb--last-buffer-menu)
|
|
|
|
;; Make a Frames menu if we have more than one frame.
|
1995-02-24 09:12:56 +00:00
|
|
|
(when (cdr frames)
|
|
|
|
(let* ((frame-length (length frames))
|
|
|
|
(f-title (format "Frames (%d)" frame-length)))
|
|
|
|
;; List only the N most recently selected frames
|
|
|
|
(when (and (integerp msb-max-menu-items)
|
|
|
|
(> msb-max-menu-items 1)
|
|
|
|
(> frame-length msb-max-menu-items))
|
|
|
|
(setcdr (nthcdr msb-max-menu-items frames) nil))
|
1994-12-23 17:58:46 +00:00
|
|
|
(setq frames-menu
|
1995-02-24 09:12:56 +00:00
|
|
|
(nconc
|
|
|
|
(list 'frame f-title '(nil) 'keymap f-title)
|
|
|
|
(mapcar
|
1998-02-15 16:45:52 +00:00
|
|
|
(lambda (frame)
|
|
|
|
(nconc
|
|
|
|
(list frame
|
|
|
|
(cdr (assq 'name
|
|
|
|
(frame-parameters frame)))
|
|
|
|
(cons nil nil))
|
|
|
|
'menu-bar-select-frame))
|
1995-02-24 09:12:56 +00:00
|
|
|
frames)))))
|
1994-12-23 17:58:46 +00:00
|
|
|
(define-key (current-global-map) [menu-bar buffer]
|
|
|
|
(cons "Buffers"
|
|
|
|
(if (and buffers-menu frames-menu)
|
1995-02-24 09:12:56 +00:00
|
|
|
;; Combine Frame and Buffers menus with separator between
|
|
|
|
(nconc (list 'keymap "Buffers and Frames" frames-menu
|
1997-12-22 02:26:17 +00:00
|
|
|
(and msb-separator-diff '(separator "--")))
|
1995-02-24 09:12:56 +00:00
|
|
|
(cddr buffers-menu))
|
|
|
|
(or buffers-menu 'undefined)))))))
|
1994-12-23 17:58:46 +00:00
|
|
|
|
1999-05-31 14:49:05 +00:00
|
|
|
;; Snarf current bindings of `mouse-buffer-menu' (normally
|
|
|
|
;; C-down-mouse-1).
|
|
|
|
(defvar msb-mode-map
|
2000-08-15 11:19:13 +00:00
|
|
|
(let ((map (make-sparse-keymap "Msb")))
|
2000-09-21 14:36:55 +00:00
|
|
|
(substitute-key-definition 'mouse-buffer-menu 'msb map global-map)
|
1999-05-31 14:49:05 +00:00
|
|
|
map))
|
|
|
|
|
|
|
|
;;;###autoload
|
2000-08-16 19:40:41 +00:00
|
|
|
(define-minor-mode msb-mode
|
1999-05-31 14:49:05 +00:00
|
|
|
"Toggle Msb mode.
|
|
|
|
With arg, turn Msb mode on if and only if arg is positive.
|
|
|
|
This mode overrides the binding(s) of `mouse-buffer-menu' to provide a
|
|
|
|
different buffer menu using the function `msb'."
|
2000-09-21 14:36:55 +00:00
|
|
|
:global t
|
1999-05-31 14:49:05 +00:00
|
|
|
(if msb-mode
|
1999-07-23 22:57:32 +00:00
|
|
|
(progn
|
|
|
|
(add-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers)
|
|
|
|
(remove-hook 'menu-bar-update-hook 'menu-bar-update-buffers))
|
|
|
|
(remove-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers)
|
|
|
|
(add-hook 'menu-bar-update-hook 'menu-bar-update-buffers))
|
|
|
|
(run-hooks 'menu-bar-update-hook))
|
1999-05-31 14:49:05 +00:00
|
|
|
|
2000-08-15 11:19:13 +00:00
|
|
|
(defun msb-unload-hook ()
|
|
|
|
(msb-mode 0))
|
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
(provide 'msb)
|
2001-01-29 21:22:00 +00:00
|
|
|
(eval-after-load "msb" '(run-hooks msb-after-load-hook msb-after-load-hooks))
|
1997-01-05 04:44:30 +00:00
|
|
|
|
1994-12-23 17:58:46 +00:00
|
|
|
;;; msb.el ends here
|