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