annotate lisp/msb.el @ 79283:2248d68d8b70

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