| 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 |
(defvar Buffer-menu-buffer-column nil) |
|---|
| 68 |
|
|---|
| 69 |
(defvar Buffer-menu-mode-map nil "") |
|---|
| 70 |
|
|---|
| 71 |
(if Buffer-menu-mode-map |
|---|
| 72 |
() |
|---|
| 73 |
(setq Buffer-menu-mode-map (make-keymap)) |
|---|
| 74 |
(suppress-keymap Buffer-menu-mode-map t) |
|---|
| 75 |
(define-key Buffer-menu-mode-map "q" 'quit-window) |
|---|
| 76 |
(define-key Buffer-menu-mode-map "v" 'Buffer-menu-select) |
|---|
| 77 |
(define-key Buffer-menu-mode-map "2" 'Buffer-menu-2-window) |
|---|
| 78 |
(define-key Buffer-menu-mode-map "1" 'Buffer-menu-1-window) |
|---|
| 79 |
(define-key Buffer-menu-mode-map "f" 'Buffer-menu-this-window) |
|---|
| 80 |
(define-key Buffer-menu-mode-map "e" 'Buffer-menu-this-window) |
|---|
| 81 |
(define-key Buffer-menu-mode-map "\C-m" 'Buffer-menu-this-window) |
|---|
| 82 |
(define-key Buffer-menu-mode-map "o" 'Buffer-menu-other-window) |
|---|
| 83 |
(define-key Buffer-menu-mode-map "\C-o" 'Buffer-menu-switch-other-window) |
|---|
| 84 |
(define-key Buffer-menu-mode-map "s" 'Buffer-menu-save) |
|---|
| 85 |
(define-key Buffer-menu-mode-map "d" 'Buffer-menu-delete) |
|---|
| 86 |
(define-key Buffer-menu-mode-map "k" 'Buffer-menu-delete) |
|---|
| 87 |
(define-key Buffer-menu-mode-map "\C-d" 'Buffer-menu-delete-backwards) |
|---|
| 88 |
(define-key Buffer-menu-mode-map "\C-k" 'Buffer-menu-delete) |
|---|
| 89 |
(define-key Buffer-menu-mode-map "x" 'Buffer-menu-execute) |
|---|
| 90 |
(define-key Buffer-menu-mode-map " " 'next-line) |
|---|
| 91 |
(define-key Buffer-menu-mode-map "n" 'next-line) |
|---|
| 92 |
(define-key Buffer-menu-mode-map "p" 'previous-line) |
|---|
| 93 |
(define-key Buffer-menu-mode-map "\177" 'Buffer-menu-backup-unmark) |
|---|
| 94 |
(define-key Buffer-menu-mode-map "~" 'Buffer-menu-not-modified) |
|---|
| 95 |
(define-key Buffer-menu-mode-map "?" 'describe-mode) |
|---|
| 96 |
(define-key Buffer-menu-mode-map "u" 'Buffer-menu-unmark) |
|---|
| 97 |
(define-key Buffer-menu-mode-map "m" 'Buffer-menu-mark) |
|---|
| 98 |
(define-key Buffer-menu-mode-map "t" 'Buffer-menu-visit-tags-table) |
|---|
| 99 |
(define-key Buffer-menu-mode-map "%" 'Buffer-menu-toggle-read-only) |
|---|
| 100 |
(define-key Buffer-menu-mode-map "b" 'Buffer-menu-bury) |
|---|
| 101 |
(define-key Buffer-menu-mode-map "g" 'Buffer-menu-revert) |
|---|
| 102 |
(define-key Buffer-menu-mode-map "V" 'Buffer-menu-view) |
|---|
| 103 |
(define-key Buffer-menu-mode-map [mouse-2] 'Buffer-menu-mouse-select) |
|---|
| 104 |
) |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
(put 'Buffer-menu-mode 'mode-class 'special) |
|---|
| 108 |
|
|---|
| 109 |
(defun Buffer-menu-mode () |
|---|
| 110 |
"Major mode for editing a list of buffers. |
|---|
| 111 |
Each line describes one of the buffers in Emacs. |
|---|
| 112 |
Letters do not insert themselves; instead, they are commands. |
|---|
| 113 |
\\<Buffer-menu-mode-map> |
|---|
| 114 |
\\[Buffer-menu-mouse-select] -- select buffer you click on, in place of the buffer menu. |
|---|
| 115 |
\\[Buffer-menu-this-window] -- select current line's buffer in place of the buffer menu. |
|---|
| 116 |
\\[Buffer-menu-other-window] -- select that buffer in another window, |
|---|
| 117 |
so the buffer menu buffer remains visible in its window. |
|---|
| 118 |
\\[Buffer-menu-view] -- select current line's buffer, but in view-mode. |
|---|
| 119 |
\\[Buffer-menu-view-other-window] -- select that buffer in |
|---|
| 120 |
another window, in view-mode. |
|---|
| 121 |
\\[Buffer-menu-switch-other-window] -- make another window display that buffer. |
|---|
| 122 |
\\[Buffer-menu-mark] -- mark current line's buffer to be displayed. |
|---|
| 123 |
\\[Buffer-menu-select] -- select current line's buffer. |
|---|
| 124 |
Also show buffers marked with m, in other windows. |
|---|
| 125 |
\\[Buffer-menu-1-window] -- select that buffer in full-frame window. |
|---|
| 126 |
\\[Buffer-menu-2-window] -- select that buffer in one window, |
|---|
| 127 |
together with buffer selected before this one in another window. |
|---|
| 128 |
\\[Buffer-menu-visit-tags-table] -- visit-tags-table this buffer. |
|---|
| 129 |
\\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. |
|---|
| 130 |
\\[Buffer-menu-save] -- mark that buffer to be saved, and move down. |
|---|
| 131 |
\\[Buffer-menu-delete] -- mark that buffer to be deleted, and move down. |
|---|
| 132 |
\\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted, and move up. |
|---|
| 133 |
\\[Buffer-menu-execute] -- delete or save marked buffers. |
|---|
| 134 |
\\[Buffer-menu-unmark] -- remove all kinds of marks from current line. |
|---|
| 135 |
With prefix argument, also move up one line. |
|---|
| 136 |
\\[Buffer-menu-backup-unmark] -- back up a line and remove marks. |
|---|
| 137 |
\\[Buffer-menu-toggle-read-only] -- toggle read-only status of buffer on this line. |
|---|
| 138 |
\\[Buffer-menu-revert] -- update the list of buffers. |
|---|
| 139 |
\\[Buffer-menu-bury] -- bury the buffer listed on this line." |
|---|
| 140 |
(kill-all-local-variables) |
|---|
| 141 |
(use-local-map Buffer-menu-mode-map) |
|---|
| 142 |
(setq major-mode 'Buffer-menu-mode) |
|---|
| 143 |
(setq mode-name "Buffer Menu") |
|---|
| 144 |
(make-local-variable 'revert-buffer-function) |
|---|
| 145 |
(setq revert-buffer-function 'Buffer-menu-revert-function) |
|---|
| 146 |
(setq truncate-lines t) |
|---|
| 147 |
(setq buffer-read-only t) |
|---|
| 148 |
(run-hooks 'buffer-menu-mode-hook)) |
|---|
| 149 |
|
|---|
| 150 |
(defun Buffer-menu-revert () |
|---|
| 151 |
"Update the list of buffers." |
|---|
| 152 |
(interactive) |
|---|
| 153 |
(revert-buffer)) |
|---|
| 154 |
|
|---|
| 155 |
(defun Buffer-menu-revert-function (ignore1 ignore2) |
|---|
| 156 |
(list-buffers)) |
|---|
| 157 |
|
|---|
| 158 |
(defun Buffer-menu-buffer (error-if-non-existent-p) |
|---|
| 159 |
"Return buffer described by this line of buffer menu." |
|---|
| 160 |
(let* ((where (save-excursion |
|---|
| 161 |
(beginning-of-line) |
|---|
| 162 |
(+ (point) Buffer-menu-buffer-column))) |
|---|
| 163 |
(name (and (not (eobp)) (get-text-property where 'buffer-name))) |
|---|
| 164 |
(buf (and (not (eobp)) (get-text-property where 'buffer)))) |
|---|
| 165 |
(if name |
|---|
| 166 |
(or (get-buffer name) |
|---|
| 167 |
(and buf (buffer-name buf) buf) |
|---|
| 168 |
(if error-if-non-existent-p |
|---|
| 169 |
(error "No buffer named `%s'" name) |
|---|
| 170 |
nil)) |
|---|
| 171 |
(or (and buf (buffer-name buf) buf) |
|---|
| 172 |
(if error-if-non-existent-p |
|---|
| 173 |
(error "No buffer on this line") |
|---|
| 174 |
nil))))) |
|---|
| 175 |
|
|---|
| 176 |
(defun buffer-menu (&optional arg) |
|---|
| 177 |
"Make a menu of buffers so you can save, delete or select them. |
|---|
| 178 |
With argument, show only buffers that are visiting files. |
|---|
| 179 |
Type ? after invocation to get help on commands available. |
|---|
| 180 |
Type q immediately to make the buffer menu go away." |
|---|
| 181 |
(interactive "P") |
|---|
| 182 |
|
|---|
| 183 |
(switch-to-buffer (list-buffers-noselect arg)) |
|---|
| 184 |
(message |
|---|
| 185 |
"Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) |
|---|
| 186 |
|
|---|
| 187 |
(defun buffer-menu-other-window (&optional arg) |
|---|
| 188 |
"Display a list of buffers in another window. |
|---|
| 189 |
With the buffer list buffer, you can save, delete or select the buffers. |
|---|
| 190 |
With argument, show only buffers that are visiting files. |
|---|
| 191 |
Type ? after invocation to get help on commands available. |
|---|
| 192 |
Type q immediately to make the buffer menu go away." |
|---|
| 193 |
(interactive "P") |
|---|
| 194 |
|
|---|
| 195 |
(switch-to-buffer-other-window (list-buffers-noselect arg)) |
|---|
| 196 |
(message |
|---|
| 197 |
"Commands: d, s, x, u; f, o, 1, 2, m, v; ~, %%; q to quit; ? for help.")) |
|---|
| 198 |
|
|---|
| 199 |
(defun Buffer-menu-mark () |
|---|
| 200 |
"Mark buffer on this line for being displayed by \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command." |
|---|
| 201 |
(interactive) |
|---|
| 202 |
(beginning-of-line) |
|---|
| 203 |
(if (looking-at " [-M]") |
|---|
| 204 |
(ding) |
|---|
| 205 |
(let ((buffer-read-only nil)) |
|---|
| 206 |
(delete-char 1) |
|---|
| 207 |
(insert ?>) |
|---|
| 208 |
(forward-line 1)))) |
|---|
| 209 |
|
|---|
| 210 |
(defun Buffer-menu-unmark (&optional backup) |
|---|
| 211 |
"Cancel all requested operations on buffer on this line and move down. |
|---|
| 212 |
Optional ARG means move up." |
|---|
| 213 |
(interactive "P") |
|---|
| 214 |
(beginning-of-line) |
|---|
| 215 |
(if (looking-at " [-M]") |
|---|
| 216 |
(ding) |
|---|
| 217 |
(let* ((buf (Buffer-menu-buffer t)) |
|---|
| 218 |
(mod (buffer-modified-p buf)) |
|---|
| 219 |
(readonly (save-excursion (set-buffer buf) buffer-read-only)) |
|---|
| 220 |
(buffer-read-only nil)) |
|---|
| 221 |
(delete-char 3) |
|---|
| 222 |
(insert (if readonly (if mod " *%" " %") (if mod " * " " "))))) |
|---|
| 223 |
(forward-line (if backup -1 1))) |
|---|
| 224 |
|
|---|
| 225 |
(defun Buffer-menu-backup-unmark () |
|---|
| 226 |
"Move up and cancel all requested operations on buffer on line above." |
|---|
| 227 |
(interactive) |
|---|
| 228 |
(forward-line -1) |
|---|
| 229 |
(Buffer-menu-unmark) |
|---|
| 230 |
(forward-line -1)) |
|---|
| 231 |
|
|---|
| 232 |
(defun Buffer-menu-delete (&optional arg) |
|---|
| 233 |
"Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command. |
|---|
| 234 |
Prefix arg is how many buffers to delete. |
|---|
| 235 |
Negative arg means delete backwards." |
|---|
| 236 |
(interactive "p") |
|---|
| 237 |
(beginning-of-line) |
|---|
| 238 |
(if (looking-at " [-M]") |
|---|
| 239 |
(ding) |
|---|
| 240 |
(let ((buffer-read-only nil)) |
|---|
| 241 |
(if (or (null arg) (= arg 0)) |
|---|
| 242 |
(setq arg 1)) |
|---|
| 243 |
(while (> arg 0) |
|---|
| 244 |
(delete-char 1) |
|---|
| 245 |
(insert ?D) |
|---|
| 246 |
(forward-line 1) |
|---|
| 247 |
(setq arg (1- arg))) |
|---|
| 248 |
(while (< arg 0) |
|---|
| 249 |
(delete-char 1) |
|---|
| 250 |
(insert ?D) |
|---|
| 251 |
(forward-line -1) |
|---|
| 252 |
(setq arg (1+ arg)))))) |
|---|
| 253 |
|
|---|
| 254 |
(defun Buffer-menu-delete-backwards (&optional arg) |
|---|
| 255 |
"Mark buffer on this line to be deleted by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command |
|---|
| 256 |
and then move up one line. Prefix arg means move that many lines." |
|---|
| 257 |
(interactive "p") |
|---|
| 258 |
(Buffer-menu-delete (- (or arg 1))) |
|---|
| 259 |
(while (looking-at " [-M]") |
|---|
| 260 |
(forward-line 1))) |
|---|
| 261 |
|
|---|
| 262 |
(defun Buffer-menu-save () |
|---|
| 263 |
"Mark buffer on this line to be saved by \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command." |
|---|
| 264 |
(interactive) |
|---|
| 265 |
(beginning-of-line) |
|---|
| 266 |
(if (looking-at " [-M]") |
|---|
| 267 |
(ding) |
|---|
| 268 |
(let ((buffer-read-only nil)) |
|---|
| 269 |
(forward-char 1) |
|---|
| 270 |
(delete-char 1) |
|---|
| 271 |
(insert ?S) |
|---|
| 272 |
(forward-line 1)))) |
|---|
| 273 |
|
|---|
| 274 |
(defun Buffer-menu-not-modified (&optional arg) |
|---|
| 275 |
"Mark buffer on this line as unmodified (no changes to save)." |
|---|
| 276 |
(interactive "P") |
|---|
| 277 |
(save-excursion |
|---|
| 278 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 279 |
(set-buffer-modified-p arg)) |
|---|
| 280 |
(save-excursion |
|---|
| 281 |
(beginning-of-line) |
|---|
| 282 |
(forward-char 1) |
|---|
| 283 |
(if (= (char-after (point)) (if arg ? ?*)) |
|---|
| 284 |
(let ((buffer-read-only nil)) |
|---|
| 285 |
(delete-char 1) |
|---|
| 286 |
(insert (if arg ?* ? )))))) |
|---|
| 287 |
|
|---|
| 288 |
(defun Buffer-menu-execute () |
|---|
| 289 |
"Save and/or delete buffers marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-save] or \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands." |
|---|
| 290 |
(interactive) |
|---|
| 291 |
(save-excursion |
|---|
| 292 |
(goto-char (point-min)) |
|---|
| 293 |
(forward-line 1) |
|---|
| 294 |
(while (re-search-forward "^.S" nil t) |
|---|
| 295 |
(let ((modp nil)) |
|---|
| 296 |
(save-excursion |
|---|
| 297 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 298 |
(save-buffer) |
|---|
| 299 |
(setq modp (buffer-modified-p))) |
|---|
| 300 |
(let ((buffer-read-only nil)) |
|---|
| 301 |
(delete-char -1) |
|---|
| 302 |
(insert (if modp ?* ? )))))) |
|---|
| 303 |
(save-excursion |
|---|
| 304 |
(goto-char (point-min)) |
|---|
| 305 |
(forward-line 1) |
|---|
| 306 |
(let ((buff-menu-buffer (current-buffer)) |
|---|
| 307 |
(buffer-read-only nil)) |
|---|
| 308 |
(while (search-forward "\nD" nil t) |
|---|
| 309 |
(forward-char -1) |
|---|
| 310 |
(let ((buf (Buffer-menu-buffer nil))) |
|---|
| 311 |
(or (eq buf nil) |
|---|
| 312 |
(eq buf buff-menu-buffer) |
|---|
| 313 |
(save-excursion (kill-buffer buf))) |
|---|
| 314 |
(if (and buf (buffer-name buf)) |
|---|
| 315 |
(progn (delete-char 1) |
|---|
| 316 |
(insert ? )) |
|---|
| 317 |
(delete-region (point) (progn (forward-line 1) (point))) |
|---|
| 318 |
(forward-char -1))))))) |
|---|
| 319 |
|
|---|
| 320 |
(defun Buffer-menu-select () |
|---|
| 321 |
"Select this line's buffer; also display buffers marked with `>'. |
|---|
| 322 |
You can mark buffers with the \\<Buffer-menu-mode-map>\\[Buffer-menu-mark] command. |
|---|
| 323 |
This command deletes and replaces all the previously existing windows |
|---|
| 324 |
in the selected frame." |
|---|
| 325 |
(interactive) |
|---|
| 326 |
(let ((buff (Buffer-menu-buffer t)) |
|---|
| 327 |
(menu (current-buffer)) |
|---|
| 328 |
(others ()) |
|---|
| 329 |
tem) |
|---|
| 330 |
(goto-char (point-min)) |
|---|
| 331 |
(while (search-forward "\n>" nil t) |
|---|
| 332 |
(setq tem (Buffer-menu-buffer t)) |
|---|
| 333 |
(let ((buffer-read-only nil)) |
|---|
| 334 |
(delete-char -1) |
|---|
| 335 |
(insert ?\ )) |
|---|
| 336 |
(or (eq tem buff) (memq tem others) (setq others (cons tem others)))) |
|---|
| 337 |
(setq others (nreverse others) |
|---|
| 338 |
tem (/ (1- (frame-height)) (1+ (length others)))) |
|---|
| 339 |
(delete-other-windows) |
|---|
| 340 |
(switch-to-buffer buff) |
|---|
| 341 |
(or (eq menu buff) |
|---|
| 342 |
(bury-buffer menu)) |
|---|
| 343 |
(if (equal (length others) 0) |
|---|
| 344 |
(progn |
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
(switch-to-buffer buff)) |
|---|
| 352 |
(while others |
|---|
| 353 |
(split-window nil tem) |
|---|
| 354 |
(other-window 1) |
|---|
| 355 |
(switch-to-buffer (car others)) |
|---|
| 356 |
(setq others (cdr others))) |
|---|
| 357 |
(other-window 1) |
|---|
| 358 |
))) |
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
|
|---|
| 362 |
(defun Buffer-menu-visit-tags-table () |
|---|
| 363 |
"Visit the tags table in the buffer on this line. See `visit-tags-table'." |
|---|
| 364 |
(interactive) |
|---|
| 365 |
(let ((file (buffer-file-name (Buffer-menu-buffer t)))) |
|---|
| 366 |
(if file |
|---|
| 367 |
(visit-tags-table file) |
|---|
| 368 |
(error "Specified buffer has no file")))) |
|---|
| 369 |
|
|---|
| 370 |
(defun Buffer-menu-1-window () |
|---|
| 371 |
"Select this line's buffer, alone, in full frame." |
|---|
| 372 |
(interactive) |
|---|
| 373 |
(switch-to-buffer (Buffer-menu-buffer t)) |
|---|
| 374 |
(bury-buffer (other-buffer)) |
|---|
| 375 |
(delete-other-windows)) |
|---|
| 376 |
|
|---|
| 377 |
(defun Buffer-menu-mouse-select (event) |
|---|
| 378 |
"Select the buffer whose line you click on." |
|---|
| 379 |
(interactive "e") |
|---|
| 380 |
(let (buffer) |
|---|
| 381 |
(save-excursion |
|---|
| 382 |
(set-buffer (window-buffer (posn-window (event-end event)))) |
|---|
| 383 |
(save-excursion |
|---|
| 384 |
(goto-char (posn-point (event-end event))) |
|---|
| 385 |
(setq buffer (Buffer-menu-buffer t)))) |
|---|
| 386 |
(select-window (posn-window (event-end event))) |
|---|
| 387 |
(if (and (window-dedicated-p (selected-window)) |
|---|
| 388 |
(eq (selected-window) (frame-root-window))) |
|---|
| 389 |
(switch-to-buffer-other-frame buffer) |
|---|
| 390 |
(switch-to-buffer buffer)))) |
|---|
| 391 |
|
|---|
| 392 |
(defun Buffer-menu-this-window () |
|---|
| 393 |
"Select this line's buffer in this window." |
|---|
| 394 |
(interactive) |
|---|
| 395 |
(switch-to-buffer (Buffer-menu-buffer t))) |
|---|
| 396 |
|
|---|
| 397 |
(defun Buffer-menu-other-window () |
|---|
| 398 |
"Select this line's buffer in other window, leaving buffer menu visible." |
|---|
| 399 |
(interactive) |
|---|
| 400 |
(switch-to-buffer-other-window (Buffer-menu-buffer t))) |
|---|
| 401 |
|
|---|
| 402 |
(defun Buffer-menu-switch-other-window () |
|---|
| 403 |
"Make the other window select this line's buffer. |
|---|
| 404 |
The current window remains selected." |
|---|
| 405 |
(interactive) |
|---|
| 406 |
(display-buffer (Buffer-menu-buffer t))) |
|---|
| 407 |
|
|---|
| 408 |
(defun Buffer-menu-2-window () |
|---|
| 409 |
"Select this line's buffer, with previous buffer in second window." |
|---|
| 410 |
(interactive) |
|---|
| 411 |
(let ((buff (Buffer-menu-buffer t)) |
|---|
| 412 |
(menu (current-buffer)) |
|---|
| 413 |
(pop-up-windows t)) |
|---|
| 414 |
(delete-other-windows) |
|---|
| 415 |
(switch-to-buffer (other-buffer)) |
|---|
| 416 |
(pop-to-buffer buff) |
|---|
| 417 |
(bury-buffer menu))) |
|---|
| 418 |
|
|---|
| 419 |
(defun Buffer-menu-toggle-read-only () |
|---|
| 420 |
"Toggle read-only status of buffer on this line, perhaps via version control." |
|---|
| 421 |
(interactive) |
|---|
| 422 |
(let (char) |
|---|
| 423 |
(save-excursion |
|---|
| 424 |
(set-buffer (Buffer-menu-buffer t)) |
|---|
| 425 |
(vc-toggle-read-only) |
|---|
| 426 |
(setq char (if buffer-read-only ?% ? ))) |
|---|
| 427 |
(save-excursion |
|---|
| 428 |
(beginning-of-line) |
|---|
| 429 |
(forward-char 2) |
|---|
| 430 |
(if (/= (following-char) char) |
|---|
| 431 |
(let (buffer-read-only) |
|---|
| 432 |
(delete-char 1) |
|---|
| 433 |
(insert char)))))) |
|---|
| 434 |
|
|---|
| 435 |
(defun Buffer-menu-bury () |
|---|
| 436 |
"Bury the buffer listed on this line." |
|---|
| 437 |
(interactive) |
|---|
| 438 |
(beginning-of-line) |
|---|
| 439 |
(if (looking-at " [-M]") |
|---|
| 440 |
(ding) |
|---|
| 441 |
(save-excursion |
|---|
| 442 |
(beginning-of-line) |
|---|
| 443 |
(bury-buffer (Buffer-menu-buffer t)) |
|---|
| 444 |
(let ((line (buffer-substring (point) (progn (forward-line 1) (point)))) |
|---|
| 445 |
(buffer-read-only nil)) |
|---|
| 446 |
(delete-region (point) (progn (forward-line -1) (point))) |
|---|
| 447 |
(goto-char (point-max)) |
|---|
| 448 |
(insert line)) |
|---|
| 449 |
(message "Buried buffer moved to the end")))) |
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
(defun Buffer-menu-view () |
|---|
| 453 |
"View this line's buffer in View mode." |
|---|
| 454 |
(interactive) |
|---|
| 455 |
(view-buffer (Buffer-menu-buffer t))) |
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
(defun Buffer-menu-view-other-window () |
|---|
| 459 |
"View this line's buffer in View mode in another window." |
|---|
| 460 |
(interactive) |
|---|
| 461 |
(view-buffer-other-window (Buffer-menu-buffer t))) |
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
(define-key ctl-x-map "\C-b" 'list-buffers) |
|---|
| 465 |
|
|---|
| 466 |
(defun list-buffers (&optional files-only) |
|---|
| 467 |
"Display a list of names of existing buffers. |
|---|
| 468 |
The list is displayed in a buffer named `*Buffer List*'. |
|---|
| 469 |
Note that buffers with names starting with spaces are omitted. |
|---|
| 470 |
Non-null optional arg FILES-ONLY means mention only file buffers. |
|---|
| 471 |
|
|---|
| 472 |
The M column contains a * for buffers that are modified. |
|---|
| 473 |
The R column contains a % for buffers that are read-only." |
|---|
| 474 |
(interactive "P") |
|---|
| 475 |
(display-buffer (list-buffers-noselect files-only))) |
|---|
| 476 |
|
|---|
| 477 |
(defun list-buffers-noselect (&optional files-only) |
|---|
| 478 |
"Create and return a buffer with a list of names of existing buffers. |
|---|
| 479 |
The buffer is named `*Buffer List*'. |
|---|
| 480 |
Note that buffers with names starting with spaces are omitted. |
|---|
| 481 |
Non-null optional arg FILES-ONLY means mention only file buffers. |
|---|
| 482 |
|
|---|
| 483 |
The M column contains a * for buffers that are modified. |
|---|
| 484 |
The R column contains a % for buffers that are read-only." |
|---|
| 485 |
(let ((old-buffer (current-buffer)) |
|---|
| 486 |
(standard-output standard-output) |
|---|
| 487 |
desired-point) |
|---|
| 488 |
(save-excursion |
|---|
| 489 |
(set-buffer (get-buffer-create "*Buffer List*")) |
|---|
| 490 |
(setq buffer-read-only nil) |
|---|
| 491 |
(erase-buffer) |
|---|
| 492 |
(setq standard-output (current-buffer)) |
|---|
| 493 |
(princ "\ |
|---|
| 494 |
MR Buffer Size Mode File |
|---|
| 495 |
-- ------ ---- ---- ---- |
|---|
| 496 |
") |
|---|
| 497 |
|
|---|
| 498 |
(setq Buffer-menu-buffer-column 4) |
|---|
| 499 |
(dolist (buffer (buffer-list)) |
|---|
| 500 |
(let ((name (buffer-name buffer)) |
|---|
| 501 |
(file (buffer-file-name buffer)) |
|---|
| 502 |
this-buffer-line-start |
|---|
| 503 |
this-buffer-read-only |
|---|
| 504 |
(this-buffer-size (buffer-size buffer)) |
|---|
| 505 |
this-buffer-mode-name |
|---|
| 506 |
this-buffer-directory) |
|---|
| 507 |
(with-current-buffer buffer |
|---|
| 508 |
(setq this-buffer-read-only buffer-read-only |
|---|
| 509 |
this-buffer-mode-name mode-name) |
|---|
| 510 |
(unless file |
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
(when (and (boundp 'list-buffers-directory) |
|---|
| 514 |
list-buffers-directory) |
|---|
| 515 |
(setq this-buffer-directory list-buffers-directory)))) |
|---|
| 516 |
(cond |
|---|
| 517 |
|
|---|
| 518 |
((string= (substring name 0 1) " ")) |
|---|
| 519 |
|
|---|
| 520 |
((and files-only (not file))) |
|---|
| 521 |
((string= name "*Buffer List*")) |
|---|
| 522 |
|
|---|
| 523 |
(t |
|---|
| 524 |
(setq this-buffer-line-start (point)) |
|---|
| 525 |
|
|---|
| 526 |
(if (eq buffer old-buffer) |
|---|
| 527 |
(progn |
|---|
| 528 |
(setq desired-point (point)) |
|---|
| 529 |
(princ ".")) |
|---|
| 530 |
(princ " ")) |
|---|
| 531 |
|
|---|
| 532 |
(princ (if (buffer-modified-p buffer) "*" " ")) |
|---|
| 533 |
|
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
(princ (if (or (eq buffer standard-output) |
|---|
| 537 |
this-buffer-read-only) |
|---|
| 538 |
"% " |
|---|
| 539 |
" ")) |
|---|
| 540 |
(princ name) |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
(setq this-buffer-line-start |
|---|
| 545 |
(+ this-buffer-line-start Buffer-menu-buffer-column)) |
|---|
| 546 |
(let ((name-end (point))) |
|---|
| 547 |
(indent-to 17 2) |
|---|
| 548 |
(put-text-property this-buffer-line-start name-end |
|---|
| 549 |
'buffer-name name) |
|---|
| 550 |
(put-text-property this-buffer-line-start (point) |
|---|
| 551 |
'buffer buffer) |
|---|
| 552 |
(put-text-property this-buffer-line-start name-end |
|---|
| 553 |
'mouse-face 'highlight) |
|---|
| 554 |
(put-text-property this-buffer-line-start name-end |
|---|
| 555 |
'help-echo "mouse-2: select this buffer")) |
|---|
| 556 |
(let ((size (format "%8d" this-buffer-size)) |
|---|
| 557 |
(mode this-buffer-mode-name) |
|---|
| 558 |
(excess (- (current-column) 17))) |
|---|
| 559 |
(while (and (> excess 0) (= (aref size 0) ?\ )) |
|---|
| 560 |
(setq size (substring size 1) |
|---|
| 561 |
excess (1- excess))) |
|---|
| 562 |
(princ size) |
|---|
| 563 |
(indent-to 27 1) |
|---|
| 564 |
(princ mode)) |
|---|
| 565 |
(indent-to 40 1) |
|---|
| 566 |
(or file (setq file this-buffer-directory)) |
|---|
| 567 |
(when file |
|---|
| 568 |
(princ (abbreviate-file-name file))) |
|---|
| 569 |
(princ "\n"))))) |
|---|
| 570 |
(Buffer-menu-mode) |
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
(and desired-point |
|---|
| 574 |
(goto-char desired-point)) |
|---|
| 575 |
(current-buffer)))) |
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|