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