summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-03-13 21:13:49 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2022-03-13 21:13:49 +0100
commit525c01c43a75b6190243530a70cd4943abe980a7 (patch)
tree1c05da9dca1e1e4e9fcdc177f345b1e67ab17bd2 /lisp/emacs-lisp
parentdd91aac508b5727e10d370f2405dbcecf9578417 (diff)
downloademacs-525c01c43a75b6190243530a70cd4943abe980a7.tar.gz
emacs-525c01c43a75b6190243530a70cd4943abe980a7.tar.bz2
emacs-525c01c43a75b6190243530a70cd4943abe980a7.zip
Make vtable sorting stable
* lisp/emacs-lisp/vtable.el (vtable--sort): Make the sorting stable.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/vtable.el24
1 files changed, 14 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el
index d8577c19762..8d777335315 100644
--- a/lisp/emacs-lisp/vtable.el
+++ b/lisp/emacs-lisp/vtable.el
@@ -456,22 +456,26 @@ This also updates the displayed table."
(pcase-dolist (`(,index . ,direction) (vtable-sort-by table))
(let ((cache (vtable--cache table))
(numerical (vtable-column--numerical
- (elt (vtable-columns table) index))))
+ (elt (vtable-columns table) index)))
+ (numcomp (if (eq direction 'descend)
+ #'> #'<))
+ (stringcomp (if (eq direction 'descend)
+ #'string> #'string<)))
(setcar cache
(sort (car cache)
(lambda (e1 e2)
(let ((c1 (elt e1 (1+ index)))
(c2 (elt e2 (1+ index))))
(if numerical
- (< (car c1) (car c2))
- (string< (if (stringp (car c1))
- (car c1)
- (format "%s" (car c1)))
- (if (stringp (car c2))
- (car c2)
- (format "%s" (car c2)))))))))
- (when (eq direction 'descend)
- (setcar cache (nreverse (car cache)))))))
+ (funcall numcomp (car c1) (car c2))
+ (funcall
+ stringcomp
+ (if (stringp (car c1))
+ (car c1)
+ (format "%s" (car c1)))
+ (if (stringp (car c2))
+ (car c2)
+ (format "%s" (car c2))))))))))))
(defun vtable--indicator (table index)
(let ((order (car (last (vtable-sort-by table)))))