diff options
| -rw-r--r-- | lisp/buff-menu.el | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index 800f8693eda..02f93a0cff2 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; buff-menu.el --- buffer menu main function and support functions | 1 | ;;; buff-menu.el --- buffer menu main function and support functions |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 2000, 2001, 2002, 2003 | 3 | ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 2000, 2001, 2002, 03, 2004 |
| 4 | ;; Free Software Foundation, Inc. | 4 | ;; Free Software Foundation, Inc. |
| 5 | 5 | ||
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -47,22 +47,22 @@ | |||
| 47 | 47 | ||
| 48 | ;;; Code: | 48 | ;;; Code: |
| 49 | 49 | ||
| 50 | ;;;Trying to preserve the old window configuration works well in | 50 | ;;Trying to preserve the old window configuration works well in |
| 51 | ;;;simple scenarios, when you enter the buffer menu, use it, and exit it. | 51 | ;;simple scenarios, when you enter the buffer menu, use it, and exit it. |
| 52 | ;;;But it does strange things when you switch back to the buffer list buffer | 52 | ;;But it does strange things when you switch back to the buffer list buffer |
| 53 | ;;;with C-x b, later on, when the window configuration is different. | 53 | ;;with C-x b, later on, when the window configuration is different. |
| 54 | ;;;The choice seems to be, either restore the window configuration | 54 | ;;The choice seems to be, either restore the window configuration |
| 55 | ;;;in all cases, or in no cases. | 55 | ;;in all cases, or in no cases. |
| 56 | ;;;I decided it was better not to restore the window config at all. -- rms. | 56 | ;;I decided it was better not to restore the window config at all. -- rms. |
| 57 | 57 | ||
| 58 | ;;;But since then, I changed buffer-menu to use the selected window, | 58 | ;;But since then, I changed buffer-menu to use the selected window, |
| 59 | ;;;so q now once again goes back to the previous window configuration. | 59 | ;;so q now once again goes back to the previous window configuration. |
| 60 | 60 | ||
| 61 | ;;;(defvar Buffer-menu-window-config nil | 61 | ;;(defvar Buffer-menu-window-config nil |
| 62 | ;;; "Window configuration saved from entry to `buffer-menu'.") | 62 | ;; "Window configuration saved from entry to `buffer-menu'.") |
| 63 | 63 | ||
| 64 | ; Put buffer *Buffer List* into proper mode right away | 64 | ;; Put buffer *Buffer List* into proper mode right away |
| 65 | ; so that from now on even list-buffers is enough to get a buffer menu. | 65 | ;; so that from now on even list-buffers is enough to get a buffer menu. |
| 66 | 66 | ||
| 67 | (defgroup Buffer-menu nil | 67 | (defgroup Buffer-menu nil |
| 68 | "Show a menu of all buffers in a buffer." | 68 | "Show a menu of all buffers in a buffer." |
| @@ -89,7 +89,7 @@ | |||
| 89 | :type 'number | 89 | :type 'number |
| 90 | :group 'Buffer-menu) | 90 | :group 'Buffer-menu) |
| 91 | 91 | ||
| 92 | ; This should get updated & resorted when you click on a column heading | 92 | ;; This should get updated & resorted when you click on a column heading |
| 93 | (defvar Buffer-menu-sort-column nil | 93 | (defvar Buffer-menu-sort-column nil |
| 94 | "*2 for sorting by buffer names. 5 for sorting by file names. | 94 | "*2 for sorting by buffer names. 5 for sorting by file names. |
| 95 | nil for default sorting by visited order.") | 95 | nil for default sorting by visited order.") |
| @@ -547,6 +547,29 @@ For more information, see the function `buffer-menu'." | |||
| 547 | ? ) | 547 | ? ) |
| 548 | size)) | 548 | size)) |
| 549 | 549 | ||
| 550 | (defun Buffer-menu-sort (column) | ||
| 551 | "Sort the buffer menu by COLUMN." | ||
| 552 | (interactive "P") | ||
| 553 | (when column | ||
| 554 | (setq column (prefix-numeric-value column)) | ||
| 555 | (if (< column 2) (setq column 2)) | ||
| 556 | (if (> column 5) (setq column 5))) | ||
| 557 | (setq Buffer-menu-sort-column column) | ||
| 558 | (Buffer-menu-revert)) | ||
| 559 | |||
| 560 | (defun Buffer-menu-make-sort-button (name column) | ||
| 561 | (if (equal column Buffer-menu-sort-column) (setq column nil)) | ||
| 562 | (propertize name | ||
| 563 | 'help-echo (if column | ||
| 564 | (concat "mouse-2: sort by " (downcase name)) | ||
| 565 | "mouse-2: sort by visited order") | ||
| 566 | 'mouse-face 'highlight | ||
| 567 | 'keymap (let ((map (make-sparse-keymap))) | ||
| 568 | (define-key map [header-line mouse-2] | ||
| 569 | `(lambda () (interactive) | ||
| 570 | (Buffer-menu-sort ,column))) | ||
| 571 | map))) | ||
| 572 | |||
| 550 | (defun list-buffers-noselect (&optional files-only) | 573 | (defun list-buffers-noselect (&optional files-only) |
| 551 | "Create and return a buffer with a list of names of existing buffers. | 574 | "Create and return a buffer with a list of names of existing buffers. |
| 552 | The buffer is named `*Buffer List*'. | 575 | The buffer is named `*Buffer List*'. |
| @@ -557,29 +580,25 @@ For more information, see the function `buffer-menu'." | |||
| 557 | (let* ((old-buffer (current-buffer)) | 580 | (let* ((old-buffer (current-buffer)) |
| 558 | (standard-output standard-output) | 581 | (standard-output standard-output) |
| 559 | (mode-end (make-string (- Buffer-menu-mode-width 2) ? )) | 582 | (mode-end (make-string (- Buffer-menu-mode-width 2) ? )) |
| 560 | (header (concat (propertize "CRM " 'face 'fixed-pitch) | 583 | (header (concat " " (propertize "CRM " 'face 'fixed-pitch) |
| 561 | (Buffer-menu-buffer+size "Buffer" "Size") | 584 | (Buffer-menu-buffer+size |
| 562 | " Mode" mode-end "File\n")) | 585 | (Buffer-menu-make-sort-button "Buffer" 2) |
| 563 | list desired-point name file mode) | 586 | (Buffer-menu-make-sort-button "Size" 3)) |
| 587 | " " | ||
| 588 | (Buffer-menu-make-sort-button "Mode" 4) mode-end | ||
| 589 | (Buffer-menu-make-sort-button "File" 5) "\n")) | ||
| 590 | list desired-point name file) | ||
| 564 | (when Buffer-menu-use-header-line | 591 | (when Buffer-menu-use-header-line |
| 565 | (let ((spaces | 592 | (let ((pos 0)) |
| 566 | (- (car (window-inside-edges)) | ||
| 567 | (car (window-edges)))) | ||
| 568 | (pos 0)) | ||
| 569 | ;; Turn spaces in the header into stretch specs so they work | 593 | ;; Turn spaces in the header into stretch specs so they work |
| 570 | ;; regardless of the header-line face. | 594 | ;; regardless of the header-line face. |
| 571 | (while (string-match "[ \t]+" header pos) | 595 | (while (string-match "[ \t]+" header pos) |
| 572 | (setq pos (match-end 0)) | 596 | (setq pos (match-end 0)) |
| 573 | (put-text-property (match-beginning 0) pos 'display | 597 | (put-text-property (match-beginning 0) pos 'display |
| 574 | ;; Assume fixed-size chars | 598 | ;; Assume fixed-size chars |
| 575 | (list 'space :align-to (+ spaces pos)) | 599 | (list 'space :align-to (1- pos)) |
| 576 | header)) | ||
| 577 | ;; Add the leading space | ||
| 578 | (setq header (concat (propertize (make-string (floor spaces) ? ) | ||
| 579 | 'display (list 'space :width spaces)) | ||
| 580 | header)))) | 600 | header)))) |
| 581 | (save-excursion | 601 | (with-current-buffer (get-buffer-create "*Buffer List*") |
| 582 | (set-buffer (get-buffer-create "*Buffer List*")) | ||
| 583 | (setq buffer-read-only nil) | 602 | (setq buffer-read-only nil) |
| 584 | (erase-buffer) | 603 | (erase-buffer) |
| 585 | (setq standard-output (current-buffer)) | 604 | (setq standard-output (current-buffer)) |