annotate lisp/buff-menu.el @ 2311:98b714786ad0

(Fy_or_n_p): Handle `recenter' response type.
author Richard M. Stallman <rms@gnu.org>
date Mon, 22 Mar 1993 06:54:36 +0000
parents 10e417efb12a
children ec4ffd67483d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 194
diff changeset
1 ;;; buff-menu.el --- buffer menu main function and support functions.
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 194
diff changeset
2
845
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 801
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 801
diff changeset
4
801
e9e34745ae3b *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 777
diff changeset
5 ;; Maintainer: FSF
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
735
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; any later version.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; GNU General Public License for more details.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
23 ;;; Commentary:
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
24
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
25 ;; Edit, delete, or change attributes of all currently active Emacs
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
26 ;; buffers from a list summarizing thir state. A good way to browse
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
27 ;; any special or scratch buffers you have loaded, since you can't find
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
28 ;; them by filename.
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 845
diff changeset
29
801
e9e34745ae3b *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 777
diff changeset
30 ;;; Code:
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ; Put buffer *Buffer List* into proper mode right away
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ; so that from now on even list-buffers is enough to get a buffer menu.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 (defvar Buffer-menu-mode-map nil "")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 (if Buffer-menu-mode-map
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 (setq Buffer-menu-mode-map (make-keymap))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 (suppress-keymap Buffer-menu-mode-map t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 (define-key Buffer-menu-mode-map "q" 'Buffer-menu-select)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 (define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 (define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 (define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 (define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window)
735
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
46 (define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window)
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (define-key Buffer-menu-mode-map "s" 'Buffer-menu-save)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 (define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 (define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 (define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 (define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 (define-key Buffer-menu-mode-map " " 'next-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (define-key Buffer-menu-mode-map "n" 'next-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 (define-key Buffer-menu-mode-map "p" 'previous-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (define-key Buffer-menu-mode-map "\177" 'Buffer-menu-backup-unmark)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 (define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (define-key Buffer-menu-mode-map "?" 'describe-mode)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 (define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 (define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 ;; Buffer Menu mode is suitable only for specially formatted data.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (put 'Buffer-menu-mode 'mode-class 'special)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (defun Buffer-menu-mode ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 "Major mode for editing a list of buffers.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 Each line describes one of the buffers in Emacs.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Letters do not insert themselves; instead, they are commands.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 \\<Buffer-menu-mode-map>
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 \\[Buffer-menu-mark] -- mark buffer to be displayed.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 \\[Buffer-menu-select] -- select buffer of line point is on.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 Also show buffers marked with m in other windows.
777
c99faf9381bb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 756
diff changeset
74 \\[Buffer-menu-1-window] -- select that buffer in full-frame window.
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 \\[Buffer-menu-2-window] -- select that buffer in one window,
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 together with buffer selected before this one in another window.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 \\[Buffer-menu-this-window] -- select that buffer in place of the buffer menu buffer.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 \\[Buffer-menu-other-window] -- select that buffer in another window,
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 so the buffer menu buffer remains visible in its window.
735
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
80 \\[Buffer-menu-switch-other-window] -- switch the other window to this buffer.
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 \\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 \\[Buffer-menu-execute] -- delete or save marked buffers.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (kill-all-local-variables)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (use-local-map Buffer-menu-mode-map)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (setq truncate-lines t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (setq buffer-read-only t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 (setq major-mode 'Buffer-menu-mode)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (setq mode-name "Buffer Menu")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (run-hooks 'buffer-menu-mode-hook))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (defvar Buffer-menu-buffer-column 4)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 (defun Buffer-menu-buffer (error-if-non-existent-p)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 "Return buffer described by this line of buffer menu."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (forward-char Buffer-menu-buffer-column)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (let ((start (point))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 string)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ;; End of buffer name marked by tab or two spaces.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (re-search-forward "\t\\| ")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (skip-chars-backward " \t")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (setq string (buffer-substring start (point)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (or (get-buffer string)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (if error-if-non-existent-p
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (error "No buffer named \"%s\"" string)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 nil)))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
756
0276f8eb306f *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 735
diff changeset
115 (defun buffer-menu (&optional arg)
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 "Make a menu of buffers so you can save, delete or select them.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 With argument, show only buffers that are visiting files.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 Type ? after invocation to get help on commands available.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 Type q immediately to make the buffer menu go away."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (interactive "P")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (list-buffers arg)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (pop-to-buffer "*Buffer List*")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (forward-line 2)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (message
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 "Commands: d, s, x; 1, 2, m, u, q; delete; ~; ? for help."))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (defun Buffer-menu-mark ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (if (looking-at " [-M]")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (ding)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (delete-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (insert ?>)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 (forward-line 1))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (defun Buffer-menu-unmark ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 "Cancel all requested operations on buffer on this line."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (if (looking-at " [-M]")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (ding)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (let* ((buf (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (mod (buffer-modified-p buf))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (readonly (save-excursion (set-buffer buf) buffer-read-only))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (delete-char 3)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (insert (if readonly (if mod " *%" " %") (if mod " * " " ")))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (forward-line 1))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (defun Buffer-menu-backup-unmark ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 "Move up and cancel all requested operations on buffer on line above."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (forward-line -1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (Buffer-menu-unmark)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (forward-line -1))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (defun Buffer-menu-delete ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (if (looking-at " [-M]") ;header lines
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (ding)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (delete-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (insert ?D)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 (forward-line 1))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 (defun Buffer-menu-delete-backwards ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 "Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 and then move up one line"
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 (Buffer-menu-delete)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 (forward-line -2)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (if (looking-at " [-M]") (forward-line 1)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (defun Buffer-menu-save ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 "Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (forward-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (if (looking-at " [-M]") ;header lines
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (ding)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (delete-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (insert ?S)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (forward-line 1))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (defun Buffer-menu-not-modified ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 "Mark buffer on this line as unmodified (no changes to save)."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (set-buffer (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (set-buffer-modified-p nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 (beginning-of-line)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (forward-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 (if (looking-at "\\*")
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 (delete-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (insert ? )))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (defun Buffer-menu-execute ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 "Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 (goto-char (point-min))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 (forward-line 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (while (re-search-forward "^.S" nil t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (let ((modp nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 (set-buffer (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (save-buffer)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 (setq modp (buffer-modified-p)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 (delete-char -1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 (insert (if modp ?* ? ))))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 (save-excursion
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (goto-char (point-min))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (forward-line 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (let ((buff-menu-buffer (current-buffer))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (while (search-forward "\nD" nil t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (forward-char -1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (let ((buf (Buffer-menu-buffer nil)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (or (eq buf nil)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (eq buf buff-menu-buffer)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (save-excursion (kill-buffer buf))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (if (Buffer-menu-buffer nil)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (progn (delete-char 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (insert ? ))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (delete-region (point) (progn (forward-line 1) (point)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (forward-char -1))))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (defun Buffer-menu-select ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 "Select this line's buffer; also display buffers marked with `>'.
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (let ((buff (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (menu (current-buffer))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (others ())
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 tem)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (goto-char (point-min))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (while (search-forward "\n>" nil t)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (setq tem (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (let ((buffer-read-only nil))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (delete-char -1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (insert ?\ ))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (setq others (nreverse others)
777
c99faf9381bb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 756
diff changeset
252 tem (/ (1- (frame-height)) (1+ (length others))))
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (delete-other-windows)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (switch-to-buffer buff)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (or (eq menu buff)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (bury-buffer menu))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (while others
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (split-window nil tem)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (other-window 1)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (switch-to-buffer (car others))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (setq others (cdr others)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (other-window 1))) ;back to the beginning!
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (defun Buffer-menu-visit-tags-table ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 (let ((file (buffer-file-name (Buffer-menu-buffer t))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 (if file
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 (visit-tags-table file)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (error "Specified buffer has no file"))))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (defun Buffer-menu-1-window ()
777
c99faf9381bb *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 756
diff changeset
273 "Select this line's buffer, alone, in full frame."
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 (switch-to-buffer (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (bury-buffer (other-buffer))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 (delete-other-windows))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 (defun Buffer-menu-this-window ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 "Select this line's buffer in this window."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 (switch-to-buffer (Buffer-menu-buffer t)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (defun Buffer-menu-other-window ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 "Select this line's buffer in other window, leaving buffer menu visible."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 (switch-to-buffer-other-window (Buffer-menu-buffer t)))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
735
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
289 (defun Buffer-menu-switch-other-window ()
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
290 "Make the other window select this line's buffer.
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
291 The current window remains selected."
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
292 (interactive)
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
293 (display-buffer (Buffer-menu-buffer t)))
ea0823fe7df5 *** empty log message ***
Roland McGrath <roland@gnu.org>
parents: 662
diff changeset
294
194
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (defun Buffer-menu-2-window ()
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 "Select this line's buffer, with previous buffer in second window."
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 (interactive)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (let ((buff (Buffer-menu-buffer t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (menu (current-buffer))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 (pop-up-windows t))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (switch-to-buffer (other-buffer))
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (pop-to-buffer buff)
5b0d1a9cf37e Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (bury-buffer menu)))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 194
diff changeset
304
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 194
diff changeset
305 ;;; buff-menu.el ends here