Function: chart-sort-matchlist
chart-sort-matchlist is a byte-compiled function defined in
chart.el.gz.
Signature
(chart-sort-matchlist NAMELST NUMLST PRED)
Documentation
Sort NAMELST and NUMLST (both sequence objects) based on predicate PRED.
PRED should be the equivalent of <, except it must expect two
cons cells of the form (NAME . NUM). See sort for more details.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/chart.el.gz
(defun chart-sort-matchlist (namelst numlst pred)
"Sort NAMELST and NUMLST (both sequence objects) based on predicate PRED.
PRED should be the equivalent of `<', except it must expect two
cons cells of the form (NAME . NUM). See `sort' for more details."
;; 1 - create 1 list of cons cells
(let ((newlist nil)
(alst (oref namelst data))
(ulst (oref numlst data)))
(while alst
;; this is reversed, but were are sorting anyway
(setq newlist (cons (cons (car alst) (car ulst)) newlist))
(setq alst (cdr alst)
ulst (cdr ulst)))
;; 2 - Run sort routine on it
(setq newlist (sort newlist pred)
alst nil
ulst nil)
;; 3 - Separate the lists
(while newlist
(setq alst (cons (car (car newlist)) alst)
ulst (cons (cdr (car newlist)) ulst))
(setq newlist (cdr newlist)))
;; 4 - Store them back
(oset namelst data (reverse alst))
(oset numlst data (reverse ulst))))