annotate lisp/msb.el @ 30078:58ce7aad3fff

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