Mercurial > emacs
annotate lisp/msb.el @ 25095:514b71b0b8f8
Require cl only when compiling.
(msb--home-dir): Deleted.
(msb--format-title): Use abbreviate-file-name.
(msb--choose-file-menu): Simplify string comparison.
| author | Dave Love <fx@gnu.org> |
|---|---|
| date | Wed, 28 Jul 1999 16:46:30 +0000 |
| parents | 1539c0070dd3 |
| children | abf35a5606f6 |
| rev | line source |
|---|---|
| 10228 | 1 ;;; msb.el --- Customizable buffer-selection with multiple menus. |
| 14169 | 2 |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
3 ;; Copyright (C) 1993, 94, 95, 97, 98, 99 Free Software Foundation, Inc. |
| 14169 | 4 |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
5 ;; Author: Lars Lindberg <Lars.G.Lindberg@capgemini.se> |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
6 ;; Maintainer: FSF |
| 10228 | 7 ;; Created: 8 Oct 1993 |
| 20901 | 8 ;; Lindberg's last update version: 3.34 |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
9 ;; Keywords: mouse buffer menu |
| 14169 | 10 |
| 11 ;; This file is part of GNU Emacs. | |
| 12 | |
| 13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 10228 | 14 ;; it under the terms of the GNU General Public License as published by |
| 14169 | 15 ;; the Free Software Foundation; either version 2, or (at your option) |
| 16 ;; any later version. | |
| 17 | |
| 18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 10228 | 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 ;; GNU General Public License for more details. | |
| 14169 | 22 |
| 10228 | 23 ;; You should have received a copy of the GNU General Public License |
| 14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| 25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 26 ;; Boston, MA 02111-1307, USA. | |
| 10228 | 27 |
| 28 ;;; Commentary: | |
| 14169 | 29 |
| 10228 | 30 ;; Purpose of this package: |
| 31 ;; 1. Offer a function for letting the user choose buffer, | |
| 32 ;; not necessarily for switching to it. | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
33 ;; 2. Make a better mouse-buffer-menu. This is done as a global |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
34 ;; minor mode, msb-mode. |
| 10228 | 35 ;; |
| 36 ;; Customization: | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
37 ;; Look at the variable `msb-menu-cond' for deciding what menus you |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
38 ;; want. It's not that hard to customize, despite my not-so-good |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
39 ;; doc-string. Feel free to send me a better doc-string. |
| 10228 | 40 ;; There are some constants for you to try here: |
| 41 ;; msb--few-menus | |
| 42 ;; msb--very-many-menus (default) | |
| 20901 | 43 ;; |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
44 ;; Look at the variable `msb-item-handling-function' for customization |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
45 ;; of the appearance of every menu item. Try for instance setting |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
46 ;; it to `msb-alon-item-handler'. |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
47 ;; |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
48 ;; Look at the variable `msb-item-sort-function' for customization |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
49 ;; of sorting the menus. Set it to t for instance, which means no |
| 10228 | 50 ;; sorting - you will get latest used buffer first. |
| 51 ;; | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
52 ;; Also check out the variable `msb-display-invisible-buffers-p'. |
| 10228 | 53 |
| 54 ;; Known bugs: | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
55 ;; - Files-by-directory |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
56 ;; + No possibility to show client/changed buffers separately. |
| 20901 | 57 ;; + All file buffers only appear in a file sub-menu, they will |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
58 ;; for instance not appear in the Mail sub-menu. |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
59 |
| 10228 | 60 ;; Future enhancements: |
| 61 | |
| 62 ;;; Thanks goes to | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
63 ;; Mark Brader <msb@sq.com> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
64 ;; Jim Berry <m1jhb00@FRB.GOV> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
65 ;; Hans Chalupsky <hans@cs.Buffalo.EDU> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
66 ;; Larry Rosenberg <ljr@ictv.com> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
67 ;; Will Henney <will@astroscu.unam.mx> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
68 ;; Jari Aalto <jaalto@tre.tele.nokia.fi> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
69 ;; Michael Kifer <kifer@sbkifer.cs.sunysb.edu> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
70 ;; Gael Marziou <gael@gnlab030.grenoble.hp.com> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
71 ;; Dave Gillespie <daveg@thymus.synaptics.com> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
72 ;; Alon Albert <alon@milcse.rtsg.mot.com> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
73 ;; Kevin Broadey, <KevinB@bartley.demon.co.uk> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
74 ;; Ake Stenhof <ake@cadpoint.se> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
75 ;; Richard Stallman <rms@gnu.ai.mit.edu> |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
76 ;; Steve Fisk <fisk@medved.bowdoin.edu> |
| 10228 | 77 |
| 25095 | 78 ;; This version turned into a global minor mode and subsequently |
| 79 ;; hacked on by Dave Love. | |
| 10228 | 80 ;;; Code: |
| 81 | |
| 25095 | 82 (eval-when-compile (require 'cl)) |
| 10228 | 83 |
| 84 ;;; | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
85 ;;; Some example constants to be used for `msb-menu-cond'. See that |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
86 ;;; variable for more information. Please note that if the condition |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
87 ;;; returns `multi', then the buffer can appear in several menus. |
| 10228 | 88 ;;; |
| 89 (defconst msb--few-menus | |
| 90 '(((and (boundp 'server-buffer-clients) | |
| 91 server-buffer-clients | |
| 92 'multi) | |
| 93 3030 | |
| 94 "Clients (%d)") | |
| 95 ((and msb-display-invisible-buffers-p | |
| 96 (msb-invisible-buffer-p) | |
| 97 'multi) | |
| 98 3090 | |
| 99 "Invisible buffers (%d)") | |
| 100 ((eq major-mode 'dired-mode) | |
| 101 2010 | |
| 102 "Dired (%d)" | |
| 103 msb-dired-item-handler | |
| 104 msb-sort-by-directory) | |
| 105 ((eq major-mode 'Man-mode) | |
| 106 4090 | |
| 107 "Manuals (%d)") | |
| 108 ((eq major-mode 'w3-mode) | |
| 109 4020 | |
| 110 "WWW (%d)") | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
111 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) |
| 10228 | 112 (memq major-mode '(mh-letter-mode |
| 113 mh-show-mode | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
114 mh-folder-mode)) |
| 10228 | 115 (memq major-mode '(gnus-summary-mode |
| 116 news-reply-mode | |
| 117 gnus-group-mode | |
| 118 gnus-article-mode | |
| 119 gnus-kill-file-mode | |
| 120 gnus-browse-killed-mode))) | |
| 121 4010 | |
| 122 "Mail (%d)") | |
| 123 ((not buffer-file-name) | |
| 124 4099 | |
| 125 "Buffers (%d)") | |
| 126 ('no-multi | |
| 127 1099 | |
| 128 "Files (%d)"))) | |
| 129 | |
| 130 (defconst msb--very-many-menus | |
| 131 '(((and (boundp 'server-buffer-clients) | |
| 132 server-buffer-clients | |
| 133 'multi) | |
| 134 1010 | |
| 135 "Clients (%d)") | |
| 136 ((and (boundp 'vc-mode) vc-mode 'multi) | |
| 137 1020 | |
| 138 "Version Control (%d)") | |
| 139 ((and buffer-file-name | |
| 140 (buffer-modified-p) | |
| 141 'multi) | |
| 142 1030 | |
| 143 "Changed files (%d)") | |
| 144 ((and (get-buffer-process (current-buffer)) | |
| 145 'multi) | |
| 146 1040 | |
| 147 "Processes (%d)") | |
| 148 ((and msb-display-invisible-buffers-p | |
| 149 (msb-invisible-buffer-p) | |
| 150 'multi) | |
| 151 1090 | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
152 "Invisible buffers (%d)") |
| 10228 | 153 ((eq major-mode 'dired-mode) |
| 154 2010 | |
| 155 "Dired (%d)" | |
| 156 ;; Note this different menu-handler | |
| 157 msb-dired-item-handler | |
| 158 ;; Also note this item-sorter | |
| 159 msb-sort-by-directory) | |
| 160 ((eq major-mode 'Man-mode) | |
| 20901 | 161 5030 |
| 10228 | 162 "Manuals (%d)") |
| 163 ((eq major-mode 'w3-mode) | |
| 20901 | 164 5020 |
| 10228 | 165 "WWW (%d)") |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
166 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) |
| 10228 | 167 (memq major-mode '(mh-letter-mode |
| 168 mh-show-mode | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
169 mh-folder-mode)) |
| 10228 | 170 (memq major-mode '(gnus-summary-mode |
| 171 news-reply-mode | |
| 172 gnus-group-mode | |
| 173 gnus-article-mode | |
| 174 gnus-kill-file-mode | |
| 175 gnus-browse-killed-mode))) | |
| 20901 | 176 5010 |
| 10228 | 177 "Mail (%d)") |
| 178 ;; Catchup for all non-file buffers | |
| 179 ((and (not buffer-file-name) | |
| 180 'no-multi) | |
| 20901 | 181 5099 |
| 10228 | 182 "Other non-file buffers (%d)") |
| 183 ((and (string-match "/\\.[^/]*$" buffer-file-name) | |
| 184 'multi) | |
| 185 3090 | |
| 186 "Hidden Files (%d)") | |
| 187 ((memq major-mode '(c-mode c++-mode)) | |
| 188 3010 | |
| 189 "C/C++ Files (%d)") | |
| 190 ((eq major-mode 'emacs-lisp-mode) | |
| 191 3020 | |
| 192 "Elisp Files (%d)") | |
| 193 ((eq major-mode 'latex-mode) | |
| 194 3030 | |
| 195 "LaTex Files (%d)") | |
| 196 ('no-multi | |
| 197 3099 | |
| 198 "Other files (%d)"))) | |
| 199 | |
| 200 ;; msb--many-menus is obsolete | |
| 201 (defvar msb--many-menus msb--very-many-menus) | |
| 202 | |
| 203 ;;; | |
| 204 ;;; Customizable variables | |
| 205 ;;; | |
| 206 | |
| 20901 | 207 (defgroup msb nil |
| 208 "Customizable buffer-selection with multiple menus." | |
| 209 :prefix "msb-" | |
| 210 :group 'mouse) | |
| 10228 | 211 |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
212 ;;;###autoload |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
213 (defcustom msb-mode nil |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
214 "Toggle msb-mode. |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
215 Setting this variable directly does not take effect; |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
216 use either \\[customize] or the function `msb-mode'." |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
217 :set (lambda (symbol value) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
218 (msb-mode (or value 0))) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
219 :initialize 'custom-initialize-default |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
220 :version "20.4" |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
221 :type 'boolean |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
222 :group 'msb |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
223 :require 'msb) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
224 |
| 20901 | 225 (defun msb-custom-set (symbol value) |
| 226 "Set the value of custom variables for msb." | |
| 227 (set symbol value) | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
228 (if (and (featurep 'msb) msb-mode) |
| 20901 | 229 ;; wait until package has been loaded before bothering to update |
| 230 ;; the buffer lists. | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
231 (msb-menu-bar-update-buffers t))) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
232 |
| 20901 | 233 (defcustom msb-menu-cond msb--very-many-menus |
|
13998
2f2d3995b57f
(msb-max-file-menu-items, msb-menu-cond): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
13372
diff
changeset
|
234 "*List of criteria for splitting the mouse buffer menu. |
| 10228 | 235 The elements in the list should be of this type: |
| 236 (CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLING-FN ITEM-SORT-FN). | |
| 237 | |
| 238 When making the split, the buffers are tested one by one against the | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
239 CONDITION, just like a Lisp cond: When hitting a true condition, the |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
240 other criteria are *not* tested and the buffer name will appear in the |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
241 menu with the menu-title corresponding to the true condition. |
| 10228 | 242 |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
243 If the condition returns the symbol `multi', then the buffer will be |
| 10228 | 244 added to this menu *and* tested for other menus too. If it returns |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
245 `no-multi', then the buffer will only be added if it hasn't been added |
| 10228 | 246 to any other menu. |
| 247 | |
| 248 During this test, the buffer in question is the current buffer, and | |
| 249 the test is surrounded by calls to `save-excursion' and | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
250 `save-match-data'. |
| 10228 | 251 |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
252 The categories are sorted by MENU-SORT-KEY. Smaller keys are on top. |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
253 nil means don't display this menu. |
| 10228 | 254 |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
255 MENU-TITLE is really a format. If you add %d in it, the %d is |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
256 replaced with the number of items in that menu. |
| 10228 | 257 |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
258 ITEM-HANDLING-FN, is optional. If it is supplied and is a function, |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
259 than it is used for displaying the items in that particular buffer |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
260 menu, otherwise the function pointed out by |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
261 `msb-item-handling-function' is used. |
| 10228 | 262 |
| 263 ITEM-SORT-FN, is also optional. | |
| 264 If it is not supplied, the function pointed out by | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
265 `msb-item-sort-function' is used. |
| 10228 | 266 If it is nil, then no sort takes place and the buffers are presented |
| 267 in least-recently-used order. | |
| 268 If it is t, then no sort takes place and the buffers are presented in | |
| 269 most-recently-used order. | |
| 270 If it is supplied and non-nil and not t than it is used for sorting | |
| 271 the items in that particular buffer menu. | |
| 272 | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
273 Note1: There should always be a `catch-all' as last element, in this |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
274 list. That is an element like (t TITLE ITEM-HANDLING-FUNCTION). |
| 10228 | 275 Note2: A buffer menu appears only if it has at least one buffer in it. |
| 276 Note3: If you have a CONDITION that can't be evaluated you will get an | |
| 20901 | 277 error every time you do \\[msb]." |
| 278 :type `(choice (const :tag "long" :value ,msb--very-many-menus) | |
| 279 (const :tag "short" :value ,msb--few-menus)) | |
| 280 :set 'msb-custom-set | |
| 281 :group 'msb) | |
| 282 | |
| 283 (defcustom msb-modes-key 4000 | |
| 284 "The sort key for files sorted by mode." | |
| 285 :type 'integer | |
| 286 :set 'msb-custom-set | |
|
21670
808ecc2eaa84
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20901
diff
changeset
|
287 :group 'msb |
|
808ecc2eaa84
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20901
diff
changeset
|
288 :version "20.3") |
| 20901 | 289 |
| 290 (defcustom msb-separator-diff 100 | |
| 291 "*Non-nil means use separators. | |
| 292 The separators will appear between all menus that have a sorting key | |
| 293 that differs by this value or more." | |
| 294 :type '(choice integer (const nil)) | |
| 295 :set 'msb-custom-set | |
| 296 :group 'msb) | |
| 297 | |
| 298 (defvar msb-files-by-directory-sort-key 0 | |
| 299 "*The sort key for files sorted by directory.") | |
| 300 | |
| 301 (defcustom msb-max-menu-items 15 | |
| 302 "*The maximum number of items in a menu. | |
| 303 If this variable is set to 15 for instance, then the submenu will be | |
| 304 split up in minor parts, 15 items each. Nil means no limit." | |
| 305 :type '(choice integer (const nil)) | |
| 306 :set 'msb-custom-set | |
| 307 :group 'msb) | |
| 308 | |
| 309 (defcustom msb-max-file-menu-items 10 | |
| 310 "*The maximum number of items from different directories. | |
| 311 | |
| 312 When the menu is of type `file by directory', this is the maximum | |
| 313 number of buffers that are clumped together from different | |
| 314 directories. | |
| 315 | |
| 316 Set this to 1 if you want one menu per directory instead of clumping | |
| 317 them together. | |
| 318 | |
| 319 If the value is not a number, then the value 10 is used." | |
| 320 :type 'integer | |
| 321 :set 'msb-custom-set | |
| 322 :group 'msb) | |
| 323 | |
| 324 (defcustom msb-most-recently-used-sort-key -1010 | |
| 325 "*Where should the menu with the most recently used buffers be placed?" | |
| 326 :type 'integer | |
| 327 :set 'msb-custom-set | |
| 328 :group 'msb) | |
| 329 | |
| 330 (defcustom msb-display-most-recently-used 15 | |
| 331 "*How many buffers should be in the most-recently-used menu. | |
| 332 No buffers at all if less than 1 or nil (or any non-number)." | |
| 333 :type 'integer | |
| 334 :set 'msb-custom-set | |
| 335 :group 'msb) | |
| 10228 | 336 |
| 20901 | 337 (defcustom msb-most-recently-used-title "Most recently used (%d)" |
| 338 "*The title for the most-recently-used menu." | |
| 339 :type 'string | |
| 340 :set 'msb-custom-set | |
| 341 :group 'msb) | |
| 342 | |
| 343 (defvar msb-horizontal-shift-function '(lambda () 0) | |
| 344 "*Function that specifies how many pixels to shift the top menu leftwards.") | |
| 345 | |
| 346 (defcustom msb-display-invisible-buffers-p nil | |
| 347 "*Show invisible buffers or not. | |
| 348 Non-nil means that the buffer menu should include buffers that have | |
| 349 names that starts with a space character." | |
| 350 :type 'boolean | |
| 351 :set 'msb-custom-set | |
| 352 :group 'msb) | |
| 353 | |
| 354 (defvar msb-item-handling-function 'msb-item-handler | |
| 355 "*The appearance of a buffer menu. | |
| 356 | |
| 357 The default function to call for handling the appearance of a menu | |
| 358 item. It should take to arguments, BUFFER and MAX-BUFFER-NAME-LENGTH, | |
| 359 where the latter is the max length of all buffer names. | |
| 360 | |
| 361 The function should return the string to use in the menu. | |
| 362 | |
| 363 When the function is called, BUFFER is the current buffer. This | |
| 364 function is called for items in the variable `msb-menu-cond' that have | |
| 365 nil as ITEM-HANDLING-FUNCTION. See `msb-menu-cond' for more | |
| 366 information.") | |
| 367 | |
| 368 (defcustom msb-item-sort-function 'msb-sort-by-name | |
| 369 "*The order of items in a buffer menu. | |
| 370 | |
| 371 The default function to call for handling the order of items in a menu | |
| 372 item. This function is called like a sort function. The items look | |
| 373 like (ITEM-NAME . BUFFER). | |
| 374 | |
| 375 ITEM-NAME is the name of the item that will appear in the menu. | |
| 376 BUFFER is the buffer, this is not necessarily the current buffer. | |
| 377 | |
| 378 Set this to nil or t if you don't want any sorting (faster)." | |
| 379 :type '(choice (const msb-sort-by-name) | |
| 380 (const :tag "Newest first" t) | |
| 381 (const :tag "Oldest first" nil)) | |
| 382 :set 'msb-custom-set | |
| 383 :group 'msb | |
| 384 ) | |
| 385 | |
| 386 (defcustom msb-files-by-directory nil | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
387 "*Non-nil means that files should be sorted by directory. |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
388 This is instead of the groups in `msb-menu-cond'." |
| 20901 | 389 :type 'boolean |
| 390 :set 'msb-custom-set | |
| 391 :group 'msb) | |
| 392 | |
| 393 (defcustom msb-after-load-hooks nil | |
| 394 "Hooks to be run after the msb package has been loaded." | |
| 395 :type 'hook | |
| 396 :set 'msb-custom-set | |
| 397 :group 'msb) | |
| 10228 | 398 |
| 399 ;;; | |
| 400 ;;; Internal variables | |
| 401 ;;; | |
| 402 | |
| 403 ;; The last calculated menu. | |
| 404 (defvar msb--last-buffer-menu nil) | |
| 405 | |
| 406 ;; If this is non-nil, then it is a string that describes the error. | |
| 407 (defvar msb--error nil) | |
| 408 | |
| 409 ;;; | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
410 ;;; Some example function to be used for `msb-item-handling-function'. |
| 10228 | 411 ;;; |
| 412 (defun msb-item-handler (buffer &optional maxbuf) | |
| 413 "Create one string item, concerning BUFFER, for the buffer menu. | |
| 414 The item looks like: | |
| 415 *% <buffer-name> | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
416 The `*' appears only if the buffer is marked as modified. |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
417 The `%' appears only if the buffer is read-only. |
| 10228 | 418 Optional second argument MAXBUF is completely ignored." |
| 419 (let ((name (buffer-name)) | |
| 420 (modified (if (buffer-modified-p) "*" " ")) | |
| 421 (read-only (if buffer-read-only "%" " "))) | |
| 422 (format "%s%s %s" modified read-only name))) | |
| 423 | |
| 424 | |
| 425 (eval-when-compile (require 'dired)) | |
| 426 | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
427 ;; `dired' can be called with a list of the form (directory file1 file2 ...) |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
428 ;; which causes `dired-directory' to be in the same form. |
| 10228 | 429 (defun msb--dired-directory () |
| 430 (cond ((stringp dired-directory) | |
| 431 (abbreviate-file-name (expand-file-name dired-directory))) | |
| 432 ((consp dired-directory) | |
| 433 (abbreviate-file-name (expand-file-name (car dired-directory)))) | |
| 434 (t | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
435 (error "Unknown type of `dired-directory' in buffer %s" |
| 10228 | 436 (buffer-name))))) |
| 437 | |
| 438 (defun msb-dired-item-handler (buffer &optional maxbuf) | |
| 439 "Create one string item, concerning a dired BUFFER, for the buffer menu. | |
| 440 The item looks like: | |
| 441 *% <buffer-name> | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
442 The `*' appears only if the buffer is marked as modified. |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
443 The `%' appears only if the buffer is read-only. |
| 10228 | 444 Optional second argument MAXBUF is completely ignored." |
| 445 (let ((name (msb--dired-directory)) | |
| 446 (modified (if (buffer-modified-p) "*" " ")) | |
| 447 (read-only (if buffer-read-only "%" " "))) | |
| 448 (format "%s%s %s" modified read-only name))) | |
| 449 | |
| 450 (defun msb-alon-item-handler (buffer maxbuf) | |
| 451 "Create one string item for the buffer menu. | |
| 452 The item looks like: | |
| 453 <buffer-name> *%# <file-name> | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
454 The `*' appears only if the buffer is marked as modified. |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
455 The `%' appears only if the buffer is read-only. |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
456 The `#' appears only version control file (SCCS/RCS)." |
| 10228 | 457 (format (format "%%%ds %%s%%s%%s %%s" maxbuf) |
| 458 (buffer-name buffer) | |
| 459 (if (buffer-modified-p) "*" " ") | |
| 460 (if buffer-read-only "%" " ") | |
| 461 (if (and (boundp 'vc-mode) vc-mode) "#" " ") | |
| 462 (or buffer-file-name ""))) | |
| 463 | |
| 464 ;;; | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
465 ;;; Some example function to be used for `msb-item-sort-function'. |
| 10228 | 466 ;;; |
| 467 (defun msb-sort-by-name (item1 item2) | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
468 "Sort the items ITEM1 and ITEM2 by their `buffer-name'. |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
469 An item looks like (NAME . BUFFER)." |
| 10228 | 470 (string-lessp (buffer-name (cdr item1)) |
| 471 (buffer-name (cdr item2)))) | |
| 472 | |
| 473 | |
| 474 (defun msb-sort-by-directory (item1 item2) | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
475 "Sort the items ITEM1 and ITEM2 by directory name. Made for dired. |
| 10228 | 476 An item look like (NAME . BUFFER)." |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
477 (string-lessp (save-excursion (set-buffer (cdr item1)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
478 (msb--dired-directory)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
479 (save-excursion (set-buffer (cdr item2)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
480 (msb--dired-directory)))) |
| 10228 | 481 |
| 482 ;;; | |
| 483 ;;; msb | |
| 484 ;;; | |
| 485 ;;; This function can be used instead of (mouse-buffer-menu EVENT) | |
| 486 ;;; function in "mouse.el". | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
487 ;;; |
| 10228 | 488 (defun msb (event) |
| 489 "Pop up several menus of buffers for selection with the mouse. | |
| 490 This command switches buffers in the window that you clicked on, and | |
| 491 selects that window. | |
| 492 | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
493 See the function `mouse-select-buffer' and the variable |
|
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
494 `msb-menu-cond' for more information about how the menus are split." |
| 10228 | 495 (interactive "e") |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
496 (let ((old-window (selected-window)) |
| 10228 | 497 (window (posn-window (event-start event)))) |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
498 (unless (framep window) (select-window window)) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
499 (let ((buffer (mouse-select-buffer event))) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
500 (if buffer |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
501 (switch-to-buffer buffer) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
502 (select-window old-window)))) |
| 10228 | 503 nil) |
| 504 | |
| 505 ;;; | |
| 506 ;;; Some supportive functions | |
| 507 ;;; | |
| 508 (defun msb-invisible-buffer-p (&optional buffer) | |
| 509 "Return t if optional BUFFER is an \"invisible\" buffer. | |
| 510 If the argument is left out or nil, then the current buffer is considered." | |
| 511 (and (> (length (buffer-name buffer)) 0) | |
| 512 (eq ?\ (aref (buffer-name buffer) 0)))) | |
| 513 | |
| 20505 | 514 (defun msb--strip-dir (dir) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
515 "Strip one hierarchy level from the end of DIR." |
|
20758
f5a113b108ff
(msb--strip-dir): Use Emacs filename primitives, not regexps.
Richard M. Stallman <rms@gnu.org>
parents:
20506
diff
changeset
|
516 (file-name-directory (directory-file-name dir))) |
| 10228 | 517 |
| 518 ;; Create an alist with all buffers from LIST that lies under the same | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
519 ;; directory will be in the same item as the directory string. |
|
20506
c096aa581013
Fix mailer-introduced garbling.
Richard M. Stallman <rms@gnu.org>
parents:
20505
diff
changeset
|
520 ;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K BUFFER-K+1...)) ...) |
| 10228 | 521 (defun msb--init-file-alist (list) |
| 522 (let ((buffer-alist | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
523 ;; Make alist that looks like |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
524 ;; ((PATH-1 BUFFER-1) (PATH-2 BUFFER-2) ...) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
525 ;; sorted on PATH-x |
| 10228 | 526 (sort (mapcan |
| 20901 | 527 (lambda (buffer) |
| 528 (let ((file-name (expand-file-name (buffer-file-name buffer)))) | |
| 529 (when file-name | |
| 530 (list (cons (msb--strip-dir file-name) buffer))))) | |
| 10228 | 531 list) |
| 20901 | 532 (lambda (item1 item2) |
| 533 (string< (car item1) (car item2)))))) | |
|
20884
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
534 ;; Now clump buffers together that have the same path |
| 10228 | 535 ;; Make alist that looks like |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
536 ;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K)) ...) |
| 10228 | 537 (let ((path nil) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
538 (buffers nil)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
539 (nconc |
| 20901 | 540 (mapcan (lambda (item) |
| 541 (cond | |
| 542 ((and path | |
| 543 (string= path (car item))) | |
| 544 ;; The same path as earlier: Add to current list of | |
| 545 ;; buffers. | |
| 546 (push (cdr item) buffers) | |
| 547 ;; This item should not be added to list | |
| 548 nil) | |
| 549 (t | |
| 550 ;; New path | |
| 551 (let ((result (and path (cons path buffers)))) | |
| 552 (setq path (car item)) | |
| 553 (setq buffers (list (cdr item))) | |
| 554 ;; Add the last result the list. | |
| 555 (and result (list result)))))) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
556 buffer-alist) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
557 ;; Add the last result to the list |
| 10228 | 558 (list (cons path buffers)))))) |
| 559 | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
560 (defun msb--format-title (top-found-p path number-of-items) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
561 "Format a suitable title for the menu item." |
| 25095 | 562 (format (if top-found-p "%s... (%d)" "%s (%d)") |
| 563 (abbreviate-file-name path) number-of-items)) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
564 |
|
20884
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
565 ;; Variables for debugging. |
|
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
566 (defvar msb--choose-file-menu-list) |
|
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
567 (defvar msb--choose-file-menu-arg-list) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
568 |
| 10228 | 569 (defun msb--choose-file-menu (list) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
570 "Choose file-menu with respect to directory for every buffer in LIST." |
|
20884
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
571 (setq msb--choose-file-menu-arg-list list) |
| 10228 | 572 (let ((buffer-alist (msb--init-file-alist list)) |
| 573 (final-list nil) | |
| 574 (max-clumped-together (if (numberp msb-max-file-menu-items) | |
| 575 msb-max-file-menu-items | |
| 576 10)) | |
| 577 (top-found-p nil) | |
| 578 (last-path nil) | |
| 20901 | 579 first rest path buffers old-path) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
580 ;; Prepare for looping over all items in buffer-alist |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
581 (setq first (car buffer-alist) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
582 rest (cdr buffer-alist) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
583 path (car first) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
584 buffers (cdr first)) |
|
20884
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
585 (setq msb--choose-file-menu-list (copy-list rest)) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
586 ;; This big loop tries to clump buffers together that have a |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
587 ;; similar name. Remember that buffer-alist is sorted based on the |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
588 ;; path for the buffers. |
| 10228 | 589 (while rest |
| 590 (let ((found-p nil) | |
| 591 (tmp-rest rest) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
592 result |
| 10228 | 593 new-path item) |
| 594 (setq item (car tmp-rest)) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
595 ;; Clump together the "rest"-buffers that have a path that is |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
596 ;; a subpath of the current one. |
| 10228 | 597 (while (and tmp-rest |
| 598 (<= (length buffers) max-clumped-together) | |
| 599 (>= (length (car item)) (length path)) | |
| 25095 | 600 (compare-strings path 0 nil (car item) 0 (length path))) |
| 10228 | 601 (setq found-p t) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
602 (setq buffers (append buffers (cdr item))) ;nconc is faster than append |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
603 (setq tmp-rest (cdr tmp-rest) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
604 item (car tmp-rest))) |
| 10228 | 605 (cond |
| 606 ((> (length buffers) max-clumped-together) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
607 ;; Oh, we failed. Too many buffers clumped together. |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
608 ;; Just use the original ones for the result. |
| 10228 | 609 (setq last-path (car first)) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
610 (push (cons (msb--format-title top-found-p |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
611 (car first) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
612 (length (cdr first))) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
613 (cdr first)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
614 final-list) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
615 (setq top-found-p nil) |
| 10228 | 616 (setq first (car rest) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
617 rest (cdr rest) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
618 path (car first) |
| 10228 | 619 buffers (cdr first))) |
| 620 (t | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
621 ;; The first pass of clumping together worked out, go ahead |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
622 ;; with this result. |
| 10228 | 623 (when found-p |
| 624 (setq top-found-p t) | |
| 625 (setq first (cons path buffers) | |
| 626 rest tmp-rest)) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
627 ;; Now see if we can clump more buffers together if we go up |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
628 ;; one step in the file hierarchy. |
| 20901 | 629 ;; If path isn't changed by msb--strip-dir, we are looking |
| 630 ;; at the machine name component of an ange-ftp filename. | |
| 631 (setq old-path path) | |
| 20505 | 632 (setq path (msb--strip-dir path) |
| 10228 | 633 buffers (cdr first)) |
| 20901 | 634 (if (equal old-path path) |
| 635 (setq last-path path)) | |
| 10228 | 636 (when (and last-path |
| 637 (or (and (>= (length path) (length last-path)) | |
| 25095 | 638 (compare-strings last-path 0 nil |
| 639 path 0 (length last-path))) | |
| 10228 | 640 (and (< (length path) (length last-path)) |
| 25095 | 641 (compare-strings path 0 nil |
| 642 last-path 0 (length path))))) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
643 ;; We have reached the same place in the file hierarchy as |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
644 ;; the last result, so we should quit at this point and |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
645 ;; take what we have as result. |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
646 (push (cons (msb--format-title top-found-p |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
647 (car first) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
648 (length (cdr first))) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
649 (cdr first)) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
650 final-list) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
651 (setq top-found-p nil) |
| 10228 | 652 (setq first (car rest) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
653 rest (cdr rest) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
654 path (car first) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
655 buffers (cdr first))))))) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
656 ;; Now take care of the last item. |
| 20901 | 657 (when first |
| 658 (push (cons (msb--format-title top-found-p | |
| 659 (car first) | |
| 660 (length (cdr first))) | |
| 661 (cdr first)) | |
| 662 final-list)) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
663 (setq top-found-p nil) |
| 10228 | 664 (nreverse final-list))) |
| 665 | |
| 666 (defun msb--create-function-info (menu-cond-elt) | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
667 "Create a vector from an element MENU-COND-ELT of `msb-menu-cond'. |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
668 This takes the form: |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
669 \]BUFFER-LIST-VARIABLE CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLER SORTER) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
670 See `msb-menu-cond' for a description of its elements." |
| 10228 | 671 (let* ((list-symbol (make-symbol "-msb-buffer-list")) |
| 672 (tmp-ih (and (> (length menu-cond-elt) 3) | |
| 673 (nth 3 menu-cond-elt))) | |
| 674 (item-handler (if (and tmp-ih (fboundp tmp-ih)) | |
| 675 tmp-ih | |
| 676 msb-item-handling-function)) | |
| 677 (tmp-s (if (> (length menu-cond-elt) 4) | |
| 678 (nth 4 menu-cond-elt) | |
| 679 msb-item-sort-function)) | |
| 680 (sorter (if (or (fboundp tmp-s) | |
| 681 (null tmp-s) | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
682 (eq tmp-s t)) |
| 10228 | 683 tmp-s |
| 684 msb-item-sort-function))) | |
| 685 (when (< (length menu-cond-elt) 3) | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
686 (error "Wrong format of msb-menu-cond")) |
| 10228 | 687 (when (and (> (length menu-cond-elt) 3) |
| 688 (not (fboundp tmp-ih))) | |
| 689 (signal 'invalid-function (list tmp-ih))) | |
| 690 (when (and (> (length menu-cond-elt) 4) | |
| 691 tmp-s | |
| 692 (not (fboundp tmp-s)) | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
693 (not (eq tmp-s t))) |
| 10228 | 694 (signal 'invalid-function (list tmp-s))) |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
695 (set list-symbol ()) |
| 10228 | 696 (vector list-symbol ;BUFFER-LIST-VARIABLE |
| 697 (nth 0 menu-cond-elt) ;CONDITION | |
| 698 (nth 1 menu-cond-elt) ;SORT-KEY | |
| 699 (nth 2 menu-cond-elt) ;MENU-TITLE | |
| 700 item-handler ;ITEM-HANDLER | |
| 701 sorter) ;SORTER | |
| 702 )) | |
| 703 | |
| 704 ;; This defsubst is only used in `msb--choose-menu' below. It was | |
| 20901 | 705 ;; pulled out merely to make the code somewhat clearer. The indentation |
| 10228 | 706 ;; level was too big. |
| 707 (defsubst msb--collect (function-info-vector) | |
| 708 (let ((result nil) | |
| 709 (multi-flag nil) | |
| 710 function-info-list) | |
| 711 (setq function-info-list | |
| 712 (loop for fi | |
| 713 across function-info-vector | |
| 714 if (and (setq result | |
| 715 (eval (aref fi 1))) ;Test CONDITION | |
| 716 (not (and (eq result 'no-multi) | |
| 717 multi-flag)) | |
| 718 (progn (when (eq result 'multi) | |
| 719 (setq multi-flag t)) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
720 t)) |
| 10228 | 721 collect fi |
| 722 until (and result | |
| 723 (not (eq result 'multi))))) | |
| 724 (when (and (not function-info-list) | |
| 725 (not result)) | |
| 726 (error "No catch-all in msb-menu-cond!")) | |
| 727 function-info-list)) | |
| 728 | |
| 729 (defun msb--add-to-menu (buffer function-info max-buffer-name-length) | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
730 "Add BUFFER to the menu depicted by FUNCTION-INFO. |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
731 All side-effects. Adds an element of form (BUFFER-TITLE . BUFFER) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
732 to the buffer-list variable in function-info." |
| 10228 | 733 (let ((list-symbol (aref function-info 0))) ;BUFFER-LIST-VARIABLE |
| 734 ;; Here comes the hairy side-effect! | |
| 735 (set list-symbol | |
| 736 (cons (cons (funcall (aref function-info 4) ;ITEM-HANDLER | |
| 737 buffer | |
| 738 max-buffer-name-length) | |
| 739 buffer) | |
| 740 (eval list-symbol))))) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
741 |
| 10228 | 742 (defsubst msb--choose-menu (buffer function-info-vector max-buffer-name-length) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
743 "Select the appropriate menu for BUFFER." |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
744 ;; This is all side-effects, folks! |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
745 ;; This should be optimized. |
| 10228 | 746 (unless (and (not msb-display-invisible-buffers-p) |
| 747 (msb-invisible-buffer-p buffer)) | |
| 748 (condition-case nil | |
| 749 (save-excursion | |
| 750 (set-buffer buffer) | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
751 ;; Menu found. Add to this menu |
| 20901 | 752 (mapc (lambda (function-info) |
| 753 (msb--add-to-menu buffer function-info max-buffer-name-length)) | |
| 10228 | 754 (msb--collect function-info-vector))) |
| 755 (error (unless msb--error | |
| 756 (setq msb--error | |
| 757 (format | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
758 "In msb-menu-cond, error for buffer `%s'." |
| 10228 | 759 (buffer-name buffer))) |
|
14427
ac3101efc47e
(msb--choose-menu): Fix error format string.
Karl Heuer <kwzh@gnu.org>
parents:
14292
diff
changeset
|
760 (error "%s" msb--error)))))) |
| 10228 | 761 |
| 762 (defun msb--create-sort-item (function-info) | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
763 "Return (SORT-KEY TITLE . BUFFER-LIST) or nil if the buffer-list is empty." |
| 10228 | 764 (let ((buffer-list (eval (aref function-info 0)))) |
| 765 (when buffer-list | |
| 766 (let ((sorter (aref function-info 5)) ;SORTER | |
| 767 (sort-key (aref function-info 2))) ;MENU-SORT-KEY | |
| 768 (when sort-key | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
769 (cons sort-key |
| 10228 | 770 (cons (format (aref function-info 3) ;MENU-TITLE |
| 771 (length buffer-list)) | |
| 772 (cond | |
| 773 ((null sorter) | |
| 774 buffer-list) | |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
775 ((eq sorter t) |
| 10228 | 776 (nreverse buffer-list)) |
| 777 (t | |
| 778 (sort buffer-list sorter)))))))))) | |
| 779 | |
| 20901 | 780 (defun msb--aggregate-alist (alist same-predicate sort-predicate) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
781 "Return ALIST as a sorted, aggregated alist. |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
782 |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
783 In the result all items with the same car element (according to |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
784 SAME-PREDICATE) are aggregated together. The alist is first sorted by |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
785 SORT-PREDICATE. |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
786 |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
787 Example: |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
788 (msb--aggregate-alist |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
789 '((a . a1) (a . a2) (b . b1) (c . c3) (a . a4) (a . a3) (b . b3) (b . b2)) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
790 (function string=) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
791 (lambda (item1 item2) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
792 (string< (symbol-name item1) (symbol-name item2)))) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
793 results in |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
794 ((a a1 a2 a4 a3) (b b1 b3 b2) (c c3))" |
| 20901 | 795 (when (not (null alist)) |
| 796 (let (result | |
| 797 same | |
| 798 tmp-old-car | |
| 799 tmp-same | |
| 800 (first-time-p t) | |
| 801 old-car) | |
| 802 (nconc | |
| 803 (mapcan (lambda (item) | |
| 804 (cond | |
| 805 (first-time-p | |
| 806 (push (cdr item) same) | |
| 807 (setq first-time-p nil) | |
| 808 (setq old-car (car item)) | |
| 809 nil) | |
| 810 ((funcall same-predicate (car item) old-car) | |
| 811 (push (cdr item) same) | |
| 812 nil) | |
| 813 (t | |
| 814 (setq tmp-same same | |
| 815 tmp-old-car old-car) | |
| 816 (setq same (list (cdr item)) | |
| 817 old-car (car item)) | |
| 818 (list (cons tmp-old-car (nreverse tmp-same)))))) | |
| 819 (sort alist (lambda (item1 item2) | |
| 820 (funcall sort-predicate (car item1) (car item2))))) | |
| 821 (list (cons old-car (nreverse same))))))) | |
| 822 | |
| 823 | |
| 824 (defun msb--mode-menu-cond () | |
| 825 (let ((key msb-modes-key)) | |
| 826 (mapcar (lambda (item) | |
| 827 (incf key) | |
| 828 (list `( eq major-mode (quote ,(car item))) | |
| 829 key | |
| 830 (concat (cdr item) " (%d)"))) | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
831 (sort |
| 20901 | 832 (let ((mode-list nil)) |
| 833 (mapc (lambda (buffer) | |
| 834 (save-excursion | |
| 835 (set-buffer buffer) | |
| 836 (when (and (not (msb-invisible-buffer-p)) | |
| 837 (not (assq major-mode mode-list)) | |
| 838 (push (cons major-mode mode-name) | |
| 839 mode-list))))) | |
| 840 (cdr (buffer-list))) | |
| 841 mode-list) | |
| 842 (lambda (item1 item2) | |
| 843 (string< (cdr item1) (cdr item2))))))) | |
| 844 | |
| 10228 | 845 (defun msb--most-recently-used-menu (max-buffer-name-length) |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
846 "Return a list for the most recently used buffers. |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
847 It takes the form ((TITLE . BUFFER-LIST)...)." |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
848 (when (and (numberp msb-display-most-recently-used) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
849 (> msb-display-most-recently-used 0)) |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
850 (let* ((buffers (cdr (buffer-list))) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
851 (most-recently-used |
| 10228 | 852 (loop with n = 0 |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
853 for buffer in buffers |
| 10228 | 854 if (save-excursion |
| 855 (set-buffer buffer) | |
| 856 (and (not (msb-invisible-buffer-p)) | |
| 857 (not (eq major-mode 'dired-mode)))) | |
| 858 collect (save-excursion | |
| 859 (set-buffer buffer) | |
| 860 (cons (funcall msb-item-handling-function | |
| 861 buffer | |
| 862 max-buffer-name-length) | |
| 863 buffer)) | |
| 864 and do (incf n) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
865 until (>= n msb-display-most-recently-used)))) |
| 10228 | 866 (cons (if (stringp msb-most-recently-used-title) |
| 867 (format msb-most-recently-used-title | |
| 868 (length most-recently-used)) | |
| 869 (signal 'wrong-type-argument (list msb-most-recently-used-title))) | |
| 870 most-recently-used)))) | |
| 871 | |
| 872 (defun msb--create-buffer-menu-2 () | |
| 873 (let ((max-buffer-name-length 0) | |
| 874 file-buffers | |
| 875 function-info-vector) | |
| 876 ;; Calculate the longest buffer name. | |
| 877 (mapc | |
| 20901 | 878 (lambda (buffer) |
| 879 (if (or msb-display-invisible-buffers-p | |
| 880 (not (msb-invisible-buffer-p))) | |
| 881 (setq max-buffer-name-length | |
| 882 (max max-buffer-name-length | |
| 883 (length (buffer-name buffer)))))) | |
| 10228 | 884 (buffer-list)) |
| 885 ;; Make a list with elements of type | |
| 886 ;; (BUFFER-LIST-VARIABLE | |
| 887 ;; CONDITION | |
| 888 ;; MENU-SORT-KEY | |
| 889 ;; MENU-TITLE | |
| 890 ;; ITEM-HANDLER | |
| 891 ;; SORTER) | |
| 892 ;; Uses "function-global" variables: | |
| 893 ;; function-info-vector | |
| 894 (setq function-info-vector | |
| 895 (apply (function vector) | |
| 896 (mapcar (function msb--create-function-info) | |
| 20901 | 897 (append msb-menu-cond (msb--mode-menu-cond))))) |
| 10228 | 898 ;; Split the buffer-list into several lists; one list for each |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
899 ;; criteria. This is the most critical part with respect to time. |
| 20901 | 900 (mapc (lambda (buffer) |
| 901 (cond ((and msb-files-by-directory | |
| 902 (buffer-file-name buffer) | |
| 903 ;; exclude ange-ftp buffers | |
| 904 ;;(not (string-match "\\/[^/:]+:" | |
| 905 ;; (buffer-file-name buffer))) | |
| 906 ) | |
| 907 (push buffer file-buffers)) | |
| 908 (t | |
| 909 (msb--choose-menu buffer | |
| 910 function-info-vector | |
| 911 max-buffer-name-length)))) | |
| 10228 | 912 (buffer-list)) |
| 913 (when file-buffers | |
| 914 (setq file-buffers | |
| 20901 | 915 (mapcar (lambda (buffer-list) |
| 916 (cons msb-files-by-directory-sort-key | |
| 917 (cons (car buffer-list) | |
| 918 (sort | |
| 919 (mapcar (function | |
| 920 (lambda (buffer) | |
| 921 (cons (save-excursion | |
| 922 (set-buffer buffer) | |
| 923 (funcall msb-item-handling-function | |
| 924 buffer | |
| 925 max-buffer-name-length)) | |
| 926 buffer))) | |
| 927 (cdr buffer-list)) | |
| 928 (function | |
| 929 (lambda (item1 item2) | |
| 930 (string< (car item1) (car item2)))))))) | |
| 10228 | 931 (msb--choose-file-menu file-buffers)))) |
| 932 ;; Now make the menu - a list of (TITLE . BUFFER-LIST) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
933 (let* (menu |
| 10228 | 934 (most-recently-used |
| 935 (msb--most-recently-used-menu max-buffer-name-length)) | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
936 (others (nconc file-buffers |
| 10228 | 937 (loop for elt |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
938 across function-info-vector |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
939 for value = (msb--create-sort-item elt) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
940 if value collect value)))) |
| 10228 | 941 (setq menu |
| 942 (mapcar 'cdr ;Remove the SORT-KEY | |
| 943 ;; Sort the menus - not the items. | |
| 944 (msb--add-separators | |
| 945 (sort | |
| 946 ;; Get a list of (SORT-KEY TITLE . BUFFER-LIST) | |
| 947 ;; Also sorts the items within the menus. | |
| 948 (if (cdr most-recently-used) | |
| 949 (cons | |
| 950 ;; Add most recent used buffers | |
| 951 (cons msb-most-recently-used-sort-key | |
| 952 most-recently-used) | |
| 953 others) | |
| 954 others) | |
| 20901 | 955 (lambda (elt1 elt2) |
| 956 (< (car elt1) (car elt2))))))) | |
| 10228 | 957 ;; Now make it a keymap menu |
| 958 (append | |
| 959 '(keymap "Select Buffer") | |
| 960 (msb--make-keymap-menu menu) | |
| 961 (when msb-separator-diff | |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
962 (list (list 'separator "--"))) |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
963 (list (cons 'toggle |
| 10228 | 964 (cons |
| 965 (if msb-files-by-directory | |
| 966 "*Files by type*" | |
| 967 "*Files by directory*") | |
| 968 'msb--toggle-menu-type))))))) | |
| 969 | |
| 970 (defun msb--create-buffer-menu () | |
| 971 (save-match-data | |
| 972 (save-excursion | |
| 973 (msb--create-buffer-menu-2)))) | |
| 974 | |
| 975 (defun msb--toggle-menu-type () | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
976 "Multi purpose function for selecting a buffer with the mouse." |
| 10228 | 977 (interactive) |
| 978 (setq msb-files-by-directory (not msb-files-by-directory)) | |
|
20884
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
979 ;; This gets a warning, but it is correct, |
|
91f9c828fc1a
(msb--choose-file-menu): Save some debugging info.
Richard M. Stallman <rms@gnu.org>
parents:
20758
diff
changeset
|
980 ;; because this file redefines menu-bar-update-buffers. |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
981 (msb-menu-bar-update-buffers t)) |
| 10228 | 982 |
| 983 (defun mouse-select-buffer (event) | |
| 984 "Pop up several menus of buffers, for selection with the mouse. | |
| 985 Returns the selected buffer or nil if no buffer is selected. | |
| 986 | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
987 The way the buffers are split is conveniently handled with the |
|
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
988 variable `msb-menu-cond'." |
| 10228 | 989 ;; Popup the menu and return the selected buffer. |
| 990 (when (or msb--error | |
| 991 (not msb--last-buffer-menu) | |
| 992 (not (fboundp 'frame-or-buffer-changed-p)) | |
| 993 (frame-or-buffer-changed-p)) | |
| 994 (setq msb--error nil) | |
| 995 (setq msb--last-buffer-menu (msb--create-buffer-menu))) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
996 (let ((position event) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
997 choice) |
| 10228 | 998 (when (and (fboundp 'posn-x-y) |
| 999 (fboundp 'posn-window)) | |
| 1000 (let ((posX (car (posn-x-y (event-start event)))) | |
| 1001 (posY (cdr (posn-x-y (event-start event)))) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1002 (posWind (posn-window (event-start event)))) |
| 10228 | 1003 ;; adjust position |
| 1004 (setq posX (- posX (funcall msb-horizontal-shift-function)) | |
| 1005 position (list (list posX posY) posWind)))) | |
|
10823
abd2a268ed88
(mouse-select-buffer): Do sit-for before x-popup-menu.
Richard M. Stallman <rms@gnu.org>
parents:
10821
diff
changeset
|
1006 ;; This `sit-for' magically makes the menu stay up if the mouse |
|
13998
2f2d3995b57f
(msb-max-file-menu-items, msb-menu-cond): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
13372
diff
changeset
|
1007 ;; button is released within 0.1 second. |
|
10823
abd2a268ed88
(mouse-select-buffer): Do sit-for before x-popup-menu.
Richard M. Stallman <rms@gnu.org>
parents:
10821
diff
changeset
|
1008 (sit-for 0 100) |
|
abd2a268ed88
(mouse-select-buffer): Do sit-for before x-popup-menu.
Richard M. Stallman <rms@gnu.org>
parents:
10821
diff
changeset
|
1009 ;; Popup the menu |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1010 (setq choice (x-popup-menu position msb--last-buffer-menu)) |
| 10228 | 1011 (cond |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1012 ((eq (car choice) 'toggle) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1013 ;; Bring up the menu again with type toggled. |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1014 (msb--toggle-menu-type) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1015 (mouse-select-buffer event)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1016 ((and (numberp (car choice)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1017 (null (cdr choice))) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1018 (let ((msb--last-buffer-menu (nthcdr 3 (assq (car choice) msb--last-buffer-menu)))) |
| 10228 | 1019 (mouse-select-buffer event))) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1020 ((while (numberp (car choice)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1021 (setq choice (cdr choice)))) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1022 ((and (stringp (car choice)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1023 (null (cdr choice))) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1024 (car choice)) |
|
10403
c0e27466fb3f
(mouse-select-buffer) Handle an aborted selection.
Richard M. Stallman <rms@gnu.org>
parents:
10371
diff
changeset
|
1025 ((null choice) |
|
c0e27466fb3f
(mouse-select-buffer) Handle an aborted selection.
Richard M. Stallman <rms@gnu.org>
parents:
10371
diff
changeset
|
1026 choice) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1027 (t |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1028 (error "Unknown form for buffer: %s" choice))))) |
| 20901 | 1029 |
| 10228 | 1030 ;; Add separators |
| 1031 (defun msb--add-separators (sorted-list) | |
| 1032 (cond | |
| 1033 ((or (not msb-separator-diff) | |
| 1034 (not (numberp msb-separator-diff))) | |
| 1035 sorted-list) | |
| 1036 (t | |
| 1037 (let ((last-key nil)) | |
| 1038 (mapcan | |
| 20901 | 1039 (lambda (item) |
| 1040 (cond | |
| 1041 ((and msb-separator-diff | |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1042 last-key |
| 20901 | 1043 (> (- (car item) last-key) |
| 1044 msb-separator-diff)) | |
| 1045 (setq last-key (car item)) | |
| 1046 (list (cons last-key 'separator) | |
| 1047 item)) | |
| 1048 (t | |
| 1049 (setq last-key (car item)) | |
| 1050 (list item)))) | |
| 10228 | 1051 sorted-list))))) |
| 1052 | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1053 (defun msb--split-menus-2 (list mcount result) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1054 (cond |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1055 ((> (length list) msb-max-menu-items) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1056 (let ((count 0) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1057 sub-name |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1058 (tmp-list nil)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1059 (while (< count msb-max-menu-items) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1060 (push (pop list) tmp-list) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1061 (incf count)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1062 (setq tmp-list (nreverse tmp-list)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1063 (setq sub-name (concat (car (car tmp-list)) "...")) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1064 (push (nconc (list mcount sub-name |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1065 'keymap sub-name) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1066 tmp-list) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1067 result)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1068 (msb--split-menus-2 list (1+ mcount) result)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1069 ((null result) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1070 list) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1071 (t |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1072 (let (sub-name) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1073 (setq sub-name (concat (car (car list)) "...")) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1074 (push (nconc (list mcount sub-name |
|
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1075 'keymap sub-name) |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1076 list) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1077 result)) |
|
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1078 (nreverse result)))) |
| 20901 | 1079 |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1080 (defun msb--split-menus (list) |
| 20901 | 1081 (if (and (integerp msb-max-menu-items) |
| 1082 (> msb-max-menu-items 0)) | |
| 1083 (msb--split-menus-2 list 0 nil) | |
| 1084 list)) | |
|
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
1085 |
| 10228 | 1086 (defun msb--make-keymap-menu (raw-menu) |
| 1087 (let ((end (cons '(nil) 'menu-bar-select-buffer)) | |
| 1088 (mcount 0)) | |
| 1089 (mapcar | |
| 20901 | 1090 (lambda (sub-menu) |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1091 (cond |
| 20901 | 1092 ((eq 'separator sub-menu) |
| 1093 (list 'separator "--")) | |
| 1094 (t | |
| 1095 (let ((buffers (mapcar (function | |
| 1096 (lambda (item) | |
| 1097 (let ((string (car item)) | |
| 1098 (buffer (cdr item))) | |
| 1099 (cons (buffer-name buffer) | |
| 1100 (cons string end))))) | |
| 1101 (cdr sub-menu)))) | |
| 1102 (nconc (list (incf mcount) (car sub-menu) | |
| 1103 'keymap (car sub-menu)) | |
| 1104 (msb--split-menus buffers)))))) | |
| 10228 | 1105 raw-menu))) |
| 1106 | |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1107 (defun msb-menu-bar-update-buffers (&optional arg) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1108 "A re-written version of `menu-bar-update-buffers'." |
| 10228 | 1109 ;; If user discards the Buffers item, play along. |
| 1110 (when (and (lookup-key (current-global-map) [menu-bar buffer]) | |
| 1111 (or (not (fboundp 'frame-or-buffer-changed-p)) | |
| 1112 (frame-or-buffer-changed-p) | |
| 1113 arg)) | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1114 (let ((frames (frame-list)) |
| 10228 | 1115 buffers-menu frames-menu) |
| 1116 ;; Make the menu of buffers proper. | |
| 1117 (setq msb--last-buffer-menu (msb--create-buffer-menu)) | |
| 1118 (setq buffers-menu msb--last-buffer-menu) | |
| 1119 ;; Make a Frames menu if we have more than one frame. | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1120 (when (cdr frames) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1121 (let* ((frame-length (length frames)) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1122 (f-title (format "Frames (%d)" frame-length))) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1123 ;; List only the N most recently selected frames |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1124 (when (and (integerp msb-max-menu-items) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1125 (> msb-max-menu-items 1) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1126 (> frame-length msb-max-menu-items)) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1127 (setcdr (nthcdr msb-max-menu-items frames) nil)) |
| 10228 | 1128 (setq frames-menu |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1129 (nconc |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1130 (list 'frame f-title '(nil) 'keymap f-title) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1131 (mapcar |
| 20901 | 1132 (lambda (frame) |
| 1133 (nconc | |
| 1134 (list frame | |
| 1135 (cdr (assq 'name | |
| 1136 (frame-parameters frame))) | |
| 1137 (cons nil nil)) | |
| 1138 'menu-bar-select-frame)) | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1139 frames))))) |
| 10228 | 1140 (define-key (current-global-map) [menu-bar buffer] |
| 1141 (cons "Buffers" | |
| 1142 (if (and buffers-menu frames-menu) | |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1143 ;; Combine Frame and Buffers menus with separator between |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1144 (nconc (list 'keymap "Buffers and Frames" frames-menu |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1145 (and msb-separator-diff '(separator "--"))) |
|
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1146 (cddr buffers-menu)) |
|
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
1147 (or buffers-menu 'undefined))))))) |
| 10228 | 1148 |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1149 ;; Snarf current bindings of `mouse-buffer-menu' (normally |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1150 ;; C-down-mouse-1). |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1151 (defvar msb-mode-map |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1152 (let ((map (make-sparse-keymap))) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1153 (mapcar (lambda (key) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1154 (define-key map key #'msb)) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1155 (where-is-internal 'mouse-buffer-menu (make-sparse-keymap))) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1156 map)) |
|
20504
1b8aec1c12f1
Doc fixes. Changed `append' to `nconc'
Richard M. Stallman <rms@gnu.org>
parents:
16833
diff
changeset
|
1157 |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1158 ;;;###autoload |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1159 (defun msb-mode (&optional arg) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1160 "Toggle Msb mode. |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1161 With arg, turn Msb mode on if and only if arg is positive. |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1162 This mode overrides the binding(s) of `mouse-buffer-menu' to provide a |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1163 different buffer menu using the function `msb'." |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1164 (interactive "P") |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1165 (setq msb-mode (if arg |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1166 (> (prefix-numeric-value arg) 0) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1167 (not msb-mode))) |
|
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1168 (if msb-mode |
|
25050
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1169 (progn |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1170 (add-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1171 (remove-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1172 (remove-hook 'menu-bar-update-hook 'msb-menu-bar-update-buffers) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1173 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) |
|
1539c0070dd3
(msb-menu-bar-update-buffers): Renamed from
Dave Love <fx@gnu.org>
parents:
24796
diff
changeset
|
1174 (run-hooks 'menu-bar-update-hook)) |
| 10228 | 1175 |
|
24796
19424321d8e1
Add to minor-mode-map-alist. Remove hook installation
Dave Love <fx@gnu.org>
parents:
21670
diff
changeset
|
1176 (add-to-list 'minor-mode-map-alist (cons 'msb-mode msb-mode-map)) |
| 10228 | 1177 |
| 1178 (provide 'msb) | |
| 1179 (eval-after-load 'msb (run-hooks 'msb-after-load-hooks)) | |
|
16833
052a9f2e21e5
(frame-or-buffer-changed-p): Definition deleted.
Richard M. Stallman <rms@gnu.org>
parents:
16428
diff
changeset
|
1180 |
| 10228 | 1181 ;;; msb.el ends here |
