annotate lisp/msb.el @ 10285:abacb10bd5e6

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