annotate lisp/msb.el @ 21366:e7b64d0b3b3d

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