Mercurial > emacs
annotate lisp/msb.el @ 10822:1ec15b8745a2
(display_string, display_text_line):
Display table overrides ordinary display even for \t, \n, etc.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 24 Feb 1995 18:49:48 +0000 |
parents | 1ff0ed96a4c0 |
children | abd2a268ed88 |
rev | line source |
---|---|
10228 | 1 ;;; msb.el --- Customizable buffer-selection with multiple menus. |
2 ;; Copyright (C) 1993, 1994 Lars Lindberg <Lars.Lindberg@sypro.cap.se> | |
3 ;; | |
4 ;; Author: Lars Lindberg <Lars.Lindberg@sypro.cap.se> | |
5 ;; Created: 8 Oct 1993 | |
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
6 ;; Lindberg's last update version: 3.31 |
10228 | 7 ;; Keywords: mouse buffer menu |
8 ;; | |
9 ;; This program is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2 of the License, or | |
12 ;; (at your option) any later version. | |
13 ;; | |
14 ;; This program is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 ;; | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with this program; if not, write to the Free Software | |
21 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Commentary: | |
24 ;; | |
25 ;; Purpose of this package: | |
26 ;; 1. Offer a function for letting the user choose buffer, | |
27 ;; not necessarily for switching to it. | |
28 ;; 2. Make a better mouse-buffer-menu. | |
29 ;; | |
30 ;; Installation: | |
31 ;; (require 'msb) | |
32 ;; Note! You now use msb instead of mouse-buffer-menu. | |
33 ;; | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
34 ;; Now try the menu bar Buffers menu. |
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) | |
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'. |
10228 | 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. |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
57 ;; + All file buffers only appear in in a file sub-menu, they will |
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 |
78 ;;; Code: | |
79 | |
80 (require 'cl) | |
81 | |
82 ;;; | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
83 ;;; 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
|
84 ;;; 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
|
85 ;;; returns `multi', then the buffer can appear in several menus. |
10228 | 86 ;;; |
87 (defconst msb--few-menus | |
88 '(((and (boundp 'server-buffer-clients) | |
89 server-buffer-clients | |
90 'multi) | |
91 3030 | |
92 "Clients (%d)") | |
93 ((and msb-display-invisible-buffers-p | |
94 (msb-invisible-buffer-p) | |
95 'multi) | |
96 3090 | |
97 "Invisible buffers (%d)") | |
98 ((eq major-mode 'dired-mode) | |
99 2010 | |
100 "Dired (%d)" | |
101 msb-dired-item-handler | |
102 msb-sort-by-directory) | |
103 ((eq major-mode 'Man-mode) | |
104 4090 | |
105 "Manuals (%d)") | |
106 ((eq major-mode 'w3-mode) | |
107 4020 | |
108 "WWW (%d)") | |
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
109 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) |
10228 | 110 (memq major-mode '(mh-letter-mode |
111 mh-show-mode | |
112 mh-folder-mode)) | |
113 (memq major-mode '(gnus-summary-mode | |
114 news-reply-mode | |
115 gnus-group-mode | |
116 gnus-article-mode | |
117 gnus-kill-file-mode | |
118 gnus-browse-killed-mode))) | |
119 4010 | |
120 "Mail (%d)") | |
121 ((not buffer-file-name) | |
122 4099 | |
123 "Buffers (%d)") | |
124 ('no-multi | |
125 1099 | |
126 "Files (%d)"))) | |
127 | |
128 (defconst msb--very-many-menus | |
129 '(((and (boundp 'server-buffer-clients) | |
130 server-buffer-clients | |
131 'multi) | |
132 1010 | |
133 "Clients (%d)") | |
134 ((and (boundp 'vc-mode) vc-mode 'multi) | |
135 1020 | |
136 "Version Control (%d)") | |
137 ((and buffer-file-name | |
138 (buffer-modified-p) | |
139 'multi) | |
140 1030 | |
141 "Changed files (%d)") | |
142 ((and (get-buffer-process (current-buffer)) | |
143 'multi) | |
144 1040 | |
145 "Processes (%d)") | |
146 ((and msb-display-invisible-buffers-p | |
147 (msb-invisible-buffer-p) | |
148 'multi) | |
149 1090 | |
150 "Invisible buffers (%d)") | |
151 ((eq major-mode 'dired-mode) | |
152 2010 | |
153 "Dired (%d)" | |
154 ;; Note this different menu-handler | |
155 msb-dired-item-handler | |
156 ;; Also note this item-sorter | |
157 msb-sort-by-directory) | |
158 ((eq major-mode 'Man-mode) | |
159 4030 | |
160 "Manuals (%d)") | |
161 ((eq major-mode 'w3-mode) | |
162 4020 | |
163 "WWW (%d)") | |
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
164 ((or (memq major-mode '(rmail-mode rmail-edit-mode vm-summary-mode vm-mode mail-mode)) |
10228 | 165 (memq major-mode '(mh-letter-mode |
166 mh-show-mode | |
167 mh-folder-mode)) | |
168 (memq major-mode '(gnus-summary-mode | |
169 news-reply-mode | |
170 gnus-group-mode | |
171 gnus-article-mode | |
172 gnus-kill-file-mode | |
173 gnus-browse-killed-mode))) | |
174 4010 | |
175 "Mail (%d)") | |
176 ;; Catchup for all non-file buffers | |
177 ((and (not buffer-file-name) | |
178 'no-multi) | |
179 4099 | |
180 "Other non-file buffers (%d)") | |
181 ((and (string-match "/\\.[^/]*$" buffer-file-name) | |
182 'multi) | |
183 3090 | |
184 "Hidden Files (%d)") | |
185 ((memq major-mode '(c-mode c++-mode)) | |
186 3010 | |
187 "C/C++ Files (%d)") | |
188 ((eq major-mode 'emacs-lisp-mode) | |
189 3020 | |
190 "Elisp Files (%d)") | |
191 ((eq major-mode 'latex-mode) | |
192 3030 | |
193 "LaTex Files (%d)") | |
194 ('no-multi | |
195 3099 | |
196 "Other files (%d)"))) | |
197 | |
198 ;; msb--many-menus is obsolete | |
199 (defvar msb--many-menus msb--very-many-menus) | |
200 | |
201 ;;; | |
202 ;;; Customizable variables | |
203 ;;; | |
204 | |
205 (defvar msb-separator-diff 100 | |
206 "*Non-nil means use separators. | |
207 The separators will appear between all menus that have a sorting key that differs by this value or more.") | |
208 | |
209 (defvar msb-files-by-directory-sort-key 0 | |
210 "*The sort key for files sorted by directory") | |
211 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
212 (defvar msb-max-menu-items 15 |
10228 | 213 "*The maximum number of items in a menu. |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
214 If this variable is set to 15 for instance, then the submenu will be split up in minor parts, 15 items each. |
10228 | 215 Nil means no limit.") |
216 | |
217 (defvar msb-max-file-menu-items 10 | |
218 "*The maximum number of items from different directories. | |
219 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
220 When the menu is of type `file by directory', this is the maximum |
10228 | 221 number of buffers that are clumped togehter from different |
222 directories. | |
223 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
224 Set this to 1 if you want one menu per directory instead of clumping |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
225 them together. |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
226 |
10228 | 227 If the value is not a number, then the value 10 is used.") |
228 | |
229 (defvar msb-most-recently-used-sort-key -1010 | |
230 "*Where should the menu with the most recently used buffers be placed?") | |
231 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
232 (defvar msb-display-most-recently-used 15 |
10228 | 233 "*How many buffers should be in the most-recently-used menu. |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
234 No buffers at all if less than 1 or nil (or any non-number).") |
10228 | 235 |
236 (defvar msb-most-recently-used-title "Most recently used (%d)" | |
237 "*The title for the most-recently-used menu.") | |
238 | |
239 (defvar msb-horizontal-shift-function '(lambda () 0) | |
240 "*Function that specifies a number of pixels by which the top menu should | |
241 be shifted leftwards.") | |
242 | |
243 (defvar msb-display-invisible-buffers-p nil | |
244 "*Show invisible buffers or not. | |
245 Non-nil means that the buffer menu should include buffers that have | |
246 names that starts with a space character.") | |
247 | |
248 (defvar msb-item-handling-function 'msb-item-handler | |
249 "*The appearance of a buffer menu. | |
250 | |
251 The default function to call for handling the appearance of a menu | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
252 item. It should take to arguments, BUFFER and MAX-BUFFER-NAME-LENGTH, |
10228 | 253 where the latter is the max length of all buffer names. |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
254 |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
255 The function should return the string to use in the menu. |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
256 |
10228 | 257 When the function is called, BUFFER is the current buffer. |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
258 This function is called for items in the variable `msb-menu-cond' that |
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
259 have nil as ITEM-HANDLING-FUNCTION. See `msb-menu-cond' for more |
10228 | 260 information.") |
261 | |
262 (defvar msb-item-sort-function 'msb-sort-by-name | |
263 "*The order of items in a buffer menu. | |
264 The default function to call for handling the order of items in a menu | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
265 item. This function is called like a sort function. The items |
10228 | 266 look like (ITEM-NAME . BUFFER). |
267 ITEM-NAME is the name of the item that will appear in the menu. | |
268 BUFFER is the buffer, this is not necessarily the current buffer. | |
269 | |
270 Set this to nil or t if you don't want any sorting (faster).") | |
271 | |
272 (defvar msb-files-by-directory nil | |
273 "*Non-nil means that files should be sorted by directory instead of | |
274 the groups in msb-menu-cond.") | |
275 | |
276 (defvar msb-menu-cond msb--very-many-menus | |
277 "*List of criterias for splitting the mouse buffer menu. | |
278 The elements in the list should be of this type: | |
279 (CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLING-FN ITEM-SORT-FN). | |
280 | |
281 When making the split, the buffers are tested one by one against the | |
282 CONDITION, just like a lisp cond: When hitting a true condition, the | |
283 other criterias are *not* tested and the buffer name will appear in | |
284 the menu with the menu-title corresponding to the true condition. | |
285 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
286 If the condition returns the symbol `multi', then the buffer will be |
10228 | 287 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
|
288 `no-multi', then the buffer will only be added if it hasn't been added |
10228 | 289 to any other menu. |
290 | |
291 During this test, the buffer in question is the current buffer, and | |
292 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
|
293 `save-match-data'. |
10228 | 294 |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
295 The categories are sorted by MENU-SORT-KEY. Smaller keys are on |
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
296 top. nil means don't display this menu. |
10228 | 297 |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
298 MENU-TITLE is really a format. If you add %d in it, the %d is replaced |
10228 | 299 with the number of items in that menu. |
300 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
301 ITEM-HANDLING-FN, is optional. If it is supplied and is a |
10228 | 302 function, than it is used for displaying the items in that particular |
303 buffer 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
|
304 `msb-item-handling-function' is used. |
10228 | 305 |
306 ITEM-SORT-FN, is also optional. | |
307 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
|
308 `msb-item-sort-function' is used. |
10228 | 309 If it is nil, then no sort takes place and the buffers are presented |
310 in least-recently-used order. | |
311 If it is t, then no sort takes place and the buffers are presented in | |
312 most-recently-used order. | |
313 If it is supplied and non-nil and not t than it is used for sorting | |
314 the items in that particular buffer menu. | |
315 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
316 Note1: There should always be a `catch-all' as last element, |
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
317 in this list. That is an element like (t TITLE ITEM-HANDLING-FUNCTION). |
10228 | 318 Note2: A buffer menu appears only if it has at least one buffer in it. |
319 Note3: If you have a CONDITION that can't be evaluated you will get an | |
320 error every time you do \\[msb].") | |
321 | |
322 (defvar msb-after-load-hooks nil | |
323 "Hooks to be run after the msb package has been loaded.") | |
324 | |
325 ;;; | |
326 ;;; Internal variables | |
327 ;;; | |
328 | |
329 ;; The last calculated menu. | |
330 (defvar msb--last-buffer-menu nil) | |
331 | |
332 ;; If this is non-nil, then it is a string that describes the error. | |
333 (defvar msb--error nil) | |
334 | |
335 ;;; | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
336 ;;; Some example function to be used for `msb-item-handling-function'. |
10228 | 337 ;;; |
338 (defun msb-item-handler (buffer &optional maxbuf) | |
339 "Create one string item, concerning BUFFER, for the buffer menu. | |
340 The item looks like: | |
341 *% <buffer-name> | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
342 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
|
343 The `%' appears only if the buffer is read-only. |
10228 | 344 Optional second argument MAXBUF is completely ignored." |
345 (let ((name (buffer-name)) | |
346 (modified (if (buffer-modified-p) "*" " ")) | |
347 (read-only (if buffer-read-only "%" " "))) | |
348 (format "%s%s %s" modified read-only name))) | |
349 | |
350 | |
351 (eval-when-compile (require 'dired)) | |
352 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
353 ;; `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
|
354 ;; which causes `dired-directory' to be in the same form. |
10228 | 355 (defun msb--dired-directory () |
356 (cond ((stringp dired-directory) | |
357 (abbreviate-file-name (expand-file-name dired-directory))) | |
358 ((consp dired-directory) | |
359 (abbreviate-file-name (expand-file-name (car dired-directory)))) | |
360 (t | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
361 (error "Unknown type of `dired-directory' in buffer %s" |
10228 | 362 (buffer-name))))) |
363 | |
364 (defun msb-dired-item-handler (buffer &optional maxbuf) | |
365 "Create one string item, concerning a dired BUFFER, for the buffer menu. | |
366 The item looks like: | |
367 *% <buffer-name> | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
368 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
|
369 The `%' appears only if the buffer is read-only. |
10228 | 370 Optional second argument MAXBUF is completely ignored." |
371 (let ((name (msb--dired-directory)) | |
372 (modified (if (buffer-modified-p) "*" " ")) | |
373 (read-only (if buffer-read-only "%" " "))) | |
374 (format "%s%s %s" modified read-only name))) | |
375 | |
376 (defun msb-alon-item-handler (buffer maxbuf) | |
377 "Create one string item for the buffer menu. | |
378 The item looks like: | |
379 <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
|
380 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
|
381 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
|
382 The `#' appears only version control file (SCCS/RCS)." |
10228 | 383 (format (format "%%%ds %%s%%s%%s %%s" maxbuf) |
384 (buffer-name buffer) | |
385 (if (buffer-modified-p) "*" " ") | |
386 (if buffer-read-only "%" " ") | |
387 (if (and (boundp 'vc-mode) vc-mode) "#" " ") | |
388 (or buffer-file-name ""))) | |
389 | |
390 ;;; | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
391 ;;; Some example function to be used for `msb-item-sort-function'. |
10228 | 392 ;;; |
393 (defun msb-sort-by-name (item1 item2) | |
394 "Sorts the items depending on their buffer-name | |
395 An item look like (NAME . BUFFER)." | |
396 (string-lessp (buffer-name (cdr item1)) | |
397 (buffer-name (cdr item2)))) | |
398 | |
399 | |
400 (defun msb-sort-by-directory (item1 item2) | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
401 "Sorts the items depending on their directory. Made for dired. |
10228 | 402 An item look like (NAME . BUFFER)." |
403 (string-lessp (save-excursion (set-buffer (cdr item1)) (msb--dired-directory)) | |
404 (save-excursion (set-buffer (cdr item2)) (msb--dired-directory)))) | |
405 | |
406 ;;; | |
407 ;;; msb | |
408 ;;; | |
409 ;;; This function can be used instead of (mouse-buffer-menu EVENT) | |
410 ;;; function in "mouse.el". | |
411 ;;; | |
412 (defun msb (event) | |
413 "Pop up several menus of buffers for selection with the mouse. | |
414 This command switches buffers in the window that you clicked on, and | |
415 selects that window. | |
416 | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
417 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
|
418 `msb-menu-cond' for more information about how the menus are split." |
10228 | 419 (interactive "e") |
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
420 (let ((old-window (selected-window)) |
10228 | 421 (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
|
422 (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
|
423 (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
|
424 (if buffer |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
425 (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
|
426 (select-window old-window)))) |
10228 | 427 nil) |
428 | |
429 ;;; | |
430 ;;; Some supportive functions | |
431 ;;; | |
432 (defun msb-invisible-buffer-p (&optional buffer) | |
433 "Return t if optional BUFFER is an \"invisible\" buffer. | |
434 If the argument is left out or nil, then the current buffer is considered." | |
435 (and (> (length (buffer-name buffer)) 0) | |
436 (eq ?\ (aref (buffer-name buffer) 0)))) | |
437 | |
438 ;; Strip one hierarcy level from the end of PATH. | |
439 (defun msb--strip-path (path) | |
440 (save-match-data | |
441 (if (string-match "\\(.+\\)/[^/]+$" path) | |
442 (substring path (match-beginning 1) (match-end 1)) | |
443 "/"))) | |
444 | |
445 ;; Create an alist with all buffers from LIST that lies under the same | |
446 ;; directory will be in the same item as the directory string as | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
447 ;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K BUFFER-K+1...)) ...) |
10228 | 448 (defun msb--init-file-alist (list) |
449 (let ((buffer-alist | |
450 (sort (mapcan | |
451 (function | |
452 (lambda (buffer) | |
453 (let ((file-name (buffer-file-name buffer))) | |
454 (when file-name | |
455 (list (cons (msb--strip-path file-name) buffer)))))) | |
456 list) | |
457 (function (lambda (item1 item2) | |
458 (string< (car item1) (car item2))))))) | |
459 ;; 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
|
460 ;; ((PATH1 . (BUFFER-1 BUFFER-2 ...)) (PATH2 . (BUFFER-K)) ...) |
10228 | 461 (let ((path nil) |
462 (buffers nil) | |
463 (result nil)) | |
464 (append | |
465 (mapcan (function | |
466 (lambda (item) | |
467 (cond | |
468 ((and path | |
469 (string= path (car item))) | |
470 (push (cdr item) buffers) | |
471 nil) | |
472 (t | |
473 (when path | |
474 (setq result (cons path buffers))) | |
475 (setq path (car item)) | |
476 (setq buffers (list (cdr item))) | |
477 (and result (list result)))))) | |
478 buffer-alist) | |
479 (list (cons path buffers)))))) | |
480 | |
481 ;; Choose file-menu with respect to directory for every buffer in LIST. | |
482 (defun msb--choose-file-menu (list) | |
483 (let ((buffer-alist (msb--init-file-alist list)) | |
484 (final-list nil) | |
485 (max-clumped-together (if (numberp msb-max-file-menu-items) | |
486 msb-max-file-menu-items | |
487 10)) | |
488 (top-found-p nil) | |
489 (last-path nil) | |
490 first rest path buffers) | |
491 (setq first (car buffer-alist)) | |
492 (setq rest (cdr buffer-alist)) | |
493 (setq path (car first)) | |
494 (setq buffers (cdr first)) | |
495 (while rest | |
496 (let ((found-p nil) | |
497 (tmp-rest rest) | |
498 new-path item) | |
499 (setq item (car tmp-rest)) | |
500 (while (and tmp-rest | |
501 (<= (length buffers) max-clumped-together) | |
502 (>= (length (car item)) (length path)) | |
503 (string= path (substring (car item) 0 (length path)))) | |
504 (setq found-p t) | |
505 (setq buffers (append buffers (cdr item))) | |
506 (setq tmp-rest (cdr tmp-rest)) | |
507 (setq item (car tmp-rest))) | |
508 (cond | |
509 ((> (length buffers) max-clumped-together) | |
510 (setq last-path (car first)) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
511 (setq first |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
512 (cons (format (if top-found-p |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
513 "%s/... (%d)" |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
514 "%s (%d)") |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
515 (car first) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
516 (length (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
517 (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
518 (setq top-found-p nil) |
10228 | 519 (push first final-list) |
520 (setq first (car rest) | |
521 rest (cdr rest)) | |
522 (setq path (car first) | |
523 buffers (cdr first))) | |
524 (t | |
525 (when found-p | |
526 (setq top-found-p t) | |
527 (setq first (cons path buffers) | |
528 rest tmp-rest)) | |
529 (setq path (msb--strip-path path) | |
530 buffers (cdr first)) | |
531 (when (and last-path | |
532 (or (and (>= (length path) (length last-path)) | |
533 (string= last-path | |
534 (substring path 0 (length last-path)))) | |
535 (and (< (length path) (length last-path)) | |
536 (string= path | |
537 (substring last-path 0 (length path)))))) | |
538 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
539 (setq first |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
540 (cons (format (if top-found-p |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
541 "%s/... (%d)" |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
542 "%s (%d)") |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
543 (car first) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
544 (length (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
545 (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
546 (setq top-found-p nil) |
10228 | 547 (push first final-list) |
548 (setq first (car rest) | |
549 rest (cdr rest)) | |
550 (setq path (car first) | |
551 buffers (cdr first))))))) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
552 (setq first |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
553 (cons (format (if top-found-p |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
554 "%s/... (%d)" |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
555 "%s (%d)") |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
556 (car first) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
557 (length (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
558 (cdr first))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
559 (setq top-found-p nil) |
10228 | 560 (push first final-list) |
561 (nreverse final-list))) | |
562 | |
563 ;; Create a vector as: | |
564 ;; [BUFFER-LIST-VARIABLE CONDITION MENU-SORT-KEY MENU-TITLE ITEM-HANDLER SORTER) | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
565 ;; from an element in `msb-menu-cond'. See that variable for a |
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
566 ;; description of its elements. |
10228 | 567 (defun msb--create-function-info (menu-cond-elt) |
568 (let* ((list-symbol (make-symbol "-msb-buffer-list")) | |
569 (tmp-ih (and (> (length menu-cond-elt) 3) | |
570 (nth 3 menu-cond-elt))) | |
571 (item-handler (if (and tmp-ih (fboundp tmp-ih)) | |
572 tmp-ih | |
573 msb-item-handling-function)) | |
574 (tmp-s (if (> (length menu-cond-elt) 4) | |
575 (nth 4 menu-cond-elt) | |
576 msb-item-sort-function)) | |
577 (sorter (if (or (fboundp tmp-s) | |
578 (null tmp-s) | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
579 (eq tmp-s t)) |
10228 | 580 tmp-s |
581 msb-item-sort-function))) | |
582 (when (< (length menu-cond-elt) 3) | |
583 (error "Wrong format of msb-menu-cond.")) | |
584 (when (and (> (length menu-cond-elt) 3) | |
585 (not (fboundp tmp-ih))) | |
586 (signal 'invalid-function (list tmp-ih))) | |
587 (when (and (> (length menu-cond-elt) 4) | |
588 tmp-s | |
589 (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
|
590 (not (eq tmp-s t))) |
10228 | 591 (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
|
592 (set list-symbol ()) |
10228 | 593 (vector list-symbol ;BUFFER-LIST-VARIABLE |
594 (nth 0 menu-cond-elt) ;CONDITION | |
595 (nth 1 menu-cond-elt) ;SORT-KEY | |
596 (nth 2 menu-cond-elt) ;MENU-TITLE | |
597 item-handler ;ITEM-HANDLER | |
598 sorter) ;SORTER | |
599 )) | |
600 | |
601 ;; This defsubst is only used in `msb--choose-menu' below. It was | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
602 ;; pulled out merely to make the code somewhat clearer. The indention |
10228 | 603 ;; level was too big. |
604 (defsubst msb--collect (function-info-vector) | |
605 (let ((result nil) | |
606 (multi-flag nil) | |
607 function-info-list) | |
608 (setq function-info-list | |
609 (loop for fi | |
610 across function-info-vector | |
611 if (and (setq result | |
612 (eval (aref fi 1))) ;Test CONDITION | |
613 (not (and (eq result 'no-multi) | |
614 multi-flag)) | |
615 (progn (when (eq result 'multi) | |
616 (setq multi-flag t)) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
617 t)) |
10228 | 618 collect fi |
619 until (and result | |
620 (not (eq result 'multi))))) | |
621 (when (and (not function-info-list) | |
622 (not result)) | |
623 (error "No catch-all in msb-menu-cond!")) | |
624 function-info-list)) | |
625 | |
626 ;; Adds BUFFER to the menu depicted by FUNCTION-INFO | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
627 ;; All side-effects. Adds an element of form (BUFFER-TITLE . BUFFER) |
10228 | 628 ;; to the buffer-list variable in function-info. |
629 (defun msb--add-to-menu (buffer function-info max-buffer-name-length) | |
630 (let ((list-symbol (aref function-info 0))) ;BUFFER-LIST-VARIABLE | |
631 ;; Here comes the hairy side-effect! | |
632 (set list-symbol | |
633 (cons (cons (funcall (aref function-info 4) ;ITEM-HANDLER | |
634 buffer | |
635 max-buffer-name-length) | |
636 buffer) | |
637 (eval list-symbol))))) | |
638 | |
639 ;; Selects the appropriate menu for BUFFER. | |
640 ;; This is all side-effects, folks! | |
641 ;; This should be optimized. | |
642 (defsubst msb--choose-menu (buffer function-info-vector max-buffer-name-length) | |
643 (unless (and (not msb-display-invisible-buffers-p) | |
644 (msb-invisible-buffer-p buffer)) | |
645 (condition-case nil | |
646 (save-excursion | |
647 (set-buffer buffer) | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
648 ;; Menu found. Add to this menu |
10228 | 649 (mapc (function |
650 (lambda (function-info) | |
651 (msb--add-to-menu buffer function-info max-buffer-name-length))) | |
652 (msb--collect function-info-vector))) | |
653 (error (unless msb--error | |
654 (setq msb--error | |
655 (format | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
656 "In msb-menu-cond, error for buffer `%s'." |
10228 | 657 (buffer-name buffer))) |
658 (error msb--error)))))) | |
659 | |
660 ;; Return (SORT-KEY TITLE . BUFFER-LIST) or nil if the | |
661 ;; buffer-list is empty. | |
662 (defun msb--create-sort-item (function-info) | |
663 (let ((buffer-list (eval (aref function-info 0)))) | |
664 (when buffer-list | |
665 (let ((sorter (aref function-info 5)) ;SORTER | |
666 (sort-key (aref function-info 2))) ;MENU-SORT-KEY | |
667 (when sort-key | |
668 (cons sort-key | |
669 (cons (format (aref function-info 3) ;MENU-TITLE | |
670 (length buffer-list)) | |
671 (cond | |
672 ((null sorter) | |
673 buffer-list) | |
10239
52a1e5ef144c
Fix quoting conventions and spaces at end of sentence.
Richard M. Stallman <rms@gnu.org>
parents:
10228
diff
changeset
|
674 ((eq sorter t) |
10228 | 675 (nreverse buffer-list)) |
676 (t | |
677 (sort buffer-list sorter)))))))))) | |
678 | |
679 ;; Returns a list on the form ((TITLE . BUFFER-LIST)) for | |
680 ;; the most recently used buffers. | |
681 (defun msb--most-recently-used-menu (max-buffer-name-length) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
682 (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
|
683 (> 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
|
684 (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
|
685 (most-recently-used |
10228 | 686 (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
|
687 for buffer in buffers |
10228 | 688 if (save-excursion |
689 (set-buffer buffer) | |
690 (and (not (msb-invisible-buffer-p)) | |
691 (not (eq major-mode 'dired-mode)))) | |
692 collect (save-excursion | |
693 (set-buffer buffer) | |
694 (cons (funcall msb-item-handling-function | |
695 buffer | |
696 max-buffer-name-length) | |
697 buffer)) | |
698 and do (incf n) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
699 until (>= n msb-display-most-recently-used)))) |
10228 | 700 (cons (if (stringp msb-most-recently-used-title) |
701 (format msb-most-recently-used-title | |
702 (length most-recently-used)) | |
703 (signal 'wrong-type-argument (list msb-most-recently-used-title))) | |
704 most-recently-used)))) | |
705 | |
706 (defun msb--create-buffer-menu-2 () | |
707 (let ((max-buffer-name-length 0) | |
708 file-buffers | |
709 function-info-vector) | |
710 ;; Calculate the longest buffer name. | |
711 (mapc | |
712 (function | |
713 (lambda (buffer) | |
714 (if (or msb-display-invisible-buffers-p | |
715 (not (msb-invisible-buffer-p))) | |
716 (setq max-buffer-name-length | |
717 (max max-buffer-name-length | |
718 (length (buffer-name buffer))))))) | |
719 (buffer-list)) | |
720 ;; Make a list with elements of type | |
721 ;; (BUFFER-LIST-VARIABLE | |
722 ;; CONDITION | |
723 ;; MENU-SORT-KEY | |
724 ;; MENU-TITLE | |
725 ;; ITEM-HANDLER | |
726 ;; SORTER) | |
727 ;; Uses "function-global" variables: | |
728 ;; function-info-vector | |
729 (setq function-info-vector | |
730 (apply (function vector) | |
731 (mapcar (function msb--create-function-info) | |
732 msb-menu-cond))) | |
733 ;; 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
|
734 ;; criteria. This is the most critical part with respect to time. |
10228 | 735 (mapc (function (lambda (buffer) |
736 (cond ((and msb-files-by-directory | |
737 (buffer-file-name buffer)) | |
738 (push buffer file-buffers)) | |
739 (t | |
740 (msb--choose-menu buffer | |
741 function-info-vector | |
742 max-buffer-name-length))))) | |
743 (buffer-list)) | |
744 (when file-buffers | |
745 (setq file-buffers | |
746 (mapcar (function | |
747 (lambda (buffer-list) | |
748 (cons msb-files-by-directory-sort-key | |
749 (cons (car buffer-list) | |
750 (sort | |
751 (mapcar (function | |
752 (lambda (buffer) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
753 (cons (save-excursion |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
754 (set-buffer buffer) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
755 (funcall msb-item-handling-function |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
756 buffer |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
757 max-buffer-name-length)) |
10228 | 758 buffer))) |
759 (cdr buffer-list)) | |
760 (function | |
761 (lambda (item1 item2) | |
762 (string< (car item1) (car item2))))))))) | |
763 (msb--choose-file-menu file-buffers)))) | |
764 ;; 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
|
765 (let* (menu |
10228 | 766 (most-recently-used |
767 (msb--most-recently-used-menu max-buffer-name-length)) | |
768 (others (append file-buffers | |
769 (loop for elt | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
770 across function-info-vector |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
771 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
|
772 if value collect value)))) |
10228 | 773 (setq menu |
774 (mapcar 'cdr ;Remove the SORT-KEY | |
775 ;; Sort the menus - not the items. | |
776 (msb--add-separators | |
777 (sort | |
778 ;; Get a list of (SORT-KEY TITLE . BUFFER-LIST) | |
779 ;; Also sorts the items within the menus. | |
780 (if (cdr most-recently-used) | |
781 (cons | |
782 ;; Add most recent used buffers | |
783 (cons msb-most-recently-used-sort-key | |
784 most-recently-used) | |
785 others) | |
786 others) | |
787 (function (lambda (elt1 elt2) | |
788 (< (car elt1) (car elt2)))))))) | |
789 ;; Now make it a keymap menu | |
790 (append | |
791 '(keymap "Select Buffer") | |
792 (msb--make-keymap-menu menu) | |
793 (when msb-separator-diff | |
794 (list (list 'separator "---"))) | |
795 (list (cons 'toggle | |
796 (cons | |
797 (if msb-files-by-directory | |
798 "*Files by type*" | |
799 "*Files by directory*") | |
800 'msb--toggle-menu-type))))))) | |
801 | |
802 (defun msb--create-buffer-menu () | |
803 (save-match-data | |
804 (save-excursion | |
805 (msb--create-buffer-menu-2)))) | |
806 | |
807 ;;; | |
808 ;;; Multi purpose function for selecting a buffer with the mouse. | |
809 ;;; | |
810 (defun msb--toggle-menu-type () | |
811 (interactive) | |
812 (setq msb-files-by-directory (not msb-files-by-directory)) | |
813 (menu-bar-update-buffers t)) | |
814 | |
815 (defun mouse-select-buffer (event) | |
816 "Pop up several menus of buffers, for selection with the mouse. | |
817 Returns the selected buffer or nil if no buffer is selected. | |
818 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
819 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
|
820 variable `msb-menu-cond'." |
10228 | 821 ;; Popup the menu and return the selected buffer. |
822 (when (or msb--error | |
823 (not msb--last-buffer-menu) | |
824 (not (fboundp 'frame-or-buffer-changed-p)) | |
825 (frame-or-buffer-changed-p)) | |
826 (setq msb--error nil) | |
827 (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
|
828 (let ((position event) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
829 choice) |
10228 | 830 (when (and (fboundp 'posn-x-y) |
831 (fboundp 'posn-window)) | |
832 (let ((posX (car (posn-x-y (event-start event)))) | |
833 (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
|
834 (posWind (posn-window (event-start event)))) |
10228 | 835 ;; adjust position |
836 (setq posX (- posX (funcall msb-horizontal-shift-function)) | |
837 position (list (list posX posY) posWind)))) | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
838 (setq choice (x-popup-menu position msb--last-buffer-menu)) |
10228 | 839 (cond |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
840 ((eq (car choice) 'toggle) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
841 ;; 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
|
842 (msb--toggle-menu-type) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
843 (mouse-select-buffer event)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
844 ((and (numberp (car choice)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
845 (null (cdr choice))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
846 (let ((msb--last-buffer-menu (nthcdr 3 (assq (car choice) msb--last-buffer-menu)))) |
10228 | 847 (mouse-select-buffer event))) |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
848 ((while (numberp (car choice)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
849 (setq choice (cdr choice)))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
850 ((and (stringp (car choice)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
851 (null (cdr choice))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
852 (car choice)) |
10403
c0e27466fb3f
(mouse-select-buffer) Handle an aborted selection.
Richard M. Stallman <rms@gnu.org>
parents:
10371
diff
changeset
|
853 ((null choice) |
c0e27466fb3f
(mouse-select-buffer) Handle an aborted selection.
Richard M. Stallman <rms@gnu.org>
parents:
10371
diff
changeset
|
854 choice) |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
855 (t |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
856 (error "Unknown form for buffer: %s" choice))))) |
10228 | 857 |
858 ;; Add separators | |
859 (defun msb--add-separators (sorted-list) | |
860 (cond | |
861 ((or (not msb-separator-diff) | |
862 (not (numberp msb-separator-diff))) | |
863 sorted-list) | |
864 (t | |
865 (let ((last-key nil)) | |
866 (mapcan | |
867 (function | |
868 (lambda (item) | |
869 (cond | |
870 ((and msb-separator-diff | |
871 last-key | |
872 (> (- (car item) last-key) | |
873 msb-separator-diff)) | |
874 (setq last-key (car item)) | |
875 (list (cons last-key 'separator) | |
876 item)) | |
877 (t | |
878 (setq last-key (car item)) | |
879 (list item))))) | |
880 sorted-list))))) | |
881 | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
882 (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
|
883 (cond |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
884 ((> (length list) msb-max-menu-items) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
885 (let ((count 0) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
886 sub-name |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
887 (tmp-list nil)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
888 (while (< count msb-max-menu-items) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
889 (push (pop list) tmp-list) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
890 (incf count)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
891 (setq tmp-list (nreverse tmp-list)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
892 (setq sub-name (concat (car (car tmp-list)) "...")) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
893 (push (append (list mcount sub-name |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
894 'keymap sub-name) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
895 tmp-list) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
896 result)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
897 (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
|
898 ((null result) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
899 list) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
900 (t |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
901 (let (sub-name) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
902 (setq sub-name (concat (car (car list)) "...")) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
903 (push (append (list mcount sub-name |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
904 'keymap sub-name) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
905 list) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
906 result)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
907 (nreverse result)))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
908 |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
909 (defun msb--split-menus (list) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
910 (msb--split-menus-2 list 0 nil)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
911 |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
912 |
10228 | 913 (defun msb--make-keymap-menu (raw-menu) |
914 (let ((end (cons '(nil) 'menu-bar-select-buffer)) | |
915 (mcount 0)) | |
916 (mapcar | |
917 (function | |
918 (lambda (sub-menu) | |
919 (cond | |
920 ((eq 'separator sub-menu) | |
921 (list 'separator "---")) | |
922 (t | |
10371
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
923 (let ((buffers (mapcar (function |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
924 (lambda (item) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
925 (let ((string (car item)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
926 (buffer (cdr item))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
927 (cons (buffer-name buffer) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
928 (cons string end))))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
929 (cdr sub-menu)))) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
930 (append (list (incf mcount) (car sub-menu) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
931 'keymap (car sub-menu)) |
629821e2b42e
Better format of files-by-directory menus.
Richard M. Stallman <rms@gnu.org>
parents:
10239
diff
changeset
|
932 (msb--split-menus buffers))))))) |
10228 | 933 raw-menu))) |
934 | |
935 (defun menu-bar-update-buffers (&optional arg) | |
936 ;; If user discards the Buffers item, play along. | |
937 (when (and (lookup-key (current-global-map) [menu-bar buffer]) | |
938 (or (not (fboundp 'frame-or-buffer-changed-p)) | |
939 (frame-or-buffer-changed-p) | |
940 arg)) | |
10821
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
941 (let ((frames (frame-list)) |
10228 | 942 buffers-menu frames-menu) |
943 ;; Make the menu of buffers proper. | |
944 (setq msb--last-buffer-menu (msb--create-buffer-menu)) | |
945 (setq buffers-menu msb--last-buffer-menu) | |
946 ;; 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
|
947 (when (cdr frames) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
948 (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
|
949 (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
|
950 ;; 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
|
951 (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
|
952 (> 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
|
953 (> 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
|
954 (setcdr (nthcdr msb-max-menu-items frames) nil)) |
10228 | 955 (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
|
956 (nconc |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
957 (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
|
958 (mapcar |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
959 (function |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
960 (lambda (frame) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
961 (nconc |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
962 (list frame |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
963 (cdr (assq 'name |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
964 (frame-parameters frame))) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
965 (cons nil nil)) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
966 'menu-bar-select-frame))) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
967 frames))))) |
10228 | 968 (define-key (current-global-map) [menu-bar buffer] |
969 (cons "Buffers" | |
970 (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
|
971 ;; 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
|
972 (nconc (list 'keymap "Buffers and Frames" frames-menu |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
973 (and msb-separator-diff '(separator "---"))) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
974 (cddr buffers-menu)) |
1ff0ed96a4c0
(msb): Select the window that the mouse is in before
Richard M. Stallman <rms@gnu.org>
parents:
10403
diff
changeset
|
975 (or buffers-menu 'undefined))))))) |
10228 | 976 |
977 (when (and (boundp 'menu-bar-update-hook) | |
978 (not (fboundp 'frame-or-buffer-changed-p))) | |
979 (defvar msb--buffer-count 0) | |
980 (defun frame-or-buffer-changed-p () | |
981 (let ((count (length (buffer-list)))) | |
982 (when (/= count msb--buffer-count) | |
983 (setq msb--buffer-count count) | |
984 t)))) | |
985 | |
986 (unless (or (not (boundp 'menu-bar-update-hook)) | |
987 (memq 'menu-bar-update-buffers menu-bar-update-hook)) | |
988 (add-hook 'menu-bar-update-hook 'menu-bar-update-buffers)) | |
989 | |
990 (and (fboundp 'mouse-buffer-menu) | |
991 (substitute-key-definition 'mouse-buffer-menu 'msb (current-global-map))) | |
992 | |
993 (provide 'msb) | |
994 (eval-after-load 'msb (run-hooks 'msb-after-load-hooks)) | |
995 ;;; msb.el ends here |