aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love1999-05-31 14:49:05 +0000
committerDave Love1999-05-31 14:49:05 +0000
commitaade135d493283a144455923f4b03856201f35fa (patch)
tree815c7a13eaf6fcd13b113c24147cf4f048711369
parent71c62b6bbecb0ecf24b79dc01b0238253e03ffd1 (diff)
downloademacs-aade135d493283a144455923f4b03856201f35fa.tar.gz
emacs-aade135d493283a144455923f4b03856201f35fa.zip
Add to minor-mode-map-alist. Remove hook installation
and keymap munging on load. (msb-mode): New option. (msb-files-by-directory, msb-sort-by-name, msb-sort-by-directory): Doc fix. (msb-mode-map): New variable. (msb-mode): New command.
-rw-r--r--lisp/msb.el92
1 files changed, 53 insertions, 39 deletions
diff --git a/lisp/msb.el b/lisp/msb.el
index 95d0fc1b302..60bad741713 100644
--- a/lisp/msb.el
+++ b/lisp/msb.el
@@ -1,6 +1,6 @@
1;;; msb.el --- Customizable buffer-selection with multiple menus. 1;;; msb.el --- Customizable buffer-selection with multiple menus.
2 2
3;; Copyright (C) 1993, 1994, 1995, 1997, 1998 Free Software Foundation, Inc. 3;; Copyright (C) 1993, 94, 95, 97, 98, 99 Free Software Foundation, Inc.
4 4
5;; Author: Lars Lindberg <Lars.G.Lindberg@capgemini.se> 5;; Author: Lars Lindberg <Lars.G.Lindberg@capgemini.se>
6;; Created: 8 Oct 1993 6;; Created: 8 Oct 1993
@@ -29,17 +29,8 @@
29;; Purpose of this package: 29;; Purpose of this package:
30;; 1. Offer a function for letting the user choose buffer, 30;; 1. Offer a function for letting the user choose buffer,
31;; not necessarily for switching to it. 31;; not necessarily for switching to it.
32;; 2. Make a better mouse-buffer-menu. 32;; 2. Make a better mouse-buffer-menu. This is done as a global
33;; 33;; minor mode, msb-mode.
34;; Installation:
35
36;; 1. Byte compile msb first. It uses things in the cl package that
37;; are slow if not compiled, but blazingly fast when compiled. I
38;; have also had one report that said that msb malfunctioned when
39;; not compiled.
40;; 2. (require 'msb)
41;; Note! You now use msb instead of mouse-buffer-menu.
42;; 3. Now try the menu bar Buffers menu.
43;; 34;;
44;; Customization: 35;; Customization:
45;; Look at the variable `msb-menu-cond' for deciding what menus you 36;; Look at the variable `msb-menu-cond' for deciding what menus you
@@ -83,6 +74,7 @@
83;; Richard Stallman <rms@gnu.ai.mit.edu> 74;; Richard Stallman <rms@gnu.ai.mit.edu>
84;; Steve Fisk <fisk@medved.bowdoin.edu> 75;; Steve Fisk <fisk@medved.bowdoin.edu>
85 76
77;; This version turned into a global minor mode by Dave Love.
86;;; Code: 78;;; Code:
87 79
88(require 'cl) 80(require 'cl)
@@ -117,7 +109,7 @@
117 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) 109 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode))
118 (memq major-mode '(mh-letter-mode 110 (memq major-mode '(mh-letter-mode
119 mh-show-mode 111 mh-show-mode
120 mh-folder-mode)) 112 mh-folder-mode))
121 (memq major-mode '(gnus-summary-mode 113 (memq major-mode '(gnus-summary-mode
122 news-reply-mode 114 news-reply-mode
123 gnus-group-mode 115 gnus-group-mode
@@ -172,7 +164,7 @@
172 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) 164 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode))
173 (memq major-mode '(mh-letter-mode 165 (memq major-mode '(mh-letter-mode
174 mh-show-mode 166 mh-show-mode
175 mh-folder-mode)) 167 mh-folder-mode))
176 (memq major-mode '(gnus-summary-mode 168 (memq major-mode '(gnus-summary-mode
177 news-reply-mode 169 news-reply-mode
178 gnus-group-mode 170 gnus-group-mode
@@ -215,6 +207,19 @@
215 :prefix "msb-" 207 :prefix "msb-"
216 :group 'mouse) 208 :group 'mouse)
217 209
210;;;###autoload
211(defcustom msb-mode nil
212 "Toggle msb-mode.
213Setting this variable directly does not take effect;
214use either \\[customize] or the function `msb-mode'."
215 :set (lambda (symbol value)
216 (msb-mode (or value 0)))
217 :initialize 'custom-initialize-default
218 :version "20.4"
219 :type 'boolean
220 :group 'msb
221 :require 'msb)
222
218(defun msb-custom-set (symbol value) 223(defun msb-custom-set (symbol value)
219 "Set the value of custom variables for msb." 224 "Set the value of custom variables for msb."
220 (set symbol value) 225 (set symbol value)
@@ -230,7 +235,7 @@ The elements in the list should be of this type:
230 (CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLING-FN ITEM-SORT-FN). 235 (CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLING-FN ITEM-SORT-FN).
231 236
232When making the split, the buffers are tested one by one against the 237When making the split, the buffers are tested one by one against the
233CONDITION, just like a lisp cond: When hitting a true condition, the 238CONDITION, just like a Lisp cond: When hitting a true condition, the
234other criteria are *not* tested and the buffer name will appear in the 239other criteria are *not* tested and the buffer name will appear in the
235menu with the menu-title corresponding to the true condition. 240menu with the menu-title corresponding to the true condition.
236 241
@@ -378,8 +383,8 @@ Set this to nil or t if you don't want any sorting (faster)."
378) 383)
379 384
380(defcustom msb-files-by-directory nil 385(defcustom msb-files-by-directory nil
381 "*Non-nil means that files should be sorted by directory instead of 386 "*Non-nil means that files should be sorted by directory.
382the groups in msb-menu-cond." 387This is instead of the groups in `msb-menu-cond'."
383 :type 'boolean 388 :type 'boolean
384 :set 'msb-custom-set 389 :set 'msb-custom-set
385 :group 'msb) 390 :group 'msb)
@@ -466,14 +471,14 @@ The `#' appears only version control file (SCCS/RCS)."
466;;; Some example function to be used for `msb-item-sort-function'. 471;;; Some example function to be used for `msb-item-sort-function'.
467;;; 472;;;
468(defun msb-sort-by-name (item1 item2) 473(defun msb-sort-by-name (item1 item2)
469 "Sorts the items depending on their buffer-name 474 "Sort the items ITEM1 and ITEM2 by their `buffer-name'.
470An item look like (NAME . BUFFER)." 475An item looks like (NAME . BUFFER)."
471 (string-lessp (buffer-name (cdr item1)) 476 (string-lessp (buffer-name (cdr item1))
472 (buffer-name (cdr item2)))) 477 (buffer-name (cdr item2))))
473 478
474 479
475(defun msb-sort-by-directory (item1 item2) 480(defun msb-sort-by-directory (item1 item2)
476 "Sorts the items depending on their directory. Made for dired. 481 "Sort the items ITEM1 and ITEM2 by directory name. Made for dired.
477An item look like (NAME . BUFFER)." 482An item look like (NAME . BUFFER)."
478 (string-lessp (save-excursion (set-buffer (cdr item1)) 483 (string-lessp (save-excursion (set-buffer (cdr item1))
479 (msb--dired-directory)) 484 (msb--dired-directory))
@@ -689,7 +694,7 @@ If the argument is left out or nil, then the current buffer is considered."
689 tmp-s 694 tmp-s
690 msb-item-sort-function))) 695 msb-item-sort-function)))
691 (when (< (length menu-cond-elt) 3) 696 (when (< (length menu-cond-elt) 3)
692 (error "Wrong format of msb-menu-cond.")) 697 (error "Wrong format of msb-menu-cond"))
693 (when (and (> (length menu-cond-elt) 3) 698 (when (and (> (length menu-cond-elt) 3)
694 (not (fboundp tmp-ih))) 699 (not (fboundp tmp-ih)))
695 (signal 'invalid-function (list tmp-ih))) 700 (signal 'invalid-function (list tmp-ih)))
@@ -832,7 +837,7 @@ If the argument is left out or nil, then the current buffer is considered."
832 (list `( eq major-mode (quote ,(car item))) 837 (list `( eq major-mode (quote ,(car item)))
833 key 838 key
834 (concat (cdr item) " (%d)"))) 839 (concat (cdr item) " (%d)")))
835 (sort 840 (sort
836 (let ((mode-list nil)) 841 (let ((mode-list nil))
837 (mapc (lambda (buffer) 842 (mapc (lambda (buffer)
838 (save-excursion 843 (save-excursion
@@ -1045,7 +1050,7 @@ variable `msb-menu-cond'."
1045 (lambda (item) 1050 (lambda (item)
1046 (cond 1051 (cond
1047 ((and msb-separator-diff 1052 ((and msb-separator-diff
1048 last-key 1053 last-key
1049 (> (- (car item) last-key) 1054 (> (- (car item) last-key)
1050 msb-separator-diff)) 1055 msb-separator-diff))
1051 (setq last-key (car item)) 1056 (setq last-key (car item))
@@ -1094,7 +1099,7 @@ variable `msb-menu-cond'."
1094 (mcount 0)) 1099 (mcount 0))
1095 (mapcar 1100 (mapcar
1096 (lambda (sub-menu) 1101 (lambda (sub-menu)
1097 (cond 1102 (cond
1098 ((eq 'separator sub-menu) 1103 ((eq 'separator sub-menu)
1099 (list 'separator "--")) 1104 (list 'separator "--"))
1100 (t 1105 (t
@@ -1151,21 +1156,30 @@ variable `msb-menu-cond'."
1151 (cddr buffers-menu)) 1156 (cddr buffers-menu))
1152 (or buffers-menu 'undefined))))))) 1157 (or buffers-menu 'undefined)))))))
1153 1158
1154(when (and (boundp 'menu-bar-update-hook) 1159;; Snarf current bindings of `mouse-buffer-menu' (normally
1155 (not (fboundp 'frame-or-buffer-changed-p))) 1160;; C-down-mouse-1).
1156 (defvar msb--buffer-count 0) 1161(defvar msb-mode-map
1157 (defun frame-or-buffer-changed-p () 1162 (let ((map (make-sparse-keymap)))
1158 (let ((count (length (buffer-list)))) 1163 (mapcar (lambda (key)
1159 (when (/= count msb--buffer-count) 1164 (define-key map key #'msb))
1160 (setq msb--buffer-count count) 1165 (where-is-internal 'mouse-buffer-menu (make-sparse-keymap)))
1161 t)))) 1166 map))
1162 1167
1163(unless (or (not (boundp 'menu-bar-update-hook)) 1168;;;###autoload
1164 (memq 'menu-bar-update-buffers menu-bar-update-hook)) 1169(defun msb-mode (&optional arg)
1165 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) 1170 "Toggle Msb mode.
1166 1171With arg, turn Msb mode on if and only if arg is positive.
1167(and (fboundp 'mouse-buffer-menu) 1172This mode overrides the binding(s) of `mouse-buffer-menu' to provide a
1168 (substitute-key-definition 'mouse-buffer-menu 'msb (current-global-map))) 1173different buffer menu using the function `msb'."
1174 (interactive "P")
1175 (setq msb-mode (if arg
1176 (> (prefix-numeric-value arg) 0)
1177 (not msb-mode)))
1178 (if msb-mode
1179 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)
1180 (remove-hook 'menu-bar-update-hook 'menu-bar-update-buffers)))
1181
1182(add-to-list 'minor-mode-map-alist (cons 'msb-mode msb-mode-map))
1169 1183
1170(provide 'msb) 1184(provide 'msb)
1171(eval-after-load 'msb (run-hooks 'msb-after-load-hooks)) 1185(eval-after-load 'msb (run-hooks 'msb-after-load-hooks))