]> git.eshelyaron.com Git - emacs.git/commitdiff
Customize tabulated-list sort indicators
authorPhilippe Vaucher <philippe.vaucher@gmail.com>
Sat, 2 Mar 2019 19:03:41 +0000 (20:03 +0100)
committerEli Zaretskii <eliz@gnu.org>
Fri, 15 Mar 2019 09:08:01 +0000 (11:08 +0200)
This allows the user to customize the sorting indicators displayed
near the current column.

* lisp/emacs-lisp/tabulated-list.el (tabulated-list): New group.
(tabulated-list-gui-sort-indicator-asc)
(tabulated-list-gui-sort-indicator-desc)
(tabulated-list-tty-sort-indicator-asc)
(tabulated-list-tty-sort-indicator-desc): New defcustomd.
(tabulated-list-glyphless-char-display): Remove.
(tabulated-list-make-glyphless-char-display-table): New function.

* doc/lispref/modes.texi (Tabulated List Mode): Add documentation
for new options.

* etc/NEWS: Mention the new options.

doc/lispref/modes.texi
etc/NEWS
lisp/emacs-lisp/tabulated-list.el

index 3f6bee9821d083992063645854a0c59d1c51a9a6..1afbc5a5cee79757d0a0ec2bcf3682a24a37f319 100644 (file)
@@ -1015,6 +1015,29 @@ list-processes}).  The listing command should create or switch to a
 buffer, turn on the derived mode, specify the tabulated data, and
 finally call @code{tabulated-list-print} to populate the buffer.
 
+@defopt tabulated-list-gui-sort-indicator-asc
+This variable specifies the character to be used on GUI frames as an
+indication that the column is sorted in the ascending order.
+
+Whenever you change the sort direction in Tabulated List buffers, this
+indicator toggles between ascending (``asc'') and descending (``desc'').
+@end defopt
+
+@defopt tabulated-list-gui-sort-indicator-desc
+Like @code{tabulated-list-gui-sort-indicator-asc}, but used when the
+column is sorted in the descending order.
+@end defopt
+
+@defopt tabulated-list-tty-sort-indicator-asc
+Like @code{tabulated-list-gui-sort-indicator-asc}, but used for
+text-mode frames.
+@end defopt
+
+@defopt tabulated-list-tty-sort-indicator-desc
+Like @code{tabulated-list-tty-sort-indicator-asc}, but used when the
+column is sorted in the descending order.
+@end defopt
+
 @defvar tabulated-list-format
 This buffer-local variable specifies the format of the Tabulated List
 data.  Its value should be a vector.  Each element of the vector
index 31772abe6c7116b18384788017afdbe079b1de3d..000d211c1ab43cf8f3a51ef2cc5c9ffc5ba1568f 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -923,7 +923,7 @@ been instrumented by Edebug.
 the XTerm window title.  This feature is experimental and is disabled
 by default.
 
-** grep
+** Grep
 
 +++
 *** rgrep, lgrep and zrgrep now hide part of the command line
@@ -1194,6 +1194,17 @@ the 128...255 range, as expected.
 This allows to create and parent immediately a minibuffer-only child
 frame when making a frame.
 
+** Tabulated List mode
+
++++
+** New user options for tabulated list sort indicators.
+You can now customize which sorting indicator character to display
+near the current column in Tabulated Lists (see variables
+'tabulated-list-gui-sort-indicator-asc',
+'tabulated-list-gui-sort-indicator-desc',
+'tabulated-list-tty-sort-indicator-asc', and
+'tabulated-list-tty-sort-indicator-desc').
+
 \f
 * New Modes and Packages in Emacs 27.1
 
index 12d0151d67ff9a7d1aa762d15aceede533c0799d..b23ce21027b73ffba36e646b10b04045dab6b75c 100644 (file)
 
 ;;; Code:
 
+(defgroup tabulated-list nil
+  "Tabulated-list customization group."
+  :group 'convenience
+  :group 'display)
+
+(defcustom tabulated-list-gui-sort-indicator-asc ?▼
+  "Indicator for columns sorted in ascending order, for GUI frames.
+See `tabulated-list-tty-sort-indicator-asc' for the indicator used on
+text-mode frames."
+  :group 'tabulated-list
+  :type 'character
+  :version "27.1")
+
+(defcustom tabulated-list-gui-sort-indicator-desc ?▲
+  "Indicator for columns sorted in descending order, for GUI frames.
+See `tabulated-list-tty-sort-indicator-desc' for the indicator used on
+text-mode frames."
+  :group 'tabulated-list
+  :type 'character
+  :version "27.1")
+
+(defcustom tabulated-list-tty-sort-indicator-asc ?v
+  "Indicator for columns sorted in ascending order, for text-mode frames.
+See `tabulated-list-gui-sort-indicator-asc' for the indicator used on GUI
+frames."
+  :group 'tabulated-list
+  :type 'character
+  :version "27.1")
+
+(defcustom tabulated-list-tty-sort-indicator-desc ?^
+  "Indicator for columns sorted in ascending order, for text-mode frames.
+See `tabulated-list-gui-sort-indicator-asc' for the indicator used on GUI
+frames."
+  :group 'tabulated-list
+  :type 'character
+  :version "27.1")
+
 ;; The reason `tabulated-list-format' and other variables are
 ;; permanent-local is to make it convenient to switch to a different
 ;; major mode, switch back, and have the original Tabulated List data
@@ -174,14 +211,20 @@ If ADVANCE is non-nil, move forward by one line afterwards."
     map)
   "Local keymap for `tabulated-list-mode' sort buttons.")
 
-(defvar tabulated-list-glyphless-char-display
+(defun tabulated-list-make-glyphless-char-display-table ()
+  "Make the `glyphless-char-display' table used for text-mode frames.
+This table is used for displaying the sorting indicators, see
+variables `tabulated-list-tty-sort-indicator-asc' and
+`tabulated-list-tty-sort-indicator-desc' for more information."
   (let ((table (make-char-table 'glyphless-char-display nil)))
     (set-char-table-parent table glyphless-char-display)
-    ;; Some text terminals can't display the Unicode arrows; be safe.
-    (aset table 9650 (cons nil "^"))
-    (aset table 9660 (cons nil "v"))
-    table)
-  "The `glyphless-char-display' table in Tabulated List buffers.")
+    (aset table
+          tabulated-list-gui-sort-indicator-desc
+          (cons nil (char-to-string tabulated-list-tty-sort-indicator-desc)))
+    (aset table
+          tabulated-list-gui-sort-indicator-asc
+          (cons nil (char-to-string tabulated-list-tty-sort-indicator-asc)))
+    table))
 
 (defvar tabulated-list--header-string nil
   "Holds the header if `tabulated-list-use-header-line' is nil.
@@ -231,8 +274,11 @@ Populated by `tabulated-list-init-header'.")
                  (concat label
                          (cond
                           ((> (+ 2 (length label)) width) "")
-                          ((cdr tabulated-list-sort-key) " ▲")
-                          (t " ▼")))
+                          ((cdr tabulated-list-sort-key)
+                            (format " %c"
+                                    tabulated-list-gui-sort-indicator-desc))
+                          (t (format " %c"
+                                      tabulated-list-gui-sort-indicator-asc))))
                  'face 'bold
                  'tabulated-list-column-name label
                  button-props))
@@ -655,7 +701,8 @@ as the ewoc pretty-printer."
   (setq-local truncate-lines t)
   (setq-local buffer-undo-list t)
   (setq-local revert-buffer-function #'tabulated-list-revert)
-  (setq-local glyphless-char-display tabulated-list-glyphless-char-display)
+  (setq-local glyphless-char-display
+              (tabulated-list-make-glyphless-char-display-table))
   ;; Avoid messing up the entries' display just because the first
   ;; column of the first entry happens to begin with a R2L letter.
   (setq bidi-paragraph-direction 'left-to-right)