Mercurial > hg > xemacs-beta
annotate lisp/buff-menu.el @ 5448:89331fa1c819
Merged with trunk.
| author | Mats Lidell <matsl@xemacs.org> |
|---|---|
| date | Thu, 06 Jan 2011 00:35:22 +0100 |
| parents | 308d34e9f07d |
| children | ac37a5f7e5be |
| 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 ;;;###autoload | |
| 514 (defvar list-buffers-directory nil) | |
| 515 | |
| 516 ;;;###autoload | |
| 517 (make-variable-buffer-local 'list-buffers-directory) | |
| 518 | |
| 519 ;; #### not synched | |
| 520 (defun default-list-buffers-identification (output) | |
| 521 (save-excursion | |
| 522 (let ((file (or (buffer-file-name (current-buffer)) | |
| 776 | 523 (and-boundp 'list-buffers-directory |
| 524 list-buffers-directory))) | |
| 428 | 525 (size (buffer-size)) |
| 526 (mode mode-name) | |
| 527 eob p s col) | |
| 528 (set-buffer output) | |
| 529 (end-of-line) | |
| 530 (setq eob (point)) | |
| 531 (prin1 size output) | |
| 532 (setq p (point)) | |
| 533 ;; right-justify the size | |
| 534 (move-to-column 19 t) | |
| 535 (setq col (point)) | |
| 536 (if (> eob col) | |
| 537 (goto-char eob)) | |
| 538 (setq s (- 6 (- p col))) | |
| 539 (while (> s 0) ; speed/consing tradeoff... | |
| 540 (insert ? ) | |
| 541 (setq s (1- s))) | |
| 542 (end-of-line) | |
| 543 (indent-to 27 1) | |
| 544 (insert mode) | |
| 545 (if (not file) | |
| 546 nil | |
| 547 ;; if the mode-name is really long, clip it for the filename | |
| 548 (if (> 0 (setq s (- 39 (current-column)))) | |
| 549 (delete-char (max s (- eob (point))))) | |
| 550 (indent-to 40 1) | |
| 551 (insert file))))) | |
| 552 | |
| 553 ;; #### not synched | |
| 554 (defun list-buffers-internal (output &optional predicate) | |
| 555 (let ((current (current-buffer)) | |
| 556 (buffers (buffer-list))) | |
| 557 (save-excursion | |
| 558 (set-buffer output) | |
| 559 (setq buffer-read-only nil) | |
| 560 (erase-buffer) | |
| 561 (buffer-disable-undo output) | |
| 562 (insert list-buffers-header-line) | |
| 563 | |
| 564 (while buffers | |
| 565 (let* ((col1 19) | |
| 566 (buffer (car buffers)) | |
| 567 (name (buffer-name buffer)) | |
| 568 this-buffer-line-start) | |
| 569 (setq buffers (cdr buffers)) | |
| 570 (cond ((null name)) ;deleted buffer | |
| 571 ((and predicate | |
| 572 (not (if (stringp predicate) | |
| 573 (string-match predicate name) | |
| 574 (funcall predicate buffer)))) | |
| 575 nil) | |
| 576 (t | |
| 577 (set-buffer buffer) | |
| 578 (let ((ro buffer-read-only) | |
| 579 (id list-buffers-identification)) | |
| 580 (set-buffer output) | |
| 581 (setq this-buffer-line-start (point)) | |
| 582 (insert (if (eq buffer current) | |
| 583 (progn (setq current (point)) ?\.) | |
| 584 ?\ )) | |
| 585 (insert (if (buffer-modified-p buffer) | |
| 444 | 586 ?\* |
| 428 | 587 ?\ )) |
| 588 (insert (if ro | |
| 589 ?\% | |
| 590 ?\ )) | |
| 591 (if (string-match "[\n\"\\ \t]" name) | |
| 592 (let ((print-escape-newlines t)) | |
| 593 (prin1 name output)) | |
| 594 (insert ?\ name)) | |
| 595 (indent-to col1 1) | |
| 596 (cond ((stringp id) | |
| 597 (insert id)) | |
| 598 (id | |
| 599 (set-buffer buffer) | |
| 600 (condition-case e | |
| 601 (funcall id output) | |
| 602 (error | |
| 603 (princ "***" output) (prin1 e output))) | |
| 604 (set-buffer output) | |
| 605 (goto-char (point-max))))) | |
| 606 (put-nonduplicable-text-property this-buffer-line-start | |
| 607 (point) | |
| 608 'buffer-name name) | |
| 609 (put-nonduplicable-text-property this-buffer-line-start | |
| 610 (point) | |
| 611 'highlight t) | |
| 612 (insert ?\n))))) | |
| 613 | |
| 614 (Buffer-menu-mode) | |
| 615 (if (not (bufferp current)) | |
| 616 (goto-char current))))) | |
| 617 ;(define-key ctl-x-map "\C-b" 'list-buffers) | |
| 618 | |
| 619 (defun list-buffers (&optional files-only) | |
| 620 "Display a list of names of existing buffers. | |
| 621 The list is displayed in a buffer named `*Buffer List*'. | |
| 622 Note that buffers with names starting with spaces are omitted. | |
| 444 | 623 Non-nil optional arg FILES-ONLY means mention only file buffers. |
| 428 | 624 |
| 625 The M column contains a * for buffers that are modified. | |
| 626 The R column contains a % for buffers that are read-only." | |
| 627 (interactive (list (if current-prefix-arg t nil))) ; XEmacs | |
| 628 (display-buffer (list-buffers-noselect files-only))) | |
| 629 | |
| 630 ;; #### not synched | |
| 631 (defun list-buffers-noselect (&optional files-only) | |
| 632 "Create and return a buffer with a list of names of existing buffers. | |
| 633 The buffer is named `*Buffer List*'. | |
| 634 Note that buffers with names starting with spaces are omitted. | |
| 444 | 635 Non-nil optional arg FILES-ONLY means mention only file buffers. |
| 428 | 636 |
| 637 The M column contains a * for buffers that are modified. | |
| 638 The R column contains a % for buffers that are read-only." | |
| 639 (let ((buffer (get-buffer-create "*Buffer List*"))) | |
| 640 (list-buffers-internal buffer | |
| 641 (if (memq files-only '(t nil)) | |
| 642 #'(lambda (b) | |
| 643 (let ((n (buffer-name b))) | |
| 644 (cond ((and (/= 0 (length n)) | |
| 645 (= (aref n 0) ?\ )) | |
| 646 ;;don't mention if starts with " " | |
| 647 nil) | |
| 648 (files-only | |
| 649 (buffer-file-name b)) | |
| 650 (t | |
| 651 t)))) | |
| 652 files-only)) | |
| 653 buffer)) | |
| 654 | |
| 442 | 655 (defun buffers-menu-omit-invisible-buffers (buf) |
| 656 "For use as a value of `buffers-menu-omit-function'. | |
| 657 Omits normally invisible buffers (those whose name begins with a space)." | |
| 658 (not (null (string-match "\\` " (buffer-name buf))))) | |
| 659 | |
| 771 | 660 ;;; The Buffers tab |
| 661 | |
| 662 ;; Some of this is taken from the buffer-menu stuff in menubar-items.el | |
| 663 | |
| 664 (defgroup buffers-tab nil | |
| 665 "Customization of `Buffers' tab." | |
| 666 :group 'gutter) | |
| 667 | |
| 668 (defcustom buffers-tab-max-size 6 | |
| 669 "*Maximum number of entries which may appear on the \"Buffers\" tab. | |
| 670 If this is 10, then only the ten most-recently-selected buffers will be | |
| 671 shown. If this is nil, then all buffers will be shown. Setting this to | |
| 672 a large number or nil will slow down tab responsiveness." | |
| 673 :type '(choice (const :tag "Show all" nil) | |
| 674 (integer 6)) | |
| 675 :group 'buffers-tab) | |
| 676 | |
| 677 (defcustom buffers-tab-switch-to-buffer-function 'buffers-tab-switch-to-buffer | |
| 678 "*The function to call to select a buffer from the buffers tab. | |
| 679 `switch-to-buffer' is a good choice, as is `pop-to-buffer'." | |
| 680 :type '(radio (function-item switch-to-buffer) | |
| 681 (function-item pop-to-buffer) | |
| 682 (function :tag "Other")) | |
| 683 :group 'buffers-tab) | |
| 684 | |
| 685 (defcustom buffers-tab-omit-function 'buffers-menu-omit-invisible-buffers | |
| 686 "*If non-nil, a function specifying the buffers to omit from the buffers tab. | |
| 687 This is passed a buffer and should return non-nil if the buffer should be | |
| 688 omitted. The default value `buffers-menu-omit-invisible-buffers' omits | |
| 689 buffers that are normally considered \"invisible\" (those whose name | |
| 690 begins with a space)." | |
| 691 :type '(choice (const :tag "None" nil) | |
| 692 function) | |
| 693 :group 'buffers-tab) | |
| 694 | |
| 695 (defcustom buffers-tab-selection-function 'select-buffers-tab-buffers-by-mode | |
| 696 "*If non-nil, a function specifying the buffers to select from the | |
| 697 buffers tab. This is passed two buffers and should return non-nil if | |
| 698 the second buffer should be selected. The default value | |
| 699 `select-buffers-tab-buffers-by-mode' groups buffers by major mode and | |
| 700 by `buffers-tab-grouping-regexp'." | |
| 701 | |
| 702 :type '(choice (const :tag "None" nil) | |
| 703 function) | |
| 704 :group 'buffers-tab) | |
| 705 | |
| 706 (defcustom buffers-tab-filter-functions (list buffers-tab-selection-function) | |
| 707 "*If non-nil, a list of functions specifying the buffers to select | |
| 708 from the buffers tab. | |
| 709 Each function in the list is passed two buffers, the buffer to | |
| 710 potentially select and the context buffer, and should return non-nil | |
| 711 if the first buffer should be selected. The default value groups | |
| 712 buffers by major mode and by `buffers-tab-grouping-regexp'." | |
| 713 | |
| 714 :type '(choice (const :tag "None" nil) | |
| 715 sexp) | |
| 716 :group 'buffers-tab) | |
| 717 | |
| 718 (defcustom buffers-tab-sort-function nil | |
| 719 "*If non-nil, a function specifying the buffers to select from the | |
| 720 buffers tab. This is passed the buffer list and returns the list in the | |
| 721 order desired for the tab widget. The default value `nil' leaves the | |
| 722 list in `buffer-list' order (usual most-recently-selected-first)." | |
| 723 | |
| 724 :type '(choice (const :tag "None" nil) | |
| 725 function) | |
| 726 :group 'buffers-tab) | |
| 727 | |
| 728 (make-face 'buffers-tab "Face for displaying the buffers tab.") | |
| 729 (set-face-parent 'buffers-tab 'default) | |
| 730 | |
| 731 (defcustom buffers-tab-face 'buffers-tab | |
| 732 "*Face to use for displaying the buffers tab." | |
| 733 :type 'face | |
| 734 :group 'buffers-tab) | |
| 735 | |
| 736 (defcustom buffers-tab-grouping-regexp | |
| 737 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)" | |
| 738 "^\\(emacs-lisp-\\|lisp-\\)") | |
| 739 "*If non-nil, a list of regular expressions for buffer grouping. | |
| 740 Each regular expression is applied to the current major-mode symbol | |
| 741 name and mode-name, if it matches then any other buffers that match | |
| 742 the same regular expression be added to the current group." | |
| 743 :type '(choice (const :tag "None" nil) | |
| 744 sexp) | |
| 745 :group 'buffers-tab) | |
| 746 | |
| 747 (defcustom buffers-tab-format-buffer-line-function 'format-buffers-tab-line | |
| 748 "*The function to call to return a string to represent a buffer in the | |
| 749 buffers tab. The function is passed a buffer and should return a | |
| 750 string. The default value `format-buffers-tab-line' just returns the | |
| 751 name of the buffer, optionally truncated to | |
| 752 `buffers-tab-max-buffer-line-length'. Also check out | |
| 753 `slow-format-buffers-menu-line' which returns a whole bunch of info | |
| 754 about a buffer." | |
| 755 :type 'function | |
| 756 :group 'buffers-tab) | |
| 757 | |
| 758 (defvar buffers-tab-default-buffer-line-length | |
| 759 (make-specifier-and-init 'generic '((global ((default) . 25))) t) | |
| 760 "*Maximum length of text which may appear in a \"Buffers\" tab. | |
| 761 This is a specifier, use set-specifier to modify it.") | |
| 762 | |
| 763 (defcustom buffers-tab-max-buffer-line-length | |
| 764 (specifier-instance buffers-tab-default-buffer-line-length) | |
| 765 "*Maximum length of text which may appear in a \"Buffers\" tab. | |
| 766 Buffer names over this length will be truncated with elipses. | |
| 767 If this is 0, then the full buffer name will be shown." | |
| 768 :type '(choice (const :tag "Show all" 0) | |
| 769 (integer 25)) | |
| 770 :group 'buffers-tab | |
| 771 :set #'(lambda (var val) | |
| 772 (set-specifier buffers-tab-default-buffer-line-length val) | |
| 773 (setq buffers-tab-max-buffer-line-length val))) | |
| 774 | |
| 775 (defun buffers-tab-switch-to-buffer (buffer) | |
| 776 "For use as a value for `buffers-tab-switch-to-buffer-function'." | |
| 777 (unless (eq (window-buffer) buffer) | |
| 778 ;; this used to add the norecord flag to both calls below. | |
| 779 ;; this is bogus because it is a pervasive assumption in XEmacs | |
| 780 ;; that the current buffer is at the front of the buffers list. | |
| 781 ;; for example, select an item and then do M-C-l | |
| 782 ;; (switch-to-other-buffer). Things get way confused. | |
| 783 (if (> (length (windows-of-buffer buffer)) 0) | |
| 784 (select-window (car (windows-of-buffer buffer))) | |
| 785 (switch-to-buffer buffer)))) | |
| 786 | |
| 787 (defun select-buffers-tab-buffers-by-mode (buffer-to-select buf1) | |
| 788 "For use as a value of `buffers-tab-selection-function'. | |
| 789 This selects buffers by major mode `buffers-tab-grouping-regexp'." | |
| 790 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1))) | |
| 791 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode | |
| 792 buffer-to-select))) | |
| 793 (modenm1 (symbol-value-in-buffer 'mode-name buf1)) | |
| 794 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select))) | |
| 795 (cond ((or (eq mode1 mode2) | |
| 796 (eq modenm1 modenm2) | |
| 797 (and (string-match "^[^-]+-" mode1) | |
| 798 (string-match | |
| 799 (concat "^" (regexp-quote | |
| 800 (substring mode1 0 (match-end 0)))) | |
| 801 mode2)) | |
| 802 (and buffers-tab-grouping-regexp | |
| 803 (find-if #'(lambda (x) | |
| 804 (or | |
| 805 (and (string-match x mode1) | |
| 806 (string-match x mode2)) | |
| 807 (and (string-match x modenm1) | |
| 808 (string-match x modenm2)))) | |
| 809 buffers-tab-grouping-regexp))) | |
| 810 t) | |
| 811 (t nil)))) | |
| 812 | |
| 813 (defun format-buffers-tab-line (buffer) | |
| 814 "For use as a value of `buffers-tab-format-buffer-line-function'. | |
| 815 This just returns the buffer's name, optionally truncated." | |
| 816 (let ((len (specifier-instance buffers-tab-default-buffer-line-length))) | |
| 817 (if (and (> len 0) | |
| 818 (> (length (buffer-name buffer)) len)) | |
| 819 (if (string-match ".*<.>$" (buffer-name buffer)) | |
| 820 (concat (substring (buffer-name buffer) | |
| 821 0 (- len 6)) "..." | |
| 822 (substring (buffer-name buffer) -3)) | |
| 823 (concat (substring (buffer-name buffer) | |
| 824 0 (- len 3)) "...")) | |
| 825 (buffer-name buffer)))) | |
| 826 | |
| 827 (defsubst build-buffers-tab-internal (buffers) | |
| 828 (let ((selected t)) | |
| 829 (mapcar | |
| 830 #'(lambda (buffer) | |
| 831 (prog1 | |
| 832 (vector | |
| 833 (funcall buffers-tab-format-buffer-line-function | |
| 834 buffer) | |
| 835 (list buffers-tab-switch-to-buffer-function | |
| 836 (buffer-name buffer)) | |
| 837 :selected selected) | |
| 838 (when selected (setq selected nil)))) | |
| 839 buffers))) | |
| 840 | |
| 841 ;;; #### SJT would like this function to have a sort function list. I | |
| 842 ;;; don't see how this could work given that sorting is not | |
| 843 ;;; cumulative --andyp. | |
| 844 (defun buffers-tab-items (&optional in-deletion frame force-selection) | |
| 845 "Return a list of tab instantiators based on the current buffers list. | |
| 846 This function is used as the tab filter for the top-level buffers | |
| 847 \"Buffers\" tab. It dynamically creates a list of tab instantiators | |
| 848 to use as the contents of the tab. The contents and order of the list | |
| 849 is controlled by `buffers-tab-filter-functions' which by default | |
| 850 groups buffers according to major mode and removes invisible buffers. | |
| 851 You can control how many buffers will be shown by setting | |
| 852 `buffers-tab-max-size'. You can control the text of the tab items by | |
| 853 redefining the function `format-buffers-menu-line'." | |
| 854 (save-match-data | |
| 855 ;; NB it is too late if we run the omit function as part of the | |
| 856 ;; filter functions because we need to know which buffer is the | |
| 857 ;; context buffer before they get run. | |
| 858 (let* ((buffers (delete-if | |
| 859 buffers-tab-omit-function (buffer-list frame))) | |
| 860 (first-buf (car buffers))) | |
| 861 ;; maybe force the selected window | |
| 862 (when (and force-selection | |
| 863 (not in-deletion) | |
| 864 (not (eq first-buf (window-buffer (selected-window frame))))) | |
| 865 (setq buffers (cons (window-buffer (selected-window frame)) | |
| 866 (delq first-buf buffers)))) | |
| 867 ;; if we're in deletion ignore the current buffer | |
| 868 (when in-deletion | |
| 869 (setq buffers (delq (current-buffer) buffers)) | |
| 870 (setq first-buf (car buffers))) | |
| 871 ;; filter buffers | |
| 872 (when buffers-tab-filter-functions | |
| 873 (setq buffers | |
| 874 (delete-if | |
| 875 #'null | |
| 876 (mapcar #'(lambda (buf) | |
| 877 (let ((tmp-buf buf)) | |
| 878 (mapc #'(lambda (fun) | |
| 879 (unless (funcall fun buf first-buf) | |
| 880 (setq tmp-buf nil))) | |
| 881 buffers-tab-filter-functions) | |
| 882 tmp-buf)) | |
| 883 buffers)))) | |
| 884 ;; maybe shorten list of buffers | |
| 885 (and (integerp buffers-tab-max-size) | |
| 886 (> buffers-tab-max-size 1) | |
| 887 (> (length buffers) buffers-tab-max-size) | |
| 888 (setcdr (nthcdr (1- buffers-tab-max-size) buffers) nil)) | |
| 889 ;; sort buffers in group (default is most-recently-selected) | |
| 890 (when buffers-tab-sort-function | |
| 891 (setq buffers (funcall buffers-tab-sort-function buffers))) | |
| 892 ;; convert list of buffers to list of structures used by tab widget | |
| 893 (setq buffers (build-buffers-tab-internal buffers)) | |
| 894 buffers))) | |
| 895 | |
| 428 | 896 (provide 'buff-menu) |
| 897 | |
| 898 ;;; buff-menu.el ends here |
