annotate lisp/msb.el @ 12656:5beb1d2be5c1

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