annotate lisp/msb.el @ 30804:fa469be05ab6

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