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.