From 029422b3d1cb922beccbf32f793df5cf3c454e20 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 22 Jul 2024 11:56:03 +0200 Subject: [PATCH] tabulated-list.el: Improve handling of disappearing sort column --- lisp/emacs-lisp/tabulated-list.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index 30397137efb..0052230488e 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -414,21 +414,22 @@ It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'." Return nil if `tabulated-list-sort-key' specifies an unsortable column. Negate the predicate that would be returned if `tabulated-list-sort-key' has a non-nil cdr." - (when (and tabulated-list-sort-key - (car tabulated-list-sort-key)) - (let* ((sort-column (car tabulated-list-sort-key)) - (n (tabulated-list--column-number sort-column)) - (sorter (nth 2 (aref tabulated-list-format n)))) - (when (eq sorter t); Default sorter checks column N: - (setq sorter (lambda (A B) - (let ((a (aref (cadr A) n)) - (b (aref (cadr B) n))) - (string< (if (stringp a) a (car a)) - (if (stringp b) b (car b))))))) - ;; Reversed order. - (if (cdr tabulated-list-sort-key) - (lambda (a b) (funcall sorter b a)) - sorter)))) + (when-let ((sort-column (and tabulated-list-sort-key + (car tabulated-list-sort-key))) + ;; `sort-column' may have been removed. If so, catch the + ;; error and bail. + (n (ignore-errors (tabulated-list--column-number sort-column))) + (sorter (nth 2 (aref tabulated-list-format n)))) + (when (eq sorter t); Default sorter checks column N: + (setq sorter (lambda (A B) + (let ((a (aref (cadr A) n)) + (b (aref (cadr B) n))) + (string< (if (stringp a) a (car a)) + (if (stringp b) b (car b))))))) + ;; Reversed order. + (if (cdr tabulated-list-sort-key) + (lambda (a b) (funcall sorter b a)) + sorter))) (defsubst tabulated-list--col-local-max-widths (col) "Return maximum entry widths at column COL around current row. -- 2.39.5