diff -c "c:/drews-lisp-20/buff-menu-before-sort-fix.el" "c:/drews-lisp-20/buff-menu-after-sort-fix.el" *** c:/drews-lisp-20/buff-menu-before-sort-fix.el Sat Oct 16 16:37:02 2004 --- c:/drews-lisp-20/buff-menu-after-sort-fix.el Sat Oct 16 16:54:44 2004 *************** *** 47,52 **** --- 47,56 ---- ;;; Code: + + (eval-when-compile (require 'cl)) ;; push, pop, unless, when, case + + ;;Trying to preserve the old window configuration works well in ;;simple scenarios, when you enter the buffer menu, use it, and exit it. ;;But it does strange things when you switch back to the buffer list buffer *************** *** 89,98 **** :type 'number :group 'Buffer-menu) ! ;; This should get updated & resorted when you click on a column heading ! (defvar Buffer-menu-sort-column nil "*2 for sorting by buffer names. 5 for sorting by file names. ! nil for default sorting by visited order.") (defconst Buffer-menu-buffer-column 4) --- 93,104 ---- :type 'number :group 'Buffer-menu) ! ;; This should get updated & re-sorted when you click a column heading ! ;; Sorted by (1) visit, (2) buffer, (3) size, (4) mode, (5) file. ! (defvar Buffer-menu-sort-column 1 "*2 for sorting by buffer names. 5 for sorting by file names. ! 1 for default sorting by visited order. 3 for sorting by buffer size. ! 4 for sorting by major-mode name.") (defconst Buffer-menu-buffer-column 4) *************** *** 574,600 **** size)) (defun Buffer-menu-sort (column) ! "Sort the buffer menu by COLUMN." (interactive "P") (when column (setq column (prefix-numeric-value column)) ! (if (< column 2) (setq column 2)) ! (if (> column 5) (setq column 5))) ! (setq Buffer-menu-sort-column column) ! (Buffer-menu-revert)) ! ! (defun Buffer-menu-make-sort-button (name column) ! (if (equal column Buffer-menu-sort-column) (setq column nil)) ! (propertize name ! 'help-echo (if column ! (concat "mouse-2: sort by " (downcase name)) ! "mouse-2: sort by visited order") ! 'mouse-face 'highlight ! 'keymap (let ((map (make-sparse-keymap))) ! (define-key map [header-line mouse-2] ! `(lambda () (interactive) ! (Buffer-menu-sort ,column))) ! map))) (defun list-buffers-noselect (&optional files-only) "Create and return a buffer with a list of names of existing buffers. --- 580,633 ---- size)) (defun Buffer-menu-sort (column) ! "Sort the buffer menu by COLUMN. ! Consecutive executions of the same COLUMN reverse the sort order." (interactive "P") (when column (setq column (prefix-numeric-value column)) ! (when (= column 0) (setq column 1)) ! (when (> column 5) (setq column 5)) ! (when (< column -5) (setq column -5))) ! (if (equal Buffer-menu-sort-column column) ! (setq Buffer-menu-sort-column (- column)) ! (setq Buffer-menu-sort-column column)) ! (Buffer-menu-revert) ! (message "Buffers are now sorted %s%s." ! (case (abs column) ! (1 "in the order they were visited") ! (2 "by buffer name") ! (3 "by size") ! (4 "by major-mode name") ! (otherwise "by associated file (including path)")) ! (if (= 1 (abs column)) ! "" ! (if (natnump Buffer-menu-sort-column) ", ascending" ", descending")))) ! ! ;; Heading of sorted column is highlighted: ! ;; - If CRM column, then use inverse-video. ! ;; - Else, use underline for ascending sort, overline for descending. ! (defun Buffer-menu-make-sort-button (name button-column) ! (let ((the-sort-column-p nil)) ! (when (equal button-column (abs Buffer-menu-sort-column)) ! (setq the-sort-column-p t) ! (setq button-column (- button-column))) ! (propertize name ! 'help-echo (if (>= (abs button-column) 2) ! (concat "mouse-2: sort by " (downcase name)) ! "mouse-2: sort by visited order") ! 'mouse-face 'highlight ! ;; Apply face to sort-column heading, depending on direction. ! (when the-sort-column-p 'face) ! (when the-sort-column-p ! (if (>= (abs button-column) 2) ! (if (natnump Buffer-menu-sort-column) ! '(:underline t) ! '(:overline t)) ! '(:inverse-video t))) ; CRM column ! 'keymap (let ((map (make-sparse-keymap))) ! (define-key map [header-line mouse-2] ! `(lambda () (interactive) (Buffer-menu-sort ,button-column))) ! map)))) (defun list-buffers-noselect (&optional files-only) "Create and return a buffer with a list of names of existing buffers. *************** *** 671,685 **** name (buffer-size) mode file))))) (buffer-list)))) (dolist (buffer ! (if Buffer-menu-sort-column ! (sort list ! (if (eq Buffer-menu-sort-column 3) ! (lambda (a b) ! (< (nth Buffer-menu-sort-column a) ! (nth Buffer-menu-sort-column b))) ! (lambda (a b) ! (string< (nth Buffer-menu-sort-column a) ! (nth Buffer-menu-sort-column b))))) list)) (if (eq (car buffer) old-buffer) (setq desired-point (point))) --- 704,724 ---- name (buffer-size) mode file))))) (buffer-list)))) (dolist (buffer ! (if (>= (abs Buffer-menu-sort-column) 2) ! (let* ((descending-p (natnump Buffer-menu-sort-column)) ! (Buffer-menu-sort-column (abs Buffer-menu-sort-column))) ! (sort list ! (if (eq Buffer-menu-sort-column 3) ! (if descending-p ! (lambda (a b) (< (nth 3 a) (nth 3 b))) ! (lambda (a b) (< (nth 3 b) (nth 3 a)))) ! (if descending-p ! (lambda (a b) ! (string< (nth Buffer-menu-sort-column a) ! (nth Buffer-menu-sort-column b))) ! (lambda (a b) ! (string< (nth Buffer-menu-sort-column b) ! (nth Buffer-menu-sort-column a))))))) list)) (if (eq (car buffer) old-buffer) (setq desired-point (point)))