annotate lisp/buff-menu.el @ 5882:bbe4146603db

Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp lisp/ChangeLog addition: 2015-04-01 Aidan Kehoe <kehoea@parhasard.net> When calling #'string-match with a REGEXP without regular expression special characters, call #'search, #'mismatch, #'find, etc. instead, making our code less likely to side-effect other functions' match data and a little faster. * apropos.el (apropos-command): * apropos.el (apropos): Call (position ?\n ...) rather than (string-match "\n" ...) here. * buff-menu.el: * buff-menu.el (buffers-menu-omit-invisible-buffers): Don't fire up the regexp engine just to check if a string starts with a space. * buff-menu.el (select-buffers-tab-buffers-by-mode): Don't fire up the regexp engine just to compare mode basenames. * buff-menu.el (format-buffers-tab-line): * buff-menu.el (build-buffers-tab-internal): Moved to being a label within the following. * buff-menu.el (buffers-tab-items): Use the label. * bytecomp.el (byte-compile-log-1): Don't fire up the regexp engine just to look for a newline. * cus-edit.el (get): Ditto. * cus-edit.el (custom-variable-value-create): Ditto, but for a colon. * descr-text.el (describe-text-sexp): Ditto. * descr-text.el (describe-char-unicode-data): Use #'split-string-by-char given that we're just looking for a semicolon. * descr-text.el (describe-char): Don't fire up the regexp engine just to look for a newline. * disass.el (disassemble-internal): Ditto. * files.el (file-name-sans-extension): Implement this using #'position. * files.el (file-name-extension): Correct this function's docstring, implement it in terms of #'position. * files.el (insert-directory): Don't fire up the regexp engine to split a string by space; don't reverse the list of switches, this is actually a longstand bug as far as I can see. * gnuserv.el (gnuserv-process-filter): Use #'position here, instead of consing inside #'split-string needlessly. * gtk-file-dialog.el (gtk-file-dialog-update-dropdown): Use #'split-string-by-char here, don't fire up #'split-string for directory-sep-char. * gtk-font-menu.el (hack-font-truename): Implement this more cheaply in terms of #'find, #'split-string-by-char, #'equal, rather than #'string-match, #'split-string, #'string-equal. * hyper-apropos.el (hyper-apropos-grok-functions): * hyper-apropos.el (hyper-apropos-grok-variables): Look for a newline using #'position rather than #'string-match in these functions. * info.el (Info-insert-dir): * info.el (Info-insert-file-contents): * info.el (Info-follow-reference): * info.el (Info-extract-menu-node-name): * info.el (Info-menu): Look for fixed strings using #'position or #'search as appropriate in this file. * ldap.el (ldap-decode-string): * ldap.el (ldap-encode-string): #'encode-coding-string, #'decode-coding-string are always available, don't check if they're fboundp. * ldap.el (ldap-decode-address): * ldap.el (ldap-encode-address): Use #'split-string-by-char in these functions. * lisp-mnt.el (lm-creation-date): * lisp-mnt.el (lm-last-modified-date): Don't fire up the regexp engine just to look for spaces in this file. * menubar-items.el (default-menubar): Use (not (mismatch ...)) rather than #'string-match here, for simple regexp. Use (search "beta" ...) rather than (string-match "beta" ...) * menubar-items.el (sort-buffers-menu-alphabetically): * menubar-items.el (sort-buffers-menu-by-mode-then-alphabetically): * menubar-items.el (group-buffers-menu-by-mode-then-alphabetically): Don't fire up the regexp engine to check if a string starts with a space or an asterisk. Use the more fine-grained results of #'compare-strings; compare case-insensitively for the buffer menu. * menubar-items.el (list-all-buffers): * menubar-items.el (tutorials-menu-filter): Use #'equal rather than #'string-equal, which, in this context, has the drawback of not having a bytecode, and no redeeming features. * minibuf.el: * minibuf.el (un-substitute-in-file-name): Use #'count, rather than counting the occurences of $ using the regexp engine. * minibuf.el (read-file-name-internal-1): Don't fire up the regexp engine to search for ?=. * mouse.el (mouse-eval-sexp): Check for newline with #'find. * msw-font-menu.el (mswindows-reset-device-font-menus): Split a string by newline with #'split-string-by-char. * mule/japanese.el: * mule/japanese.el ("Japanese"): Use #'search rather than #'string-match; canoncase before comparing; fix a bug I had introduced where I had been making case insensitive comparisons where the case mattered. * mule/korea-util.el (default-korean-keyboard): Look for ?3 using #'find, not #'string-march. * mule/korea-util.el (quail-hangul-switch-hanja): Search for a fixed string using #'search. * mule/mule-cmds.el (set-locale-for-language-environment): #'position, #'substitute rather than #'string-match, #'replace-in-string. * newcomment.el (comment-make-extra-lines): Use #'search rather than #'string-match for a simple string. * package-get.el (package-get-remote-filename): Use #'position when looking for ?@ * process.el (setenv): * process.el (read-envvar-name): Use #'position when looking for ?=. * replace.el (map-query-replace-regexp): Use #'split-string-by-char instead of using an inline implementation of it. * select.el (select-convert-from-cf-text): * select.el (select-convert-from-cf-unicodetext): Use #'position rather than #'string-match in these functions. * setup-paths.el (paths-emacs-data-root-p): Use #'search when looking for simple string. * sound.el (load-sound-file): Use #'split-string-by-char rather than an inline reimplementation of same. * startup.el (splash-screen-window-body): * startup.el (splash-screen-tty-body): Search for simple strings using #'search. * version.el (emacs-version): Ditto. * x-font-menu.el (hack-font-truename): Implement this more cheaply in terms of #'find, #'split-string-by-char, #'equal, rather than #'string-match, #'split-string, #'string-equal. * x-font-menu.el (x-reset-device-font-menus-core): Use #'split-string-by-char here. * x-init.el (x-initialize-keyboard): Search for a simple string using #'search.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 01 Apr 2015 14:28:20 +0100
parents cc6f0266bc36
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
1 ;;; buff-menu.el --- buffer menu/tab main function and support functions.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
4 ;; Copyright (C) 1999, 2000 Andy Piper.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
5 ;; Copyright (C) 2000 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
7 ;; Maintainer: XEmacs Development Team
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
8 ;; Keywords: frames, extensions, internal, dumped
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
12 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
13 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
14 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
15 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
19 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
20 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 3162
diff changeset
23 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34 except as noted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; Edit, delete, or change attributes of all currently active Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; buffers from a list summarizing their state. A good way to browse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; any special or scratch buffers you have loaded, since you can't find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; them by filename. The single entry point is `Buffer-menu-mode',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; normally bound to C-x C-b.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
37 ;; Also contains buffers-tab code, because it's used by
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
38 ;; switch-to-next-buffer and friends.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
39
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;;; Change Log:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;; Merged by esr with recent mods to Emacs 19 buff-menu, 23 Mar 1993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; Modified by Bob Weiner, Motorola, Inc., 4/14/89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; Added optional backup argument to 'Buffer-menu-unmark' to make it undelete
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;; current entry and then move to previous one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;; Based on FSF code dating back to 1985.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;;; Code:
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
52
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;;Trying to preserve the old window configuration works well in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;;;simple scenarios, when you enter the buffer menu, use it, and exit it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;;;But it does strange things when you switch back to the buffer list buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;;;with C-x b, later on, when the window configuration is different.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;;;The choice seems to be, either restore the window configuration
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;;;in all cases, or in no cases.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;;;I decided it was better not to restore the window config at all. -- rms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;;;But since then, I changed buffer-menu to use the selected window,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;;;so q now once again goes back to the previous window configuration.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 ;;;(defvar Buffer-menu-window-config nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;;; "Window configuration saved from entry to `buffer-menu'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ; Put buffer *Buffer List* into proper mode right away
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ; so that from now on even list-buffers is enough to get a buffer menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (defvar Buffer-menu-buffer-column 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (defvar Buffer-menu-mode-map nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (if Buffer-menu-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 (setq Buffer-menu-mode-map (make-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (suppress-keymap Buffer-menu-mode-map t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (set-keymap-name Buffer-menu-mode-map 'Buffer-menu-mode-map) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (define-key Buffer-menu-mode-map "q" 'Buffer-menu-quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (define-key Buffer-menu-mode-map "v" 'Buffer-menu-select)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-this-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (define-key Buffer-menu-mode-map "s" 'Buffer-menu-save)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete)
3162
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
92 (define-key Buffer-menu-mode-map "r" 'Buffer-menu-rename)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (define-key Buffer-menu-mode-map " " 'next-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (define-key Buffer-menu-mode-map "n" 'next-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (define-key Buffer-menu-mode-map "p" 'previous-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (define-key Buffer-menu-mode-map 'backspace 'Buffer-menu-backup-unmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (define-key Buffer-menu-mode-map 'delete 'Buffer-menu-backup-unmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 (define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 (define-key Buffer-menu-mode-map "?" 'describe-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 (define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 (define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 (define-key Buffer-menu-mode-map "%" 'Buffer-menu-toggle-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 (define-key Buffer-menu-mode-map "g" 'revert-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (define-key Buffer-menu-mode-map 'button2 'Buffer-menu-mouse-select)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 (define-key Buffer-menu-mode-map 'button3 'Buffer-menu-popup-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ;; Buffer Menu mode is suitable only for specially formatted data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 (put 'Buffer-menu-mode 'mode-class 'special)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 (defun Buffer-menu-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 "Major mode for editing a list of buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 Each line describes one of the buffers in Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 Letters do not insert themselves; instead, they are commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 \\<Buffer-menu-mode-map>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 \\[Buffer-menu-mouse-select] -- select buffer you click on, in place of the buffer menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 \\[Buffer-menu-this-window] -- select current line's buffer in place of the buffer menu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 \\[Buffer-menu-other-window] -- select that buffer in another window,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 so the buffer menu buffer remains visible in its window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 \\[Buffer-menu-switch-other-window] -- make another window display that buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 \\[Buffer-menu-mark] -- mark current line's buffer to be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 \\[Buffer-menu-select] -- select current line's buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 Also show buffers marked with m, in other windows.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 \\[Buffer-menu-1-window] -- select that buffer in full-frame window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 \\[Buffer-menu-2-window] -- select that buffer in one window,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 together with buffer selected before this one in another window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 \\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 \\[Buffer-menu-execute] -- delete or save marked buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 With prefix argument, also move up one line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 \\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (use-local-map Buffer-menu-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (setq major-mode 'Buffer-menu-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (setq mode-name "Buffer Menu")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (make-local-variable 'revert-buffer-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (setq revert-buffer-function 'Buffer-menu-revert-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (setq truncate-lines t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (setq buffer-read-only t)
548
0f4bdbb07414 [xemacs-hg @ 2001-05-20 21:36:06 by adrian]
adrian
parents: 538
diff changeset
147 (make-local-hook 'mouse-track-click-hook) ; XEmacs
0f4bdbb07414 [xemacs-hg @ 2001-05-20 21:36:06 by adrian]
adrian
parents: 538
diff changeset
148 (add-hook 'mouse-track-click-hook 'Buffer-menu-maybe-mouse-select t t) ; XEmacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (run-hooks 'buffer-menu-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (defun Buffer-menu-revert-function (ignore1 ignore2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (list-buffers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (defun Buffer-menu-buffer (error-if-non-existent-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 "Return buffer described by this line of buffer menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (let* ((where (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (+ (point) Buffer-menu-buffer-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (name (and (not (eobp)) (get-text-property where 'buffer-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (if name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (or (get-buffer name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (if error-if-non-existent-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (error "No buffer named `%s'" name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (if error-if-non-existent-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (error "No buffer on this line")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (defun buffer-menu (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 "Make a menu of buffers so you can save, delete or select them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 With argument, show only buffers that are visiting files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 Type ? after invocation to get help on commands available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 Type q immediately to make the buffer menu go away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ;;; (setq Buffer-menu-window-config (current-window-configuration))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (switch-to-buffer (list-buffers-noselect arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (defun buffer-menu-other-window (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 "Display a list of buffers in another window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 With the buffer list buffer, you can save, delete or select the buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 With argument, show only buffers that are visiting files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 Type ? after invocation to get help on commands available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 Type q immediately to make the buffer menu go away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 ;;; (setq Buffer-menu-window-config (current-window-configuration))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (switch-to-buffer-other-window (list-buffers-noselect arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 "Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (defun Buffer-menu-quit ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 "Quit the buffer menu."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (let ((buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;; Switch away from the buffer menu and bury it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 (switch-to-buffer (other-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (bury-buffer buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (defun Buffer-menu-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (if (looking-at " [-M]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (ding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (insert ?>)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (forward-line 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (defun Buffer-menu-unmark (&optional backup)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 "Cancel all requested operations on buffer on this line and move down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 Optional ARG means move up."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (if (looking-at " [-M]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (ding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (let* ((buf (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (mod (buffer-modified-p buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (readonly (save-excursion (set-buffer buf) buffer-read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (delete-char 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (insert (if readonly (if mod " *%" " %") (if mod " * " " ")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (forward-line (if backup -1 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (defun Buffer-menu-backup-unmark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 "Move up and cancel all requested operations on buffer on line above."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (Buffer-menu-unmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (defun Buffer-menu-delete (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 Prefix arg is how many buffers to delete.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 Negative arg means delete backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (if (looking-at " [-M]") ;header lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (ding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (if (or (null arg) (= arg 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (setq arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (insert ?D)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (setq arg (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (insert ?D)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (setq arg (1+ arg))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (defun Buffer-menu-delete-backwards (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 and then move up one line. Prefix arg means move that many lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (Buffer-menu-delete (- (or arg 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (while (looking-at " [-M]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3162
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
263 (defun Buffer-menu-rename (newname unique)
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
264 "Rename buffer on this line to NEWNAME, immediately.
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
265 If given a prefix argument, automatically uniquify. See `rename-buffer'."
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
266 (interactive "sNew name for buffer: \np")
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
267 (beginning-of-line)
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
268 (if (looking-at " [-M]") ;header lines
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
269 (ding)
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
270 (save-excursion
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
271 (set-buffer (Buffer-menu-buffer t))
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
272 (rename-buffer newname unique))
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
273 (revert-buffer)))
6e11554a16aa [xemacs-hg @ 2005-12-23 11:40:32 by stephent]
stephent
parents: 776
diff changeset
274
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (defun Buffer-menu-save ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 "Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (if (looking-at " [-M]") ;header lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (ding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (insert ?S)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (forward-line 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (defun Buffer-menu-not-modified (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 "Mark buffer on this line as unmodified (no changes to save)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (set-buffer (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (set-buffer-modified-p arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (if (= (char-after (point)) (if arg ? ?*))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (insert (if arg ?* ? ))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (defun Buffer-menu-execute ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 "Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (while (re-search-forward "^.S" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (let ((modp nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (set-buffer (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (save-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (setq modp (buffer-modified-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (delete-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (insert (if modp ?* ? ))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (let ((buff-menu-buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (while (search-forward "\nD" nil t)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
322 (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (let ((buf (Buffer-menu-buffer nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (or (eq buf nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (eq buf buff-menu-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (save-excursion (kill-buffer buf))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (if (Buffer-menu-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (progn (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (insert ? ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (delete-region (point) (progn (forward-line 1) (point)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
331 (backward-char 1))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (defun Buffer-menu-select ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 "Select this line's buffer; also display buffers marked with `>'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 This command deletes and replaces all the previously existing windows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 in the selected frame."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (let ((buff (Buffer-menu-buffer t))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
340 (menu (current-buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (others ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 tem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (while (search-forward "\n>" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (setq tem (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (delete-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (insert ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (setq others (nreverse others)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 tem (/ (1- (frame-height)) (1+ (length others))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (delete-other-windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (switch-to-buffer buff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (or (eq menu buff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (bury-buffer menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (if (equal (length others) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ;;; ;; Restore previous window configuration before displaying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 ;;; ;; selected buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 ;;; (if Buffer-menu-window-config
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 ;;; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 ;;; (set-window-configuration Buffer-menu-window-config)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 ;;; (setq Buffer-menu-window-config nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (switch-to-buffer buff))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (while others
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (split-window nil tem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (other-window 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (switch-to-buffer (car others))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (setq others (cdr others)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (other-window 1) ;back to the beginning!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
375 (eval-when-compile (autoload 'visit-tags-table "etags"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
376
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (defun Buffer-menu-visit-tags-table ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (let ((file (buffer-file-name (Buffer-menu-buffer t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (if file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (visit-tags-table file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (error "Specified buffer has no file"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (defun Buffer-menu-1-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 "Select this line's buffer, alone, in full frame."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (switch-to-buffer (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 (bury-buffer (other-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (delete-other-windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 ;; XEmacs:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 ;; This is to get w->force_start set to nil. Don't ask me, I only work here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (set-window-buffer (selected-window) (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (defun Buffer-menu-mouse-select (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 "Select the buffer whose line you click on."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (let (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (set-buffer (event-buffer event)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (goto-char (event-point event)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (setq buffer (Buffer-menu-buffer t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (select-window (event-window event)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (if (and (window-dedicated-p (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (eq (selected-window) (frame-root-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (switch-to-buffer-other-frame buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (switch-to-buffer buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (defun Buffer-menu-maybe-mouse-select (event &optional click-count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (and (>= click-count 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (let ((buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (config (current-window-configuration)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (Buffer-menu-mouse-select event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (set-window-configuration config)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (goto-char point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (defun Buffer-menu-this-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 "Select this line's buffer in this window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (switch-to-buffer (Buffer-menu-buffer t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (defun Buffer-menu-other-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 "Select this line's buffer in other window, leaving buffer menu visible."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (switch-to-buffer-other-window (Buffer-menu-buffer t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (defun Buffer-menu-switch-other-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 "Make the other window select this line's buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 The current window remains selected."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (display-buffer (Buffer-menu-buffer t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (defun Buffer-menu-2-window ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 "Select this line's buffer, with previous buffer in second window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (let ((buff (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (menu (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (pop-up-windows t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (delete-other-windows)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 (switch-to-buffer (other-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (pop-to-buffer buff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (bury-buffer menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (defun Buffer-menu-toggle-read-only ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 "Toggle read-only status of buffer on this line, perhaps via version control."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (let (char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (set-buffer (Buffer-menu-buffer t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (modeline-toggle-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (setq char (if buffer-read-only ?% ? )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (forward-char 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (if (/= (following-char) char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (let (buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (delete-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (insert char))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 (defvar Buffer-menu-popup-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 '("Buffer Commands"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 ["Select Buffer" Buffer-menu-select t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 ["Select buffer Other Window" Buffer-menu-other-window t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 ["Clear Buffer Modification Flag" Buffer-menu-not-modified t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 "----"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 ["Mark Buffer for Selection" Buffer-menu-mark t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 ["Mark Buffer for Save" Buffer-menu-save t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 ["Mark Buffer for Deletion" Buffer-menu-delete t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 ["Unmark Buffer" Buffer-menu-unmark t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 "----"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 ["Delete/Save Marked Buffers" Buffer-menu-execute t]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (defun Buffer-menu-popup-menu (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (mouse-set-point event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (let ((buffer (Buffer-menu-buffer nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (if buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (popup-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 (nconc (list (car Buffer-menu-popup-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 "Commands on buffer \"" (buffer-name buffer) "\":")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 "----")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (cdr Buffer-menu-popup-menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (error "no buffer on this line"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (defvar list-buffers-header-line
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
503 (concat " MR Buffer Size Mode File\n"
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
504 " -- ------ ---- ---- ----\n"))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (defvar list-buffers-identification 'default-list-buffers-identification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 "String used to identify this buffer, or a function of one argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 to generate such a string. This variable is always buffer-local.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (make-variable-buffer-local 'list-buffers-identification)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (defvar list-buffers-directory nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (make-variable-buffer-local 'list-buffers-directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 ;; #### not synched
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (defun default-list-buffers-identification (output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (let ((file (or (buffer-file-name (current-buffer))
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
520 (and-boundp 'list-buffers-directory
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
521 list-buffers-directory)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (size (buffer-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 (mode mode-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 eob p s col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (set-buffer output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (setq eob (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (prin1 size output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (setq p (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 ;; right-justify the size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (move-to-column 19 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (setq col (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (if (> eob col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (goto-char eob))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (setq s (- 6 (- p col)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 (while (> s 0) ; speed/consing tradeoff...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (insert ? )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (setq s (1- s)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (indent-to 27 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (insert mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (if (not file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 ;; if the mode-name is really long, clip it for the filename
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (if (> 0 (setq s (- 39 (current-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (delete-char (max s (- eob (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (indent-to 40 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (insert file)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 ;; #### not synched
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (defun list-buffers-internal (output &optional predicate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (let ((current (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (buffers (buffer-list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 (set-buffer output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (setq buffer-read-only nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (buffer-disable-undo output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (insert list-buffers-header-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (while buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (let* ((col1 19)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (buffer (car buffers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (name (buffer-name buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 this-buffer-line-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (setq buffers (cdr buffers))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (cond ((null name)) ;deleted buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 ((and predicate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (not (if (stringp predicate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (string-match predicate name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (funcall predicate buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (let ((ro buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (id list-buffers-identification))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (set-buffer output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (setq this-buffer-line-start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (insert (if (eq buffer current)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (progn (setq current (point)) ?\.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (insert (if (buffer-modified-p buffer)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
583 ?\*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (insert (if ro
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ?\%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 ?\ ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (if (string-match "[\n\"\\ \t]" name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (let ((print-escape-newlines t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (prin1 name output))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (insert ?\ name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 (indent-to col1 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (cond ((stringp id)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 (insert id))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (id
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (condition-case e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (funcall id output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (princ "***" output) (prin1 e output)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (set-buffer output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (goto-char (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (put-nonduplicable-text-property this-buffer-line-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 'buffer-name name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 (put-nonduplicable-text-property this-buffer-line-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 'highlight t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (insert ?\n)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (Buffer-menu-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (if (not (bufferp current))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (goto-char current)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 ;(define-key ctl-x-map "\C-b" 'list-buffers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (defun list-buffers (&optional files-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 "Display a list of names of existing buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 The list is displayed in a buffer named `*Buffer List*'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 Note that buffers with names starting with spaces are omitted.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
620 Non-nil optional arg FILES-ONLY means mention only file buffers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 The M column contains a * for buffers that are modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 The R column contains a % for buffers that are read-only."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 (interactive (list (if current-prefix-arg t nil))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (display-buffer (list-buffers-noselect files-only)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 ;; #### not synched
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (defun list-buffers-noselect (&optional files-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 "Create and return a buffer with a list of names of existing buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 The buffer is named `*Buffer List*'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 Note that buffers with names starting with spaces are omitted.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
632 Non-nil optional arg FILES-ONLY means mention only file buffers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 The M column contains a * for buffers that are modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 The R column contains a % for buffers that are read-only."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 (let ((buffer (get-buffer-create "*Buffer List*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (list-buffers-internal buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (if (memq files-only '(t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 #'(lambda (b)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (let ((n (buffer-name b)))
5366
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 3162
diff changeset
641 (cond ((and (not (eql 0 (length n)))
f00192e1cd49 Examining the result of #'length: `eql', not `=', it's better style & cheaper
Aidan Kehoe <kehoea@parhasard.net>
parents: 3162
diff changeset
642 (eql (aref n 0) ?\ ))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ;;don't mention if starts with " "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (files-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (buffer-file-name b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 files-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
652 (defun buffers-menu-omit-invisible-buffers (buffer)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
653 "For use as a value of `buffers-menu-omit-function'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
654 Omits normally invisible buffers (those whose name begins with a space)."
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
655 (eql ?\ (elt (buffer-name buffer) 0)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
656
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
657 ;;; The Buffers tab
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
658
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
659 ;; Some of this is taken from the buffer-menu stuff in menubar-items.el
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
660
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
661 (defgroup buffers-tab nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
662 "Customization of `Buffers' tab."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
663 :group 'gutter)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
664
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
665 (defcustom buffers-tab-max-size 6
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
666 "*Maximum number of entries which may appear on the \"Buffers\" tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
667 If this is 10, then only the ten most-recently-selected buffers will be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
668 shown. If this is nil, then all buffers will be shown. Setting this to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
669 a large number or nil will slow down tab responsiveness."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
670 :type '(choice (const :tag "Show all" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
671 (integer 6))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
672 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
673
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
674 (defcustom buffers-tab-switch-to-buffer-function 'buffers-tab-switch-to-buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
675 "*The function to call to select a buffer from the buffers tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
676 `switch-to-buffer' is a good choice, as is `pop-to-buffer'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
677 :type '(radio (function-item switch-to-buffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
678 (function-item pop-to-buffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
679 (function :tag "Other"))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
680 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
681
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
682 (defcustom buffers-tab-omit-function 'buffers-menu-omit-invisible-buffers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
683 "*If non-nil, a function specifying the buffers to omit from the buffers tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
684 This is passed a buffer and should return non-nil if the buffer should be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
685 omitted. The default value `buffers-menu-omit-invisible-buffers' omits
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
686 buffers that are normally considered \"invisible\" (those whose name
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
687 begins with a space)."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
688 :type '(choice (const :tag "None" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
689 function)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
690 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
691
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
692 (defcustom buffers-tab-selection-function 'select-buffers-tab-buffers-by-mode
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
693 "*If non-nil, a function specifying the buffers to select from the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
694 buffers tab. This is passed two buffers and should return non-nil if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
695 the second buffer should be selected. The default value
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
696 `select-buffers-tab-buffers-by-mode' groups buffers by major mode and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
697 by `buffers-tab-grouping-regexp'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
698
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
699 :type '(choice (const :tag "None" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
700 function)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
701 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
702
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
703 (defcustom buffers-tab-filter-functions (list buffers-tab-selection-function)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
704 "*If non-nil, a list of functions specifying the buffers to select
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
705 from the buffers tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
706 Each function in the list is passed two buffers, the buffer to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
707 potentially select and the context buffer, and should return non-nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
708 if the first buffer should be selected. The default value groups
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
709 buffers by major mode and by `buffers-tab-grouping-regexp'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
710
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
711 :type '(choice (const :tag "None" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
712 sexp)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
713 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
714
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
715 (defcustom buffers-tab-sort-function nil
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
716 "*If non-nil, a function specifying the buffers to select from the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
717 buffers tab. This is passed the buffer list and returns the list in the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
718 order desired for the tab widget. The default value `nil' leaves the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
719 list in `buffer-list' order (usual most-recently-selected-first)."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
720
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
721 :type '(choice (const :tag "None" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
722 function)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
723 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
724
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
725 (make-face 'buffers-tab "Face for displaying the buffers tab.")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
726 (set-face-parent 'buffers-tab 'default)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
727
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
728 (defcustom buffers-tab-face 'buffers-tab
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
729 "*Face to use for displaying the buffers tab."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
730 :type 'face
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
731 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
732
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
733 (defcustom buffers-tab-grouping-regexp
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
734 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
735 "^\\(emacs-lisp-\\|lisp-\\)")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
736 "*If non-nil, a list of regular expressions for buffer grouping.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
737 Each regular expression is applied to the current major-mode symbol
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
738 name and mode-name, if it matches then any other buffers that match
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
739 the same regular expression be added to the current group."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
740 :type '(choice (const :tag "None" nil)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
741 sexp)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
742 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
743
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
744 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-tab-line
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
745 "*The function to call to return a string to represent a buffer in the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
746 buffers tab. The function is passed a buffer and should return a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
747 string. The default value `format-buffers-tab-line' just returns the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
748 name of the buffer, optionally truncated to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
749 `buffers-tab-max-buffer-line-length'. Also check out
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
750 `slow-format-buffers-menu-line' which returns a whole bunch of info
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
751 about a buffer."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
752 :type 'function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
753 :group 'buffers-tab)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
754
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
755 (defvar buffers-tab-default-buffer-line-length
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
756 (make-specifier-and-init 'generic '((global ((default) . 25))) t)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
757 "*Maximum length of text which may appear in a \"Buffers\" tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
758 This is a specifier, use set-specifier to modify it.")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
759
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
760 (defcustom buffers-tab-max-buffer-line-length
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
761 (specifier-instance buffers-tab-default-buffer-line-length)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
762 "*Maximum length of text which may appear in a \"Buffers\" tab.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
763 Buffer names over this length will be truncated with elipses.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
764 If this is 0, then the full buffer name will be shown."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
765 :type '(choice (const :tag "Show all" 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
766 (integer 25))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
767 :group 'buffers-tab
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
768 :set #'(lambda (var val)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
769 (set-specifier buffers-tab-default-buffer-line-length val)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
770 (setq buffers-tab-max-buffer-line-length val)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
772 (defun buffers-tab-switch-to-buffer (buffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
773 "For use as a value for `buffers-tab-switch-to-buffer-function'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
774 (unless (eq (window-buffer) buffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
775 ;; this used to add the norecord flag to both calls below.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
776 ;; this is bogus because it is a pervasive assumption in XEmacs
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
777 ;; that the current buffer is at the front of the buffers list.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
778 ;; for example, select an item and then do M-C-l
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
779 ;; (switch-to-other-buffer). Things get way confused.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
780 (if (> (length (windows-of-buffer buffer)) 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
781 (select-window (car (windows-of-buffer buffer)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
782 (switch-to-buffer buffer))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
783
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
784 (defun select-buffers-tab-buffers-by-mode (buffer-to-select buf1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
785 "For use as a value of `buffers-tab-selection-function'.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
786 This selects buffers by major mode `buffers-tab-grouping-regexp'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
787 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
788 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
789 buffer-to-select)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
790 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
791 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
792 position mismatch)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
793 (cond ((or (eq mode1 mode2)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
794 (eq modenm1 modenm2)
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
795 (and (setq position (position ?- mode1)) (> position 0)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
796 (prog2
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
797 (setq mismatch (mismatch mode1 mode2 :end1 position))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
798 (not (or (null mismatch) (eql mismatch position)))))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
799 (and buffers-tab-grouping-regexp
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
800 (find-if #'(lambda (x)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
801 (or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
802 (and (string-match x mode1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
803 (string-match x mode2))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
804 (and (string-match x modenm1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
805 (string-match x modenm2))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
806 buffers-tab-grouping-regexp)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
807 t)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
808 (t nil))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
809
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
810 (defun format-buffers-tab-line (buffer)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
811 "For use as a value of `buffers-tab-format-buffer-line-function'.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
812 This just returns the buffer's name, optionally truncated."
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
813 (let* ((len (specifier-instance buffers-tab-default-buffer-line-length))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
814 (buffer-name (buffer-name buffer))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
815 (len1 (length buffer-name)))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
816 (if (and (> len 0) (> len1 len))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
817 (if (and (> len1 3) (eql ?< (aref buffer-name (- len1 3)))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
818 (eql ?> (aref buffer-name (1- len1))))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
819 (concat (subseq buffer-name 0 (- len 6))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
820 "..." (subseq buffer-name -3))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
821 (concat (subseq buffer-name 0 (- len 3)) "..."))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
822 buffer-name)))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
823
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
824 ;;; #### SJT would like this function to have a sort function list. I
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
825 ;;; don't see how this could work given that sorting is not
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
826 ;;; cumulative --andyp.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
827 (defun buffers-tab-items (&optional in-deletion frame force-selection)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
828 "Return a list of tab instantiators based on the current buffers list.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
829 This function is used as the tab filter for the top-level buffers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
830 \"Buffers\" tab. It dynamically creates a list of tab instantiators
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
831 to use as the contents of the tab. The contents and order of the list
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
832 is controlled by `buffers-tab-filter-functions' which by default
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
833 groups buffers according to major mode and removes invisible buffers.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
834 You can control how many buffers will be shown by setting
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
835 `buffers-tab-max-size'. You can control the text of the tab items by
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
836 redefining the function `format-buffers-menu-line'."
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
837 (save-match-data
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
838 ;; NB it is too late if we run the omit function as part of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
839 ;; filter functions because we need to know which buffer is the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
840 ;; context buffer before they get run.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
841 (let* ((buffers (delete-if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
842 buffers-tab-omit-function (buffer-list frame)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
843 (first-buf (car buffers)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
844 ;; maybe force the selected window
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
845 (when (and force-selection
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
846 (not in-deletion)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
847 (not (eq first-buf (window-buffer (selected-window frame)))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
848 (setq buffers (cons (window-buffer (selected-window frame))
5652
cc6f0266bc36 Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents: 5490
diff changeset
849 (delete* first-buf buffers))))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
850 ;; if we're in deletion ignore the current buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
851 (when in-deletion
5652
cc6f0266bc36 Avoid #'delq in core Lisp, for the sake of style, a very slightly smaller binary
Aidan Kehoe <kehoea@parhasard.net>
parents: 5490
diff changeset
852 (setq buffers (delete* (current-buffer) buffers))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
853 (setq first-buf (car buffers)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
854 ;; filter buffers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
855 (when buffers-tab-filter-functions
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
856 (setq buffers
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
857 (mapcan #'(lambda (buf)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
858 (let ((tmp-buf buf))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
859 (mapc #'(lambda (fun)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
860 (unless (funcall fun buf first-buf)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
861 (setq tmp-buf nil)))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
862 buffers-tab-filter-functions)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
863 (and tmp-buf (list tmp-buf))))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
864 buffers)))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
865 ;; maybe shorten list of buffers
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
866 (and (integerp buffers-tab-max-size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
867 (> buffers-tab-max-size 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
868 (> (length buffers) buffers-tab-max-size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
869 (setcdr (nthcdr (1- buffers-tab-max-size) buffers) nil))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
870 ;; sort buffers in group (default is most-recently-selected)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
871 (when buffers-tab-sort-function
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
872 (setq buffers (funcall buffers-tab-sort-function buffers)))
5882
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
873 (labels
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
874 ((build-buffers-tab-internal (buffers)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
875 (let ((selected t))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
876 (mapcar
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
877 #'(lambda (buffer)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
878 (prog1
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
879 (vector
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
880 (funcall buffers-tab-format-buffer-line-function
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
881 buffer)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
882 (list buffers-tab-switch-to-buffer-function
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
883 (buffer-name buffer))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
884 :selected selected)
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
885 (when selected (setq selected nil))))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
886 buffers))))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
887 ;; convert list of buffers to list of structures used by tab widget
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
888 (setq buffers (build-buffers-tab-internal buffers))
bbe4146603db Reduce regexp usage, now CL-oriented non-regexp code available, core Lisp
Aidan Kehoe <kehoea@parhasard.net>
parents: 5652
diff changeset
889 buffers))))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 548
diff changeset
890
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 (provide 'buff-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 ;;; buff-menu.el ends here