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