From f1a316fb834566dae1b76c815af32e51987166cd Mon Sep 17 00:00:00 2001 From: Philippe Vaucher Date: Sat, 2 Mar 2019 20:03:41 +0100 Subject: [PATCH] Customize tabulated-list sort indicators This allows the user to customize the sorting indicators displayed near the current column. * etc/NEWS: Mention changes * lisp/emacs-lisp/tabulated-list.el (tabulated-list): New group. (tabulated-list-gui-sort-indicator-asc): New defcustom. (tabulated-list-gui-sort-indicator-desc): New defcustom. (tabulated-list-tty-sort-indicator-asc): New defcustom. (tabulated-list-tty-sort-indicator-desc): New defcustom. (tabulated-list-glyphless-char-display): Removal. (tabulated-list-make-glyphless-char-display-table): New function. --- etc/NEWS | 9 ++++++ lisp/emacs-lisp/tabulated-list.el | 52 +++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b265185567..a2cdec0083 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -279,6 +279,15 @@ matches strings where the pattern appears as a subsequence. Put simply, makes "foo" complete to both "barfoo" and "frodo". Add 'flex' to 'completion-styles' or 'completion-category-overrides' to use it. ++++ +** New user options for tabulated list sort indicators +The user can customize which sorting indicator character to display +near the current column in Tabulated Lists: +- tabulated-list-gui-sort-indicator-asc +- tabulated-list-gui-sort-indicator-desc +- tabulated-list-tty-sort-indicator-asc +- tabulated-list-tty-sort-indicator-desc + * Editing Changes in Emacs 27.1 diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index 12d0151d67..cc82d3397d 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -36,6 +36,37 @@ ;;; Code: +(defgroup tabulated-list nil + "Tabulated-list customization group.") + +(defcustom tabulated-list-gui-sort-indicator-asc ?▼ + "GUI indicator displayed near the current column when the sort order +is ascending." + :group 'tabulated-list + :type 'character + :version "27.1") + +(defcustom tabulated-list-gui-sort-indicator-desc ?▲ + "GUI indicator displayed near the current column when the sort order +is descending." + :group 'tabulated-list + :type 'character + :version "27.1") + +(defcustom tabulated-list-tty-sort-indicator-asc ?v + "TTY indicator displayed near the current column when the sort order +is ascending." + :group 'tabulated-list + :type 'character + :version "27.1") + +(defcustom tabulated-list-tty-sort-indicator-desc ?^ + "TTY indicator displayed near the current column when the sort order +is descending." + :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 +205,17 @@ 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 in Tabulated List buffers." (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 +265,8 @@ 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 +689,7 @@ 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) -- 2.17.1