comparison lisp/buff-menu.el @ 2334:ec4ffd67483d

Incorporated changes from Bob Weiner's enhanced buff-menu from the LCD archive.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Tue, 23 Mar 1993 07:26:34 +0000
parents 10e417efb12a
children c5d0140aa7b6
comparison
equal deleted inserted replaced
2333:47e301d9868b 2334:ec4ffd67483d
1 ;;; buff-menu.el --- buffer menu main function and support functions. 1 ;;; buff-menu.el --- buffer menu main function and support functions.
2 2
3 ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
4 4
5 ;; Author: Bob Weiner <rsw@cs.brown.edu>
5 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Adapted-by: Eric S. Raymond <esr@snark.thyrsus.com>
6 8
7 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
8 10
9 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
23 ;;; Commentary: 25 ;;; Commentary:
24 26
25 ;; Edit, delete, or change attributes of all currently active Emacs 27 ;; Edit, delete, or change attributes of all currently active Emacs
26 ;; buffers from a list summarizing thir state. A good way to browse 28 ;; buffers from a list summarizing thir state. A good way to browse
27 ;; any special or scratch buffers you have loaded, since you can't find 29 ;; any special or scratch buffers you have loaded, since you can't find
28 ;; them by filename. 30 ;; them by filename. The single entry point is `Buffer-menu-mode',
31 ;; normally bound to C-x C-b.
32
33 ;;; Change Log:
34
35 ;; Merged by esr with recent mods to Emacs 19 buff-menu, 23 Mar 1993
36 ;;
37 ;; Modified by Bob Weiner, Motorola, Inc., 3/1/89
38 ;;
39 ;; Save window configuration when 'buffer-menu' is called so that
40 ;; previous window configuration is restored. prior to selecting
41 ;; buffers.
42 ;; Made 'Buffer-menu-select' also perform a 'Buffer-menu-execute'.
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.
29 50
30 ;;; Code: 51 ;;; Code:
52
53 (defvar *buff-window-config* nil
54 "Stores window configuration upon entry of 'buffer-menu'. Used to
55 restore window configuration when only one buffer is selected.")
31 56
32 ; Put buffer *Buffer List* into proper mode right away 57 ; Put buffer *Buffer List* into proper mode right away
33 ; so that from now on even list-buffers is enough to get a buffer menu. 58 ; so that from now on even list-buffers is enough to get a buffer menu.
34 59
35 (defvar Buffer-menu-mode-map nil "") 60 (defvar Buffer-menu-mode-map nil "")
83 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down. 108 \\[Buffer-menu-save] -- mark that buffer to be saved, and move down.
84 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down. 109 \\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down.
85 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up. 110 \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up.
86 \\[Buffer-menu-execute] -- delete or save marked buffers. 111 \\[Buffer-menu-execute] -- delete or save marked buffers.
87 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line. 112 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
113 With prefix argument, also move up one line.
88 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks." 114 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks."
89 (kill-all-local-variables) 115 (kill-all-local-variables)
90 (use-local-map Buffer-menu-mode-map) 116 (use-local-map Buffer-menu-mode-map)
91 (setq truncate-lines t) 117 (setq truncate-lines t)
92 (setq buffer-read-only t) 118 (setq buffer-read-only t)
93 (setq major-mode 'Buffer-menu-mode) 119 (setq major-mode 'Buffer-menu-mode)
94 (setq mode-name "Buffer Menu") 120 (setq mode-name "Buffer Menu")
95 (run-hooks 'buffer-menu-mode-hook)) 121 (run-hooks 'buffer-menu-mode-hook))
96 122
97 (defvar Buffer-menu-buffer-column 4) 123 (defvar Buffer-menu-buffer-column nil)
124
125 (defvar Buffer-menu-size-column nil)
98 126
99 (defun Buffer-menu-buffer (error-if-non-existent-p) 127 (defun Buffer-menu-buffer (error-if-non-existent-p)
100 "Return buffer described by this line of buffer menu." 128 "Return buffer described by this line of buffer menu."
129 (if (null Buffer-menu-buffer-column)
130 (save-excursion
131 (goto-char (point-min))
132 (search-forward "Buffer")
133 (backward-word 1)
134 (setq Buffer-menu-buffer-column (current-column))
135 (search-forward "Size")
136 (backward-word 1)
137 (setq Buffer-menu-size-column (current-column))))
101 (save-excursion 138 (save-excursion
102 (beginning-of-line) 139 (beginning-of-line)
103 (forward-char Buffer-menu-buffer-column) 140 (forward-char Buffer-menu-buffer-column)
104 (let ((start (point)) 141 (let ((start (point))
105 string) 142 string)
114 151
115 (defun buffer-menu (&optional arg) 152 (defun buffer-menu (&optional arg)
116 "Make a menu of buffers so you can save, delete or select them. 153 "Make a menu of buffers so you can save, delete or select them.
117 With argument, show only buffers that are visiting files. 154 With argument, show only buffers that are visiting files.
118 Type ? after invocation to get help on commands available. 155 Type ? after invocation to get help on commands available.
119 Type q immediately to make the buffer menu go away." 156 Type q immediately to make the buffer menu go away and to restore
157 previous window configuration."
120 (interactive "P") 158 (interactive "P")
159 (setq *buff-window-config* (current-window-configuration))
121 (list-buffers arg) 160 (list-buffers arg)
122 (pop-to-buffer "*Buffer List*") 161 (pop-to-buffer "*Buffer List*")
123 (forward-line 2) 162 (forward-line 2)
124 (message 163 (message
125 "Commands: d, s, x; 1, 2, m, u, q; delete; ~; ? for help.")) 164 "Commands: d, s, x; 1, 2, m, u; delete; ~; q to quit; ? for help."))
126 165
127 (defun Buffer-menu-mark () 166 (defun Buffer-menu-mark ()
128 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command." 167 "Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
129 (interactive) 168 (interactive)
130 (beginning-of-line) 169 (beginning-of-line)
133 (let ((buffer-read-only nil)) 172 (let ((buffer-read-only nil))
134 (delete-char 1) 173 (delete-char 1)
135 (insert ?>) 174 (insert ?>)
136 (forward-line 1)))) 175 (forward-line 1))))
137 176
138 (defun Buffer-menu-unmark () 177 (defun Buffer-menu-unmark (&optional backup)
139 "Cancel all requested operations on buffer on this line." 178 "Cancel all requested operations on buffer on this line and move down.
140 (interactive) 179 Optional ARG means move up."
180 (interactive "P")
141 (beginning-of-line) 181 (beginning-of-line)
142 (if (looking-at " [-M]") 182 (if (looking-at " [-M]")
143 (ding) 183 (ding)
144 (let* ((buf (Buffer-menu-buffer t)) 184 (let* ((buf (Buffer-menu-buffer t))
145 (mod (buffer-modified-p buf)) 185 (mod (buffer-modified-p buf))
146 (readonly (save-excursion (set-buffer buf) buffer-read-only)) 186 (readonly (save-excursion (set-buffer buf) buffer-read-only))
147 (buffer-read-only nil)) 187 (buffer-read-only nil))
148 (delete-char 3) 188 (delete-char 3)
149 (insert (if readonly (if mod " *%" " %") (if mod " * " " "))))) 189 (insert (if readonly (if mod " *%" " %") (if mod " * " " ")))))
150 (forward-line 1)) 190 (forward-line (if backup -1 1)))
151 191
152 (defun Buffer-menu-backup-unmark () 192 (defun Buffer-menu-backup-unmark ()
153 "Move up and cancel all requested operations on buffer on line above." 193 "Move up and cancel all requested operations on buffer on line above."
154 (interactive) 194 (interactive)
155 (forward-line -1) 195 (forward-line -1)
248 (delete-char -1) 288 (delete-char -1)
249 (insert ?\ )) 289 (insert ?\ ))
250 (or (eq tem buff) (memq tem others) (setq others (cons tem others)))) 290 (or (eq tem buff) (memq tem others) (setq others (cons tem others))))
251 (setq others (nreverse others) 291 (setq others (nreverse others)
252 tem (/ (1- (frame-height)) (1+ (length others)))) 292 tem (/ (1- (frame-height)) (1+ (length others))))
293 (Buffer-menu-execute)
253 (delete-other-windows) 294 (delete-other-windows)
254 (switch-to-buffer buff) 295 (switch-to-buffer buff)
255 (or (eq menu buff) 296 (or (eq menu buff)
256 (bury-buffer menu)) 297 (bury-buffer menu))
257 (while others 298 (if (equal (length others) 0)
258 (split-window nil tem) 299 (progn
259 (other-window 1) 300 ;; Restore previous window configuration before displaying
260 (switch-to-buffer (car others)) 301 ;; selected buffers.
261 (setq others (cdr others))) 302 (if *buff-window-config*
262 (other-window 1))) ;back to the beginning! 303 (progn
304 (set-window-configuration *buff-window-config*)
305 (setq *buff-window-config* nil)))
306 (switch-to-buffer buff))
307 (while others
308 (split-window nil tem)
309 (other-window 1)
310 (switch-to-buffer (car others))
311 (setq others (cdr others)))
312 (other-window 1) ;back to the beginning!
313 )))
314
263 315
264 (defun Buffer-menu-visit-tags-table () 316 (defun Buffer-menu-visit-tags-table ()
265 "Visit the tags table in the buffer on this line. See `visit-tags-table'." 317 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
266 (interactive) 318 (interactive)
267 (let ((file (buffer-file-name (Buffer-menu-buffer t)))) 319 (let ((file (buffer-file-name (Buffer-menu-buffer t))))
296 "Select this line's buffer, with previous buffer in second window." 348 "Select this line's buffer, with previous buffer in second window."
297 (interactive) 349 (interactive)
298 (let ((buff (Buffer-menu-buffer t)) 350 (let ((buff (Buffer-menu-buffer t))
299 (menu (current-buffer)) 351 (menu (current-buffer))
300 (pop-up-windows t)) 352 (pop-up-windows t))
353 (delete-other-windows)
301 (switch-to-buffer (other-buffer)) 354 (switch-to-buffer (other-buffer))
302 (pop-to-buffer buff) 355 (pop-to-buffer buff)
303 (bury-buffer menu))) 356 (bury-buffer menu)))
304 357
305 ;;; buff-menu.el ends here 358 ;;; buff-menu.el ends here