mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-20 04:30:55 -08:00
Make vtable sorting stable
* lisp/emacs-lisp/vtable.el (vtable--sort): Make the sorting stable.
This commit is contained in:
parent
dd91aac508
commit
525c01c43a
1 changed files with 14 additions and 10 deletions
|
|
@ -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)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue