| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
(defgroup Buffer-menu nil |
|---|
| 68 |
"Show a menu of all buffers in a buffer." |
|---|
| 69 |
:group 'tools |
|---|
| 70 |
:group 'convenience) |
|---|
| 71 |
|
|---|
| 72 |
(defcustom Buffer-menu-use-header-line t |
|---|
| 73 |
"*Non-nil means to use an immovable header-line." |
|---|
| 74 |
:type 'boolean |
|---|
| 75 |
:group 'Buffer-menu) |
|---|
| 76 |
|
|---|
| 77 |
(defface buffer-menu-buffer |
|---|
| 78 |
'((t (:weight bold))) |
|---|
| 79 |
"Face used to highlight buffer names in the buffer menu." |
|---|
| 80 |
:group 'Buffer-menu) |
|---|
| 81 |
(put 'Buffer-menu-buffer 'face-alias 'buffer-menu-buffer) |
|---|
| 82 |
|
|---|
| 83 |
(defcustom Buffer-menu-buffer+size-width 26 |
|---|
| 84 |
"*How wide to jointly make the buffer name and size columns." |
|---|
| 85 |
:type 'number |
|---|
| 86 |
:group 'Buffer-menu) |
|---|
| 87 |
|
|---|
| 88 |
(defcustom Buffer-menu-mode-width 16 |
|---|
| 89 |
"*How wide to make the mode name column." |
|---|
| 90 |
:type 'number |
|---|
| 91 |
:group 'Buffer-menu) |
|---|
| 92 |
|
|---|
| 93 |
(defcustom Buffer-menu-use-frame-buffer-list t |
|---|
| 94 |
"If non-nil, the Buffer Menu uses the selected frame's buffer list. |
|---|
| 95 |
Buffers that were never selected in that frame are listed at the end. |
|---|
| 96 |
If the value is nil, the Buffer Menu uses the global buffer list. |
|---|
| 97 |
This variable matters if the Buffer Menu is sorted by visited order, |
|---|
| 98 |
as it is by default." |
|---|
| 99 |
:type 'boolean |
|---|
| 100 |
:group 'Buffer-menu |
|---|
| 101 |
:version "22.1") |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
(defvar Buffer-menu-sort-column nil |
|---|
| 105 |
"Which column to sort the menu on. |
|---|
| 106 |
Use 2 to sort by buffer names, or 5 to sort by file names. |
|---|
| 107 |
nil means sort by visited order (the default).") |
|---|
| 108 |
|
|---|
| 109 |
(defconst Buffer-menu-buffer-column 4) |
|---|
| 110 |
|
|---|
| 111 |
(defvar Buffer-menu-mode-map nil |
|---|
| 112 |
"Local keymap for `Buffer-menu-mode' buffers.") |
|---|
| 113 |
|
|---|
| 114 |
(defvar Buffer-menu-files-only nil |
|---|
| 115 |
"Non-nil if the current buffer-menu lists only file buffers. |
|---|
| 116 |
This variable determines whether reverting the buffer lists only |
|---|
| 117 |
file buffers. It affects both manual reverting and reverting by |
|---|
| 118 |
Auto Revert Mode.") |
|---|
| 119 |
|
|---|
| 120 |
(defvar Info-current-file) |
|---|
| 121 |
(defvar Info-current-node) |
|---|
| 122 |
|
|---|
| 123 |
(make-variable-buffer-local 'Buffer-menu-files-only) |
|---|
| 124 |
|
|---|
| 125 |
(if Buffer-menu-mode-map |
|---|
| 126 |
() |
|---|
| 127 |
(setq Buffer-menu-mode-map (make-keymap)) |
|---|
| 128 |
(suppress-keymap Buffer-menu-mode-map t) |
|---|
| 129 |
(define-key Buffer-menu-mode-map "q" 'quit-window) |
|---|
| 130 |
(define-key Buffer-menu-mode-map "v" 'Buffer-menu-select) |
|---|
| 131 |
(define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window) |
|---|
| 132 |
(define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window) |
|---|
| 133 |
(define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window) |
|---|
| 134 |
(define-key Buffer-menu-mode-map "e" 'Buffer-menu-this-window) |
|---|
| 135 |
(define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-this-window) |
|---|
| 136 |
(define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window) |
|---|
| 137 |
(define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window) |
|---|
| 138 |
(define-key Buffer-menu-mode-map "s" 'Buffer-menu-save) |
|---|
| 139 |
(define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete) |
|---|
| 140 |
(define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete) |
|---|
| 141 |
(define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards) |
|---|
| 142 |
(define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete) |
|---|
| 143 |
(define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute) |
|---|
| 144 |
(define-key Buffer-menu-mode-map " " 'next-line) |
|---|
| 145 |
(define-key Buffer-menu-mode-map "n" 'next-line) |
|---|
| 146 |
(define-key Buffer-menu-mode-map "p" 'previous-line) |
|---|
| 147 |
(define-key Buffer-menu-mode-map "\177" 'Buffer-menu-backup-unmark) |
|---|
| 148 |
(define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified) |
|---|
| 149 |
(define-key Buffer-menu-mode-map "?" 'describe-mode) |
|---|
| 150 |
(define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark) |
|---|
| 151 |
(define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark) |
|---|
| 152 |
(define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table) |
|---|
| 153 |
(define-key Buffer-menu-mode-map "%" 'Buffer-menu-toggle-read-only) |
|---|
| 154 |
(define-key Buffer-menu-mode-map "b" 'Buffer-menu-bury) |
|---|
| 155 |
(define-key Buffer-menu-mode-map "g" 'Buffer-menu-revert) |
|---|
| 156 |
(define-key Buffer-menu-mode-map "V" 'Buffer-menu-view) |
|---|
| 157 |
(define-key Buffer-menu-mode-map "T" 'Buffer-menu-toggle-files-only) |
|---|
| 158 |
(define-key Buffer-menu-mode-map [mouse-2] 'Buffer-menu-mouse-select) |
|---|
| 159 |
(define-key Buffer-menu-mode-map [follow-link] 'mouse-face) |
|---|
| 160 |
) |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
(put 'Buffer-menu-mode 'mode-class 'special) |
|---|
| 164 |
|
|---|
| 165 |
(defun Buffer-menu-mode () |
|---|
| 166 |
"Major mode for editing a list of buffers. |
|---|
| 167 |
Each line describes one of the buffers in Emacs. |
|---|
| 168 |
Letters do not insert themselves; instead, they are commands. |
|---|
| 169 |
\\<Buffer-menu-mode-map> |
|---|
| 170 |
\\[Buffer-menu-mouse-select] -- select buffer you click on, in place of the buffer menu. |
|---|
| 171 |
\\[Buffer-menu-this-window] -- select current line's buffer in place of the buffer menu. |
|---|
| 172 |
\\[Buffer-menu-other-window] -- select that buffer in another window, |
|---|
| 173 |
so the buffer menu buffer remains visible in its window. |
|---|
| 174 |
\\[Buffer-menu-view] -- select current line's buffer, but in view-mode. |
|---|
| 175 |
\\[Buffer-menu-view-other-window] -- select that buffer in |
|---|
| 176 |
another window, in view-mode. |
|---|
| 177 |
\\[Buffer-menu-switch-other-window] -- make another window display that buffer. |
|---|
| 178 |
\\[Buffer-menu-mark] -- mark current line's buffer to be displayed. |
|---|
| 179 |
\\[Buffer-menu-select] -- select current line's buffer. |
|---|
| 180 |
Also show buffers marked with m, in other windows. |
|---|
| 181 |
\\[Buffer-menu-1-window] -- select that buffer in full-frame window. |
|---|
| 182 |
\\[Buffer-menu-2-window] -- select that buffer in one window, |
|---|
| 183 |
together with buffer selected before this one in another window. |
|---|
| 184 |
\\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer. |
|---|
| 185 |
\\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. |
|---|
| 186 |
\\[Buffer-menu-save] -- mark that buffer to be saved, and move down. |
|---|
| 187 |
\\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down. |
|---|
| 188 |
\\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up. |
|---|
| 189 |
\\[Buffer-menu-execute] -- delete or save marked buffers. |
|---|
| 190 |
\\[Buffer-menu-unmark] -- remove all kinds of marks from current line. |
|---|
| 191 |
With prefix argument, also move up one line. |
|---|
| 192 |
\\[Buffer-menu-backup-unmark] -- back up a line and remove marks. |
|---|
| 193 |
\\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line. |
|---|
| 194 |
\\[Buffer-menu-revert] -- update the list of buffers. |
|---|
| 195 |
\\[Buffer-menu-toggle-files-only] -- toggle whether the menu displays only file buffers. |
|---|
| 196 |
\\[Buffer-menu-bury] -- bury the buffer listed on this line." |
|---|
| 197 |
(kill-all-local-variables) |
|---|
| 198 |
(use-local-map Buffer-menu-mode-map) |
|---|
| 199 |
(setq major-mode 'Buffer-menu-mode) |
|---|
| 200 |
(setq mode-name "Buffer Menu") |
|---|
| 201 |
(set (make-local-variable 'revert-buffer-function) |
|---|
| 202 |
'Buffer-menu-revert-function) |
|---|
| 203 |
(set (make-local-variable 'buffer-stale-function) |
|---|
| 204 |
#'(lambda (&optional noconfirm) 'fast)) |
|---|
| 205 |
(setq truncate-lines t) |
|---|
| 206 |
(setq buffer-read-only t) |
|---|
| 207 |
(run-mode-hooks 'buffer-menu-mode-hook)) |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
(defun Buffer-menu-revert () |
|---|
| 212 |
"Update the list of buffers." |
|---|
| 213 |
(interactive) |
|---|
| 214 |
(revert-buffer)) |
|---|
| 215 |
|
|---|
| 216 |
(defun Buffer-menu-revert-function (ignore1 ignore2) |
|---|
| 217 |
(or (eq buffer-undo-list t) |
|---|
| 218 |
(setq buffer-undo-list nil)) |
|---|
| 219 |
|
|---|
| 220 |
(let ((opoint (point)) |
|---|
| 221 |
(eobp (eobp)) |
|---|
| 222 |
(ocol (current-column)) |
|---|
| 223 |
(oline (progn (move-to-column 4) |
|---|
| 224 |
(get-text-property (point) 'buffer))) |
|---|
| 225 |
(prop (point-min)) |
|---|
| 226 |
|
|---|
| 227 |
(buffer-undo-list t)) |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
(with-current-buffer (window-buffer) |
|---|
| 233 |
(list-buffers-noselect Buffer-menu-files-only)) |
|---|
| 234 |
(if oline |
|---|
| 235 |
(while (setq prop (next-single-property-change prop 'buffer)) |
|---|
| 236 |
(when (eq (get-text-property prop 'buffer) oline) |
|---|
| 237 |
(goto-char prop) |
|---|
| 238 |
(move-to-column ocol))) |
|---|
| 239 |
(goto-char (if eobp (point-max) opoint))))) |
|---|
| 240 |
|
|---|
| 241 |
(defun Buffer-menu-toggle-files-only (arg) |
|---|
| 242 |
"Toggle whether the current buffer-menu displays only file buffers. |
|---|
| 243 |
With a positive ARG display only file buffers. With zero or |
|---|
| 244 |
negative ARG, display other buffers as well." |
|---|
| 245 |
(interactive "P") |
|---|
| 246 |
(setq Buffer-menu-files-only |
|---|
| 247 |
(cond ((not arg) (not Buffer-menu-files-only)) |
|---|
| 248 |
((> (prefix-numeric-value arg) 0) t))) |
|---|
| 249 |
(revert-buffer)) |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
(defun Buffer-menu-buffer (error-if-non-existent-p) |
|---|
| 253 |
"Return buffer described by this line of buffer menu." |
|---|
| 254 |
(let* ((where (save-excursion |
|---|
| 255 |
(beginning-of-line) |
|---|
| 256 |
(+ (point) Buffer-menu-buffer-column))) |
|---|
| 257 |
(name (and (not (eobp)) (get-text-property where 'buffer-name))) |
|---|
| 258 |
(buf (and (not (eobp)) (get-text-property where 'buffer)))) |
|---|
| 259 |
(if name |
|---|
| 260 |
(or (get-buffer name) |
|---|
| 261 |
(and buf (buffer-name buf) buf) |
|---|
| 262 |
(if error-if-non-existent-p |
|---|
| 263 |
(error "No buffer named `%s'" name) |
|---|
| 264 |
nil)) |
|---|
| 265 |
(or (and buf (buffer-name buf) buf) |
|---|
| 266 |
(if error-if-non-existent-p |
|---|
| 267 |
(error "No buffer on this line") |
|---|
| 268 |
nil))))) |
|---|
| 269 |
|
|---|
| 270 |
(defun buffer-menu (&optional arg) |
|---|
| 271 |
"Make a menu of buffers so you can save, delete or select them. |
|---|
| 272 |
With argument, show only buffers that are visiting files. |
|---|
| 273 |
Type ? after invocation to get help on commands available. |
|---|
| 274 |
Type q to remove the buffer menu from the display. |
|---|
| 275 |
|
|---|
| 276 |
The first column shows `>' for a buffer you have |
|---|
| 277 |
marked to be displayed, `D' for one you have marked for |
|---|
| 278 |
deletion, and `.' for the current buffer. |
|---|
| 279 |
|
|---|
| 280 |
The C column has a `.' for the buffer from which you came. |
|---|
| 281 |
The R column has a `%' if the buffer is read-only. |
|---|
| 282 |
The M column has a `*' if it is modified, |
|---|
| 283 |
or `S' if you have marked it for saving. |
|---|
| 284 |
After this come the buffer name, its size in characters, |
|---|
| 285 |
its major mode, and the visited file name (if any)." |
|---|
| 286 |
(interactive "P") |
|---|
| 287 |
|
|---|
| 288 |
(switch-to-buffer (list-buffers-noselect arg)) |
|---|
| 289 |
(message |
|---|
| 290 |
"Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) |
|---|
| 291 |
|
|---|
| 292 |
(defun buffer-menu-other-window (&optional arg) |
|---|
| 293 |
"Display a list of buffers in another window. |
|---|
| 294 |
With the buffer list buffer, you can save, delete or select the buffers. |
|---|
| 295 |
With argument, show only buffers that are visiting files. |
|---|
| 296 |
Type ? after invocation to get help on commands available. |
|---|
| 297 |
Type q to remove the buffer menu from the display. |
|---|
| 298 |
For more information, see the function `buffer-menu'." |
|---|
| 299 |
(interactive "P") |
|---|
| 300 |
|
|---|
| 301 |
(switch-to-buffer-other-window (list-buffers-noselect arg)) |
|---|
| 302 |
(message |
|---|
| 303 |
"Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) |
|---|
| 304 |
|
|---|
| 305 |
(defun Buffer-menu-no-header () |
|---|
| 306 |
(beginning-of-line) |
|---|
| 307 |
(if (or Buffer-menu-use-header-line |
|---|
| 308 |
(not (eq (char-after) ?C))) |
|---|
| 309 |
t |
|---|
| 310 |
(ding) |
|---|
| 311 |
(forward-line 1) |
|---|
| 312 |
nil)) |
|---|
| 313 |
|
|---|
| 314 |
(defun Buffer-menu-mark () |
|---|
| 315 |
"Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command." |
|---|
| 316 |
(interactive) |
|---|
| 317 |
(when (Buffer-menu-no-header) |
|---|
| 318 |
(let ((buffer-read-only nil)) |
|---|
| 319 |
(delete-char 1) |
|---|
| 320 |
(insert ?>) |
|---|
| 321 |
(forward-line 1)))) |
|---|
| 322 |
|
|---|
| 323 |
(defun Buffer-menu-unmark (&optional backup) |
|---|
| 324 |
"Cancel all requested operations on buffer on this line and move down. |
|---|
| 325 |
Optional prefix arg means move up." |
|---|
| 326 |
(interactive "P") |
|---|
| 327 |
(when (Buffer-menu-no-header) |
|---|
| 328 |
(let* ((buf (Buffer-menu-buffer t)) |
|---|
| 329 |
(mod (buffer-modified-p buf)) |
|---|
| 330 |
(readonly (save-excursion (set-buffer buf) buffer-read-only)) |
|---|
| 331 |
(buffer-read-only nil)) |
|---|
| 332 |
(delete-char 3) |
|---|
| 333 |
(insert (if readonly (if mod " %*" " % ") (if mod " *" " "))))) |
|---|
| 334 |
(forward-line (if backup -1 1))) |
|---|
| 335 |
|
|---|
| 336 |
(defun Buffer-menu-backup-unmark () |
|---|
| 337 |
"Move up and cancel all requested operations on buffer on line above." |
|---|
| 338 |
(interactive) |
|---|
| 339 |
(forward-line -1) |
|---|
| 340 |
(Buffer-menu-unmark) |
|---|
| 341 |
(forward-line -1)) |
|---|
| 342 |
|
|---|
| 343 |
(defun Buffer-menu-delete (&optional arg) |
|---|
| 344 |
"Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command. |
|---|
| 345 |
Prefix arg is how many buffers to delete. |
|---|
| 346 |
Negative arg means delete backwards." |
|---|
| 347 |
(interactive "p") |
|---|
| 348 |
(when (Buffer-menu-no-header) |
|---|
| 349 |
(let ((buffer-read-only nil)) |
|---|
| 350 |
(if (or (null arg) (= arg 0)) |
|---|
| 351 |
(setq arg 1)) |
|---|
| 352 |
(while (> arg 0) |
|---|
| 353 |
(delete-char 1) |
|---|
| 354 |
(insert ?D) |
|---|
| 355 |
(forward-line 1) |
|---|
| 356 |
(setq arg (1- arg))) |
|---|
| 357 |
(while (and (< arg 0) |
|---|
| 358 |
(Buffer-menu-no-header)) |
|---|
| 359 |
(delete-char 1) |
|---|
| 360 |
(insert ?D) |
|---|
| 361 |
(forward-line -1) |
|---|
| 362 |
(setq arg (1+ arg)))))) |
|---|
| 363 |
|
|---|
| 364 |
(defun Buffer-menu-delete-backwards (&optional arg) |
|---|
| 365 |
"Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command |
|---|
| 366 |
and then move up one line. Prefix arg means move that many lines." |
|---|
| 367 |
(interactive "p") |
|---|
| 368 |
(Buffer-menu-delete (- (or arg 1)))) |
|---|
| 369 |
|
|---|
| 370 |
(defun Buffer-menu-save () |
|---|
| 371 |
"Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command." |
|---|
| 372 |
(interactive) |
|---|
| 373 |
(when (Buffer-menu-no-header) |
|---|
| 374 |
(let ((buffer-read-only nil)) |
|---|
| 375 |
(forward-char 2) |
|---|
| 376 |
(delete-char 1) |
|---|
| 377 |
(insert ?S) |
|---|
| 378 |
(forward-line 1)))) |
|---|
| 379 |
|
|---|
| 380 |
(defun Buffer-menu-not-modified (&optional arg) |
|---|
| 381 |
"Mark buffer on this line as unmodified (no changes to save)." |
|---|
| 382 |
(interactive "P") |
|---|
| 383 |
(save-excursion |
|---|
| 384 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 385 |
(set-buffer-modified-p arg)) |
|---|
| 386 |
(save-excursion |
|---|
| 387 |
(beginning-of-line) |
|---|
| 388 |
(forward-char 2) |
|---|
| 389 |
(if (= (char-after) (if arg ?\s ?*)) |
|---|
| 390 |
(let ((buffer-read-only nil)) |
|---|
| 391 |
(delete-char 1) |
|---|
| 392 |
(insert (if arg ?* ?\s)))))) |
|---|
| 393 |
|
|---|
| 394 |
(defun Buffer-menu-beginning () |
|---|
| 395 |
(goto-char (point-min)) |
|---|
| 396 |
(unless Buffer-menu-use-header-line |
|---|
| 397 |
(forward-line))) |
|---|
| 398 |
|
|---|
| 399 |
(defun Buffer-menu-execute () |
|---|
| 400 |
"Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands." |
|---|
| 401 |
(interactive) |
|---|
| 402 |
(save-excursion |
|---|
| 403 |
(Buffer-menu-beginning) |
|---|
| 404 |
(while (re-search-forward "^..S" nil t) |
|---|
| 405 |
(let ((modp nil)) |
|---|
| 406 |
(save-excursion |
|---|
| 407 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 408 |
(save-buffer) |
|---|
| 409 |
(setq modp (buffer-modified-p))) |
|---|
| 410 |
(let ((buffer-read-only nil)) |
|---|
| 411 |
(delete-char -1) |
|---|
| 412 |
(insert (if modp ?* ?\s)))))) |
|---|
| 413 |
(save-excursion |
|---|
| 414 |
(Buffer-menu-beginning) |
|---|
| 415 |
(let ((buff-menu-buffer (current-buffer)) |
|---|
| 416 |
(buffer-read-only nil)) |
|---|
| 417 |
(while (re-search-forward "^D" nil t) |
|---|
| 418 |
(forward-char -1) |
|---|
| 419 |
(let ((buf (Buffer-menu-buffer nil))) |
|---|
| 420 |
(or (eq buf nil) |
|---|
| 421 |
(eq buf buff-menu-buffer) |
|---|
| 422 |
(save-excursion (kill-buffer buf))) |
|---|
| 423 |
(if (and buf (buffer-name buf)) |
|---|
| 424 |
(progn (delete-char 1) |
|---|
| 425 |
(insert ?\s)) |
|---|
| 426 |
(delete-region (point) (progn (forward-line 1) (point))) |
|---|
| 427 |
(unless (bobp) |
|---|
| 428 |
(forward-char -1)))))))) |
|---|
| 429 |
|
|---|
| 430 |
(defun Buffer-menu-select () |
|---|
| 431 |
"Select this line's buffer; also display buffers marked with `>'. |
|---|
| 432 |
You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command. |
|---|
| 433 |
This command deletes and replaces all the previously existing windows |
|---|
| 434 |
in the selected frame." |
|---|
| 435 |
(interactive) |
|---|
| 436 |
(let ((buff (Buffer-menu-buffer t)) |
|---|
| 437 |
(menu (current-buffer)) |
|---|
| 438 |
(others ()) |
|---|
| 439 |
tem) |
|---|
| 440 |
(Buffer-menu-beginning) |
|---|
| 441 |
(while (re-search-forward "^>" nil t) |
|---|
| 442 |
(setq tem (Buffer-menu-buffer t)) |
|---|
| 443 |
(let ((buffer-read-only nil)) |
|---|
| 444 |
(delete-char -1) |
|---|
| 445 |
(insert ?\s)) |
|---|
| 446 |
(or (eq tem buff) (memq tem others) (setq others (cons tem others)))) |
|---|
| 447 |
(setq others (nreverse others) |
|---|
| 448 |
tem (/ (1- (frame-height)) (1+ (length others)))) |
|---|
| 449 |
(delete-other-windows) |
|---|
| 450 |
(switch-to-buffer buff) |
|---|
| 451 |
(or (eq menu buff) |
|---|
| 452 |
(bury-buffer menu)) |
|---|
| 453 |
(if (equal (length others) 0) |
|---|
| 454 |
(progn |
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
(switch-to-buffer buff)) |
|---|
| 462 |
(while others |
|---|
| 463 |
(split-window nil tem) |
|---|
| 464 |
(other-window 1) |
|---|
| 465 |
(switch-to-buffer (car others)) |
|---|
| 466 |
(setq others (cdr others))) |
|---|
| 467 |
(other-window 1) |
|---|
| 468 |
))) |
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
(defun Buffer-menu-visit-tags-table () |
|---|
| 473 |
"Visit the tags table in the buffer on this line. See `visit-tags-table'." |
|---|
| 474 |
(interactive) |
|---|
| 475 |
(let ((file (buffer-file-name (Buffer-menu-buffer t)))) |
|---|
| 476 |
(if file |
|---|
| 477 |
(visit-tags-table file) |
|---|
| 478 |
(error "Specified buffer has no file")))) |
|---|
| 479 |
|
|---|
| 480 |
(defun Buffer-menu-1-window () |
|---|
| 481 |
"Select this line's buffer, alone, in full frame." |
|---|
| 482 |
(interactive) |
|---|
| 483 |
(switch-to-buffer (Buffer-menu-buffer t)) |
|---|
| 484 |
(bury-buffer (other-buffer)) |
|---|
| 485 |
(delete-other-windows)) |
|---|
| 486 |
|
|---|
| 487 |
(defun Buffer-menu-mouse-select (event) |
|---|
| 488 |
"Select the buffer whose line you click on." |
|---|
| 489 |
(interactive "e") |
|---|
| 490 |
(let (buffer) |
|---|
| 491 |
(save-excursion |
|---|
| 492 |
(set-buffer (window-buffer (posn-window (event-end event)))) |
|---|
| 493 |
(save-excursion |
|---|
| 494 |
(goto-char (posn-point (event-end event))) |
|---|
| 495 |
(setq buffer (Buffer-menu-buffer t)))) |
|---|
| 496 |
(select-window (posn-window (event-end event))) |
|---|
| 497 |
(if (and (window-dedicated-p (selected-window)) |
|---|
| 498 |
(eq (selected-window) (frame-root-window))) |
|---|
| 499 |
(switch-to-buffer-other-frame buffer) |
|---|
| 500 |
(switch-to-buffer buffer)))) |
|---|
| 501 |
|
|---|
| 502 |
(defun Buffer-menu-this-window () |
|---|
| 503 |
"Select this line's buffer in this window." |
|---|
| 504 |
(interactive) |
|---|
| 505 |
(switch-to-buffer (Buffer-menu-buffer t))) |
|---|
| 506 |
|
|---|
| 507 |
(defun Buffer-menu-other-window () |
|---|
| 508 |
"Select this line's buffer in other window, leaving buffer menu visible." |
|---|
| 509 |
(interactive) |
|---|
| 510 |
(switch-to-buffer-other-window (Buffer-menu-buffer t))) |
|---|
| 511 |
|
|---|
| 512 |
(defun Buffer-menu-switch-other-window () |
|---|
| 513 |
"Make the other window select this line's buffer. |
|---|
| 514 |
The current window remains selected." |
|---|
| 515 |
(interactive) |
|---|
| 516 |
(let ((pop-up-windows t) |
|---|
| 517 |
same-window-buffer-names |
|---|
| 518 |
same-window-regexps) |
|---|
| 519 |
(display-buffer (Buffer-menu-buffer t)))) |
|---|
| 520 |
|
|---|
| 521 |
(defun Buffer-menu-2-window () |
|---|
| 522 |
"Select this line's buffer, with previous buffer in second window." |
|---|
| 523 |
(interactive) |
|---|
| 524 |
(let ((buff (Buffer-menu-buffer t)) |
|---|
| 525 |
(menu (current-buffer)) |
|---|
| 526 |
(pop-up-windows t) |
|---|
| 527 |
same-window-buffer-names |
|---|
| 528 |
same-window-regexps) |
|---|
| 529 |
(delete-other-windows) |
|---|
| 530 |
(switch-to-buffer (other-buffer)) |
|---|
| 531 |
(pop-to-buffer buff) |
|---|
| 532 |
(bury-buffer menu))) |
|---|
| 533 |
|
|---|
| 534 |
(defun Buffer-menu-toggle-read-only () |
|---|
| 535 |
"Toggle read-only status of buffer on this line, perhaps via version control." |
|---|
| 536 |
(interactive) |
|---|
| 537 |
(let (char) |
|---|
| 538 |
(save-excursion |
|---|
| 539 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 540 |
(vc-toggle-read-only) |
|---|
| 541 |
(setq char (if buffer-read-only ?% ?\s))) |
|---|
| 542 |
(save-excursion |
|---|
| 543 |
(beginning-of-line) |
|---|
| 544 |
(forward-char 1) |
|---|
| 545 |
(if (/= (following-char) char) |
|---|
| 546 |
(let (buffer-read-only) |
|---|
| 547 |
(delete-char 1) |
|---|
| 548 |
(insert char)))))) |
|---|
| 549 |
|
|---|
| 550 |
(defun Buffer-menu-bury () |
|---|
| 551 |
"Bury the buffer listed on this line." |
|---|
| 552 |
(interactive) |
|---|
| 553 |
(when (Buffer-menu-no-header) |
|---|
| 554 |
(save-excursion |
|---|
| 555 |
(beginning-of-line) |
|---|
| 556 |
(bury-buffer (Buffer-menu-buffer t)) |
|---|
| 557 |
(let ((line (buffer-substring (point) (progn (forward-line 1) (point)))) |
|---|
| 558 |
(buffer-read-only nil)) |
|---|
| 559 |
(delete-region (point) (progn (forward-line -1) (point))) |
|---|
| 560 |
(goto-char (point-max)) |
|---|
| 561 |
(insert line)) |
|---|
| 562 |
(message "Buried buffer moved to the end")))) |
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
(defun Buffer-menu-view () |
|---|
| 566 |
"View this line's buffer in View mode." |
|---|
| 567 |
(interactive) |
|---|
| 568 |
(view-buffer (Buffer-menu-buffer t))) |
|---|
| 569 |
|
|---|
| 570 |
|
|---|
| 571 |
(defun Buffer-menu-view-other-window () |
|---|
| 572 |
"View this line's buffer in View mode in another window." |
|---|
| 573 |
(interactive) |
|---|
| 574 |
(view-buffer-other-window (Buffer-menu-buffer t))) |
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
(define-key ctl-x-map "\C-b" 'list-buffers) |
|---|
| 578 |
|
|---|
| 579 |
(defun list-buffers (&optional files-only) |
|---|
| 580 |
"Display a list of names of existing buffers. |
|---|
| 581 |
The list is displayed in a buffer named `*Buffer List*'. |
|---|
| 582 |
Note that buffers with names starting with spaces are omitted. |
|---|
| 583 |
Non-null optional arg FILES-ONLY means mention only file buffers. |
|---|
| 584 |
|
|---|
| 585 |
For more information, see the function `buffer-menu'." |
|---|
| 586 |
(interactive "P") |
|---|
| 587 |
(display-buffer (list-buffers-noselect files-only))) |
|---|
| 588 |
|
|---|
| 589 |
(defun Buffer-menu-buffer+size (name size &optional name-props size-props) |
|---|
| 590 |
(if (> (+ (length name) (length size) 2) Buffer-menu-buffer+size-width) |
|---|
| 591 |
(setq name |
|---|
| 592 |
(if (string-match "<[0-9]+>$" name) |
|---|
| 593 |
(concat (substring name 0 |
|---|
| 594 |
(- Buffer-menu-buffer+size-width |
|---|
| 595 |
(max (length size) 3) |
|---|
| 596 |
(match-end 0) |
|---|
| 597 |
(- (match-beginning 0)) |
|---|
| 598 |
2)) |
|---|
| 599 |
":" |
|---|
| 600 |
(match-string 0 name)) |
|---|
| 601 |
(concat (substring name 0 |
|---|
| 602 |
(- Buffer-menu-buffer+size-width |
|---|
| 603 |
(max (length size) 3) |
|---|
| 604 |
2)) |
|---|
| 605 |
":"))) |
|---|
| 606 |
|
|---|
| 607 |
(setq name (copy-sequence name))) |
|---|
| 608 |
(add-text-properties 0 (length name) name-props name) |
|---|
| 609 |
(add-text-properties 0 (length size) size-props size) |
|---|
| 610 |
(concat name |
|---|
| 611 |
(make-string (- Buffer-menu-buffer+size-width |
|---|
| 612 |
(length name) |
|---|
| 613 |
(length size)) |
|---|
| 614 |
?\s) |
|---|
| 615 |
size)) |
|---|
| 616 |
|
|---|
| 617 |
(defun Buffer-menu-sort (column) |
|---|
| 618 |
"Sort the buffer menu by COLUMN." |
|---|
| 619 |
(interactive "P") |
|---|
| 620 |
(when column |
|---|
| 621 |
(setq column (prefix-numeric-value column)) |
|---|
| 622 |
(if (< column 2) (setq column 2)) |
|---|
| 623 |
(if (> column 5) (setq column 5))) |
|---|
| 624 |
(setq Buffer-menu-sort-column column) |
|---|
| 625 |
(let (buffer-read-only l buf m1 m2) |
|---|
| 626 |
(save-excursion |
|---|
| 627 |
(Buffer-menu-beginning) |
|---|
| 628 |
(while (not (eobp)) |
|---|
| 629 |
(when (buffer-live-p (setq buf (get-text-property (+ (point) 4) 'buffer))) |
|---|
| 630 |
(setq m1 (char-after) |
|---|
| 631 |
m1 (if (memq m1 '(?> ?D)) m1) |
|---|
| 632 |
m2 (char-after (+ (point) 2)) |
|---|
| 633 |
m2 (if (eq m2 ?S) m2)) |
|---|
| 634 |
(if (or m1 m2) |
|---|
| 635 |
(push (list buf m1 m2) l))) |
|---|
| 636 |
(forward-line))) |
|---|
| 637 |
(Buffer-menu-revert) |
|---|
| 638 |
(setq buffer-read-only) |
|---|
| 639 |
(save-excursion |
|---|
| 640 |
(Buffer-menu-beginning) |
|---|
| 641 |
(while (not (eobp)) |
|---|
| 642 |
(when (setq buf (assq (get-text-property (+ (point) 4) 'buffer) l)) |
|---|
| 643 |
(setq m1 (cadr buf) |
|---|
| 644 |
m2 (cadr (cdr buf))) |
|---|
| 645 |
(when m1 |
|---|
| 646 |
(delete-char 1) |
|---|
| 647 |
(insert m1) |
|---|
| 648 |
(backward-char 1)) |
|---|
| 649 |
(when m2 |
|---|
| 650 |
(forward-char 2) |
|---|
| 651 |
(delete-char 1) |
|---|
| 652 |
(insert m2))) |
|---|
| 653 |
(forward-line))))) |
|---|
| 654 |
|
|---|
| 655 |
(defun Buffer-menu-sort-by-column (&optional e) |
|---|
| 656 |
"Sort the buffer menu by the column clicked on." |
|---|
| 657 |
(interactive (list last-input-event)) |
|---|
| 658 |
(if e (mouse-select-window e)) |
|---|
| 659 |
(let* ((pos (event-start e)) |
|---|
| 660 |
(obj (posn-object pos)) |
|---|
| 661 |
(col (if obj |
|---|
| 662 |
(get-text-property (cdr obj) 'column (car obj)) |
|---|
| 663 |
(get-text-property (posn-point pos) 'column)))) |
|---|
| 664 |
(Buffer-menu-sort col))) |
|---|
| 665 |
|
|---|
| 666 |
(defvar Buffer-menu-sort-button-map |
|---|
| 667 |
(let ((map (make-sparse-keymap))) |
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
(define-key map [header-line mouse-1] 'Buffer-menu-sort-by-column) |
|---|
| 671 |
(define-key map [header-line mouse-2] 'Buffer-menu-sort-by-column) |
|---|
| 672 |
(define-key map [mouse-2] 'Buffer-menu-sort-by-column) |
|---|
| 673 |
(define-key map [follow-link] 'mouse-face) |
|---|
| 674 |
(define-key map "\C-m" 'Buffer-menu-sort-by-column) |
|---|
| 675 |
map) |
|---|
| 676 |
"Local keymap for Buffer menu sort buttons.") |
|---|
| 677 |
|
|---|
| 678 |
(defun Buffer-menu-make-sort-button (name column) |
|---|
| 679 |
(if (equal column Buffer-menu-sort-column) (setq column nil)) |
|---|
| 680 |
(propertize name |
|---|
| 681 |
'column column |
|---|
| 682 |
'help-echo (concat |
|---|
| 683 |
(if Buffer-menu-use-header-line |
|---|
| 684 |
"mouse-1, mouse-2: sort by " |
|---|
| 685 |
"mouse-2, RET: sort by ") |
|---|
| 686 |
(if column (downcase name) "visited order")) |
|---|
| 687 |
'mouse-face 'highlight |
|---|
| 688 |
'keymap Buffer-menu-sort-button-map)) |
|---|
| 689 |
|
|---|
| 690 |
(defun list-buffers-noselect (&optional files-only buffer-list) |
|---|
| 691 |
"Create and return a buffer with a list of names of existing buffers. |
|---|
| 692 |
The buffer is named `*Buffer List*'. |
|---|
| 693 |
Note that buffers with names starting with spaces are omitted. |
|---|
| 694 |
Non-null optional arg FILES-ONLY means mention only file buffers. |
|---|
| 695 |
|
|---|
| 696 |
If BUFFER-LIST is non-nil, it should be a list of buffers; |
|---|
| 697 |
it means list those buffers and no others. |
|---|
| 698 |
|
|---|
| 699 |
For more information, see the function `buffer-menu'." |
|---|
| 700 |
(let* ((old-buffer (current-buffer)) |
|---|
| 701 |
(standard-output standard-output) |
|---|
| 702 |
(mode-end (make-string (- Buffer-menu-mode-width 2) ?\s)) |
|---|
| 703 |
(header (concat "CRM " |
|---|
| 704 |
(Buffer-menu-buffer+size |
|---|
| 705 |
(Buffer-menu-make-sort-button "Buffer" 2) |
|---|
| 706 |
(Buffer-menu-make-sort-button "Size" 3)) |
|---|
| 707 |
" " |
|---|
| 708 |
(Buffer-menu-make-sort-button "Mode" 4) mode-end |
|---|
| 709 |
(Buffer-menu-make-sort-button "File" 5) "\n")) |
|---|
| 710 |
list desired-point) |
|---|
| 711 |
(when Buffer-menu-use-header-line |
|---|
| 712 |
(let ((pos 0)) |
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
(while (string-match "[ \t\n]+" header pos) |
|---|
| 716 |
(setq pos (match-end 0)) |
|---|
| 717 |
(put-text-property (match-beginning 0) pos 'display |
|---|
| 718 |
|
|---|
| 719 |
(list 'space :align-to pos) |
|---|
| 720 |
header))) |
|---|
| 721 |
|
|---|
| 722 |
(put-text-property 0 3 'face 'fixed-pitch header) |
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
(setq header (concat (propertize " " 'display '(space :align-to 0)) |
|---|
| 727 |
header))) |
|---|
| 728 |
(with-current-buffer (get-buffer-create "*Buffer List*") |
|---|
| 729 |
(setq buffer-read-only nil) |
|---|
| 730 |
(erase-buffer) |
|---|
| 731 |
(setq standard-output (current-buffer)) |
|---|
| 732 |
(unless Buffer-menu-use-header-line |
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
(let ((underline (if (char-displayable-p ?\u2014) ?\u2014 ?-))) |
|---|
| 736 |
(insert header |
|---|
| 737 |
(apply 'string |
|---|
| 738 |
(mapcar (lambda (c) |
|---|
| 739 |
(if (memq c '(?\n ?\s)) c underline)) |
|---|
| 740 |
header))))) |
|---|
| 741 |
|
|---|
| 742 |
(dolist (buffer (or buffer-list |
|---|
| 743 |
(buffer-list |
|---|
| 744 |
(when Buffer-menu-use-frame-buffer-list |
|---|
| 745 |
(selected-frame))))) |
|---|
| 746 |
(with-current-buffer buffer |
|---|
| 747 |
(let ((name (buffer-name)) |
|---|
| 748 |
(file buffer-file-name)) |
|---|
| 749 |
(unless (and (not buffer-list) |
|---|
| 750 |
(or |
|---|
| 751 |
|
|---|
| 752 |
(and (string= (substring name 0 1) " ") (null file)) |
|---|
| 753 |
|
|---|
| 754 |
(and files-only (not file)) |
|---|
| 755 |
(string= name "*Buffer List*"))) |
|---|
| 756 |
|
|---|
| 757 |
(let ((mode (concat (format-mode-line mode-name nil nil buffer) |
|---|
| 758 |
(if mode-line-process |
|---|
| 759 |
(format-mode-line mode-line-process |
|---|
| 760 |
nil nil buffer)))) |
|---|
| 761 |
(bits (string |
|---|
| 762 |
(if (eq buffer old-buffer) ?. ?\s) |
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
(if (or (eq buffer standard-output) |
|---|
| 767 |
buffer-read-only) |
|---|
| 768 |
?% ?\s) |
|---|
| 769 |
|
|---|
| 770 |
(if (buffer-modified-p) ?* ?\s) |
|---|
| 771 |
|
|---|
| 772 |
?\s))) |
|---|
| 773 |
(unless file |
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
(cond ((and (boundp 'list-buffers-directory) |
|---|
| 778 |
list-buffers-directory) |
|---|
| 779 |
(setq file list-buffers-directory)) |
|---|
| 780 |
((eq major-mode 'Info-mode) |
|---|
| 781 |
(setq file Info-current-file) |
|---|
| 782 |
(cond |
|---|
| 783 |
((equal file "dir") |
|---|
| 784 |
(setq file "*Info Directory*")) |
|---|
| 785 |
((eq file 'apropos) |
|---|
| 786 |
(setq file "*Info Apropos*")) |
|---|
| 787 |
((eq file 'history) |
|---|
| 788 |
(setq file "*Info History*")) |
|---|
| 789 |
((eq file 'toc) |
|---|
| 790 |
(setq file "*Info TOC*")) |
|---|
| 791 |
((not (stringp file)) |
|---|
| 792 |
(setq file nil)) |
|---|
| 793 |
(t |
|---|
| 794 |
(setq file (concat "(" |
|---|
| 795 |
(file-name-nondirectory file) |
|---|
| 796 |
")" |
|---|
| 797 |
Info-current-node))))))) |
|---|
| 798 |
(push (list buffer bits name (buffer-size) mode file) |
|---|
| 799 |
list)))))) |
|---|
| 800 |
|
|---|
| 801 |
(setq list (nreverse list)) |
|---|
| 802 |
|
|---|
| 803 |
(dolist (buffer |
|---|
| 804 |
(if Buffer-menu-sort-column |
|---|
| 805 |
(sort list |
|---|
| 806 |
(if (eq Buffer-menu-sort-column 3) |
|---|
| 807 |
(lambda (a b) |
|---|
| 808 |
(< (nth Buffer-menu-sort-column a) |
|---|
| 809 |
(nth Buffer-menu-sort-column b))) |
|---|
| 810 |
(lambda (a b) |
|---|
| 811 |
(string< (nth Buffer-menu-sort-column a) |
|---|
| 812 |
(nth Buffer-menu-sort-column b))))) |
|---|
| 813 |
list)) |
|---|
| 814 |
(if (eq (car buffer) old-buffer) |
|---|
| 815 |
(setq desired-point (point))) |
|---|
| 816 |
(insert (cadr buffer) |
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
(Buffer-menu-buffer+size (nth 2 buffer) |
|---|
| 821 |
(int-to-string (nth 3 buffer)) |
|---|
| 822 |
`(buffer-name ,(nth 2 buffer) |
|---|
| 823 |
buffer ,(car buffer) |
|---|
| 824 |
  |
|---|