* buff-menu.el - minor enhancement to sort columns up or down
@ 2004-10-17 0:33 Drew Adams
0 siblings, 0 replies; only message in thread
From: Drew Adams @ 2004-10-17 0:33 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 2330 bytes --]
This is a minor enhancement to buff-menu.el. It lets you sort *Buffer List*
columns in ascending or descending order (consecutive heading clicks reverse
direction), and it highlights the heading of the sorted column (indicating
the current direction).
To try it:
1. Patch file buff-menu.el from CVS using the attached patch.
2. Compile the patched file, then load the compiled patched file.
Or, load cl.el, then load the uncompiled patched file.
3. (setq Buffer-menu-sort-column 1)
Buffer-menu-sort-column was preloaded with dumped emacs, so the defvar
for
it in the patched file doesn't take effect. You need to do this, or you
will get an error because the dumped value for it is nil.
4. C-x C-b, to display buffer *Buffer List*.
5. Click in the *Buffer List* window.
(This should not be necessary. I've just filed a bug on this:
command `buffer-menu' doesn't select buffer *Buffer List* as it should.)
>From now on, when you click a column header in *Buffer List*:
- Consecutive clicks of the same header reverse the previous sort order.
- The sorted column has its heading underlined or overlined, depending on
the sort direction. This tells you 1) which column is sorted and 2) the sort
direction.
- A message in the echo area also tells you what the new order is (which
column is sorted, and whether ascending or descending).
You can click column heading "CRM" to get the "visited" order that is the
default order. When the buffer is sorted that way, the CRM heading is in
inverse video (there is no reverse of this sort order).
Note: The attached patch patches the latest buff-menu.el from CVS. However,
I'm using a Windows binary from 7-26-2004. The version of buff-menu.el that
corresponds to my binary has a different version of `list-buffers-noselect'.
The newer, CVS version uses a 4-argument form of format-mode-line that is
not available in my binary. So, I've tested this by patching the older
`list-buffers-noselect' that works with my binary. (In fact, I tested it
with a version of `list-buffers-noselect' that fixes a bug that doesn't let
you use it with dedicated windows.) Let me know if you have a pb with the
patched CVS version.
Since this is a minor code change, how about including it in Emacs now?
(Something similar could perhaps be done for Dired column headings, later.)
[-- Attachment #2: diff-buff-menu-w-new-sort.txt --]
[-- Type: text/plain, Size: 6798 bytes --]
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)))
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-10-17 0:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-17 0:33 buff-menu.el - minor enhancement to sort columns up or down Drew Adams
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.