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