diff options
| author | Dave Love | 1999-07-23 22:57:32 +0000 |
|---|---|---|
| committer | Dave Love | 1999-07-23 22:57:32 +0000 |
| commit | eed3065994faf2d48338359c839cb0ee49444626 (patch) | |
| tree | 2ee559f20111cc0ee65ec7948b080f4d13f9e12a | |
| parent | a33209e8ef4da4f1b7db38d87db7f8bbfec4ace6 (diff) | |
| download | emacs-eed3065994faf2d48338359c839cb0ee49444626.tar.gz emacs-eed3065994faf2d48338359c839cb0ee49444626.zip | |
(msb-menu-bar-update-buffers): Renamed from
menu-bar-update-buffers.
(msb-custom-set, msb--toggle-menu-type): Call
msb-menu-bar-update-buffers.
(msb-mode): Revise the hook setting.
| -rw-r--r-- | lisp/msb.el | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/lisp/msb.el b/lisp/msb.el index 60bad741713..9d523a666a5 100644 --- a/lisp/msb.el +++ b/lisp/msb.el | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1993, 94, 95, 97, 98, 99 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 | ;; Maintainer: FSF | ||
| 6 | ;; Created: 8 Oct 1993 | 7 | ;; Created: 8 Oct 1993 |
| 7 | ;; Lindberg's last update version: 3.34 | 8 | ;; Lindberg's last update version: 3.34 |
| 8 | ;; Keywords: mouse buffer menu | 9 | ;; Keywords: mouse buffer menu |
| @@ -223,11 +224,10 @@ use either \\[customize] or the function `msb-mode'." | |||
| 223 | (defun msb-custom-set (symbol value) | 224 | (defun msb-custom-set (symbol value) |
| 224 | "Set the value of custom variables for msb." | 225 | "Set the value of custom variables for msb." |
| 225 | (set symbol value) | 226 | (set symbol value) |
| 226 | (if (featurep 'msb) | 227 | (if (and (featurep 'msb) msb-mode) |
| 227 | ;; wait until package has been loaded before bothering to update | 228 | ;; wait until package has been loaded before bothering to update |
| 228 | ;; the buffer lists. | 229 | ;; the buffer lists. |
| 229 | (menu-bar-update-buffers t)) | 230 | (msb-menu-bar-update-buffers t))) |
| 230 | ) | ||
| 231 | 231 | ||
| 232 | (defcustom msb-menu-cond msb--very-many-menus | 232 | (defcustom msb-menu-cond msb--very-many-menus |
| 233 | "*List of criteria for splitting the mouse buffer menu. | 233 | "*List of criteria for splitting the mouse buffer menu. |
| @@ -517,8 +517,8 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 517 | (and (> (length (buffer-name buffer)) 0) | 517 | (and (> (length (buffer-name buffer)) 0) |
| 518 | (eq ?\ (aref (buffer-name buffer) 0)))) | 518 | (eq ?\ (aref (buffer-name buffer) 0)))) |
| 519 | 519 | ||
| 520 | ;; Strip one hierarchy level from the end of DIR. | ||
| 521 | (defun msb--strip-dir (dir) | 520 | (defun msb--strip-dir (dir) |
| 521 | "Strip one hierarchy level from the end of DIR." | ||
| 522 | (file-name-directory (directory-file-name dir))) | 522 | (file-name-directory (directory-file-name dir))) |
| 523 | 523 | ||
| 524 | ;; Create an alist with all buffers from LIST that lies under the same | 524 | ;; Create an alist with all buffers from LIST that lies under the same |
| @@ -563,8 +563,8 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 563 | ;; Add the last result to the list | 563 | ;; Add the last result to the list |
| 564 | (list (cons path buffers)))))) | 564 | (list (cons path buffers)))))) |
| 565 | 565 | ||
| 566 | ;; Format a suitable title for the menu item. | ||
| 567 | (defun msb--format-title (top-found-p path number-of-items) | 566 | (defun msb--format-title (top-found-p path number-of-items) |
| 567 | "Format a suitable title for the menu item." | ||
| 568 | (let ((new-path path)) | 568 | (let ((new-path path)) |
| 569 | (when (and msb--home-dir | 569 | (when (and msb--home-dir |
| 570 | (string-match (concat "^" msb--home-dir) path)) | 570 | (string-match (concat "^" msb--home-dir) path)) |
| @@ -577,8 +577,8 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 577 | (defvar msb--choose-file-menu-list) | 577 | (defvar msb--choose-file-menu-list) |
| 578 | (defvar msb--choose-file-menu-arg-list) | 578 | (defvar msb--choose-file-menu-arg-list) |
| 579 | 579 | ||
| 580 | ;; Choose file-menu with respect to directory for every buffer in LIST. | ||
| 581 | (defun msb--choose-file-menu (list) | 580 | (defun msb--choose-file-menu (list) |
| 581 | "Choose file-menu with respect to directory for every buffer in LIST." | ||
| 582 | (setq msb--choose-file-menu-arg-list list) | 582 | (setq msb--choose-file-menu-arg-list list) |
| 583 | (let ((buffer-alist (msb--init-file-alist list)) | 583 | (let ((buffer-alist (msb--init-file-alist list)) |
| 584 | (final-list nil) | 584 | (final-list nil) |
| @@ -674,11 +674,11 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 674 | (setq top-found-p nil) | 674 | (setq top-found-p nil) |
| 675 | (nreverse final-list))) | 675 | (nreverse final-list))) |
| 676 | 676 | ||
| 677 | ;; Create a vector as: | ||
| 678 | ;; [BUFFER-LIST-VARIABLE CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLER SORTER) | ||
| 679 | ;; from an element in `msb-menu-cond'. See that variable for a | ||
| 680 | ;; description of its elements. | ||
| 681 | (defun msb--create-function-info (menu-cond-elt) | 677 | (defun msb--create-function-info (menu-cond-elt) |
| 678 | "Create a vector from an element MENU-COND-ELT of `msb-menu-cond'. | ||
| 679 | This takes the form: | ||
| 680 | \]BUFFER-LIST-VARIABLE CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLER SORTER) | ||
| 681 | See `msb-menu-cond' for a description of its elements." | ||
| 682 | (let* ((list-symbol (make-symbol "-msb-buffer-list")) | 682 | (let* ((list-symbol (make-symbol "-msb-buffer-list")) |
| 683 | (tmp-ih (and (> (length menu-cond-elt) 3) | 683 | (tmp-ih (and (> (length menu-cond-elt) 3) |
| 684 | (nth 3 menu-cond-elt))) | 684 | (nth 3 menu-cond-elt))) |
| @@ -737,10 +737,10 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 737 | (error "No catch-all in msb-menu-cond!")) | 737 | (error "No catch-all in msb-menu-cond!")) |
| 738 | function-info-list)) | 738 | function-info-list)) |
| 739 | 739 | ||
| 740 | ;; Adds BUFFER to the menu depicted by FUNCTION-INFO | ||
| 741 | ;; All side-effects. Adds an element of form (BUFFER-TITLE . BUFFER) | ||
| 742 | ;; to the buffer-list variable in function-info. | ||
| 743 | (defun msb--add-to-menu (buffer function-info max-buffer-name-length) | 740 | (defun msb--add-to-menu (buffer function-info max-buffer-name-length) |
| 741 | "Add BUFFER to the menu depicted by FUNCTION-INFO. | ||
| 742 | All side-effects. Adds an element of form (BUFFER-TITLE . BUFFER) | ||
| 743 | to the buffer-list variable in function-info." | ||
| 744 | (let ((list-symbol (aref function-info 0))) ;BUFFER-LIST-VARIABLE | 744 | (let ((list-symbol (aref function-info 0))) ;BUFFER-LIST-VARIABLE |
| 745 | ;; Here comes the hairy side-effect! | 745 | ;; Here comes the hairy side-effect! |
| 746 | (set list-symbol | 746 | (set list-symbol |
| @@ -750,10 +750,10 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 750 | buffer) | 750 | buffer) |
| 751 | (eval list-symbol))))) | 751 | (eval list-symbol))))) |
| 752 | 752 | ||
| 753 | ;; Selects the appropriate menu for BUFFER. | ||
| 754 | ;; This is all side-effects, folks! | ||
| 755 | ;; This should be optimized. | ||
| 756 | (defsubst msb--choose-menu (buffer function-info-vector max-buffer-name-length) | 753 | (defsubst msb--choose-menu (buffer function-info-vector max-buffer-name-length) |
| 754 | "Select the appropriate menu for BUFFER." | ||
| 755 | ;; This is all side-effects, folks! | ||
| 756 | ;; This should be optimized. | ||
| 757 | (unless (and (not msb-display-invisible-buffers-p) | 757 | (unless (and (not msb-display-invisible-buffers-p) |
| 758 | (msb-invisible-buffer-p buffer)) | 758 | (msb-invisible-buffer-p buffer)) |
| 759 | (condition-case nil | 759 | (condition-case nil |
| @@ -770,9 +770,8 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 770 | (buffer-name buffer))) | 770 | (buffer-name buffer))) |
| 771 | (error "%s" msb--error)))))) | 771 | (error "%s" msb--error)))))) |
| 772 | 772 | ||
| 773 | ;; Return (SORT-KEY TITLE . BUFFER-LIST) or nil if the | ||
| 774 | ;; buffer-list is empty. | ||
| 775 | (defun msb--create-sort-item (function-info) | 773 | (defun msb--create-sort-item (function-info) |
| 774 | "Return (SORT-KEY TITLE . BUFFER-LIST) or nil if the buffer-list is empty." | ||
| 776 | (let ((buffer-list (eval (aref function-info 0)))) | 775 | (let ((buffer-list (eval (aref function-info 0)))) |
| 777 | (when buffer-list | 776 | (when buffer-list |
| 778 | (let ((sorter (aref function-info 5)) ;SORTER | 777 | (let ((sorter (aref function-info 5)) ;SORTER |
| @@ -789,18 +788,21 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 789 | (t | 788 | (t |
| 790 | (sort buffer-list sorter)))))))))) | 789 | (sort buffer-list sorter)))))))))) |
| 791 | 790 | ||
| 792 | ;; Return ALIST as a sorted, aggregated alist, where all items with | ||
| 793 | ;; the same car element (according to SAME-PREDICATE) are aggregated | ||
| 794 | ;; together. The alist is first sorted by SORT-PREDICATE. | ||
| 795 | ;; Example: | ||
| 796 | ;; (msb--aggregate-alist | ||
| 797 | ;; '((a . a1) (a . a2) (b . b1) (c . c3) (a . a4) (a . a3) (b . b3) (b . b2)) | ||
| 798 | ;; (function string=) | ||
| 799 | ;; (lambda (item1 item2) | ||
| 800 | ;; (string< (symbol-name item1) (symbol-name item2)))) | ||
| 801 | ;; results in | ||
| 802 | ;; ((a a1 a2 a4 a3) (b b1 b3 b2) (c c3)) | ||
| 803 | (defun msb--aggregate-alist (alist same-predicate sort-predicate) | 791 | (defun msb--aggregate-alist (alist same-predicate sort-predicate) |
| 792 | "Return ALIST as a sorted, aggregated alist. | ||
| 793 | |||
| 794 | In the result all items with the same car element (according to | ||
| 795 | SAME-PREDICATE) are aggregated together. The alist is first sorted by | ||
| 796 | SORT-PREDICATE. | ||
| 797 | |||
| 798 | Example: | ||
| 799 | (msb--aggregate-alist | ||
| 800 | '((a . a1) (a . a2) (b . b1) (c . c3) (a . a4) (a . a3) (b . b3) (b . b2)) | ||
| 801 | (function string=) | ||
| 802 | (lambda (item1 item2) | ||
| 803 | (string< (symbol-name item1) (symbol-name item2)))) | ||
| 804 | results in | ||
| 805 | ((a a1 a2 a4 a3) (b b1 b3 b2) (c c3))" | ||
| 804 | (when (not (null alist)) | 806 | (when (not (null alist)) |
| 805 | (let (result | 807 | (let (result |
| 806 | same | 808 | same |
| @@ -851,9 +853,9 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 851 | (lambda (item1 item2) | 853 | (lambda (item1 item2) |
| 852 | (string< (cdr item1) (cdr item2))))))) | 854 | (string< (cdr item1) (cdr item2))))))) |
| 853 | 855 | ||
| 854 | ;; Returns a list on the form ((TITLE . BUFFER-LIST)) for | ||
| 855 | ;; the most recently used buffers. | ||
| 856 | (defun msb--most-recently-used-menu (max-buffer-name-length) | 856 | (defun msb--most-recently-used-menu (max-buffer-name-length) |
| 857 | "Return a list for the most recently used buffers. | ||
| 858 | It takes the form ((TITLE . BUFFER-LIST)...)." | ||
| 857 | (when (and (numberp msb-display-most-recently-used) | 859 | (when (and (numberp msb-display-most-recently-used) |
| 858 | (> msb-display-most-recently-used 0)) | 860 | (> msb-display-most-recently-used 0)) |
| 859 | (let* ((buffers (cdr (buffer-list))) | 861 | (let* ((buffers (cdr (buffer-list))) |
| @@ -981,15 +983,13 @@ If the argument is left out or nil, then the current buffer is considered." | |||
| 981 | (save-excursion | 983 | (save-excursion |
| 982 | (msb--create-buffer-menu-2)))) | 984 | (msb--create-buffer-menu-2)))) |
| 983 | 985 | ||
| 984 | ;;; | ||
| 985 | ;;; Multi purpose function for selecting a buffer with the mouse. | ||
| 986 | ;;; | ||
| 987 | (defun msb--toggle-menu-type () | 986 | (defun msb--toggle-menu-type () |
| 987 | "Multi purpose function for selecting a buffer with the mouse." | ||
| 988 | (interactive) | 988 | (interactive) |
| 989 | (setq msb-files-by-directory (not msb-files-by-directory)) | 989 | (setq msb-files-by-directory (not msb-files-by-directory)) |
| 990 | ;; This gets a warning, but it is correct, | 990 | ;; This gets a warning, but it is correct, |
| 991 | ;; because this file redefines menu-bar-update-buffers. | 991 | ;; because this file redefines menu-bar-update-buffers. |
| 992 | (menu-bar-update-buffers t)) | 992 | (msb-menu-bar-update-buffers t)) |
| 993 | 993 | ||
| 994 | (defun mouse-select-buffer (event) | 994 | (defun mouse-select-buffer (event) |
| 995 | "Pop up several menus of buffers, for selection with the mouse. | 995 | "Pop up several menus of buffers, for selection with the mouse. |
| @@ -1115,7 +1115,8 @@ variable `msb-menu-cond'." | |||
| 1115 | (msb--split-menus buffers)))))) | 1115 | (msb--split-menus buffers)))))) |
| 1116 | raw-menu))) | 1116 | raw-menu))) |
| 1117 | 1117 | ||
| 1118 | (defun menu-bar-update-buffers (&optional arg) | 1118 | (defun msb-menu-bar-update-buffers (&optional arg) |
| 1119 | "A re-written version of `menu-bar-update-buffers'." | ||
| 1119 | ;; If user discards the Buffers item, play along. | 1120 | ;; If user discards the Buffers item, play along. |
| 1120 | (when (and (lookup-key (current-global-map) [menu-bar buffer]) | 1121 | (when (and (lookup-key (current-global-map) [menu-bar buffer]) |
| 1121 | (or (not (fboundp 'frame-or-buffer-changed-p)) | 1122 | (or (not (fboundp 'frame-or-buffer-changed-p)) |
| @@ -1176,8 +1177,12 @@ different buffer menu using the function `msb'." | |||
| 1176 | (> (prefix-numeric-value arg) 0) | 1177 | (> (prefix-numeric-value arg) 0) |
| 1177 | (not msb-mode))) | 1178 | (not msb-mode))) |
| 1178 | (if msb-mode | 1179 | (if msb-mode |
| 1179 | (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers) | 1180 | (progn |
| 1180 | (remove-hook 'menu-bar-update-hook 'menu-bar-update-buffers))) | 1181 | (add-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers) |
| 1182 | (remove-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) | ||
| 1183 | (remove-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers) | ||
| 1184 | (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) | ||
| 1185 | (run-hooks 'menu-bar-update-hook)) | ||
| 1181 | 1186 | ||
| 1182 | (add-to-list 'minor-mode-map-alist (cons 'msb-mode msb-mode-map)) | 1187 | (add-to-list 'minor-mode-map-alist (cons 'msb-mode msb-mode-map)) |
| 1183 | 1188 | ||