From: Eshel Yaron Date: Sat, 30 Mar 2024 09:08:07 +0000 (+0100) Subject: ; Simplify many 'sort' invocations using new interface X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2b436991167938d04d3724670bdf4a8cc90249cb;p=emacs.git ; Simplify many 'sort' invocations using new interface --- diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 188eeb720c0..4be54c4a193 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -261,10 +261,7 @@ abbrevs have been saved." ;; user keeps their home directory in a revision ;; control system, and therefore keeps multiple ;; slightly-differing loosely synchronized copies. - (sort (copy-sequence abbrev-table-name-list) - (lambda (s1 s2) - (string< (symbol-name s1) - (symbol-name s2))))) + (sort (copy-sequence abbrev-table-name-list))) (if (abbrev--table-symbols table) (insert-abbrev-table-description table nil))) (when (unencodable-char-position (point-min) (point-max) 'utf-8) @@ -1158,7 +1155,7 @@ a call to `define-abbrev-table' that, when evaluated, will define the abbrev table NAME exactly as it is currently defined. Abbrevs marked as \"system abbrevs\" are ignored." (let ((symbols (abbrev--table-symbols name readable))) - (setq symbols (sort symbols 'string-lessp)) + (setq symbols (sort symbols)) (let ((standard-output (current-buffer))) (if readable (progn @@ -1247,8 +1244,7 @@ SORTFUN is passed to `sort' to change the default ordering." entries)))) table) (nconc (make-sparse-keymap prompt) - (sort entries (lambda (x y) - (funcall sortfun (nth 2 x) (nth 2 y))))))) + (sort entries :key #'caddr :lessp sortfun)))) (defface abbrev-table-name '((t :inherit font-lock-function-name-face)) diff --git a/lisp/allout-widgets.el b/lisp/allout-widgets.el index 7f5831d4124..3c7ffa6c8fe 100644 --- a/lisp/allout-widgets.el +++ b/lisp/allout-widgets.el @@ -964,8 +964,7 @@ Records changes in `allout-widgets-changes-record'." Generally invoked via `allout-exposure-change-functions'." - (let ((changes (sort changes (lambda (this next) - (< (cadr this) (cadr next))))) + (let ((changes (sort changes :key #'cadr)) ;; have to distinguish between concealing and exposing so that, eg, ;; `allout-expose-topic's mix is handled properly. handled-expose diff --git a/lisp/autoinsert.el b/lisp/autoinsert.el index 641016fb622..3a87c5610a4 100644 --- a/lisp/autoinsert.el +++ b/lisp/autoinsert.el @@ -176,7 +176,7 @@ If this contains a %s, that will be replaced by the matching rule." (let ((name (symbol-name mode))) (when (string-match "-mode\\'" name) (push name modes))))) - (sort modes 'string<))) + (sort modes))) (completing-read "Local variables for mode: " v1 nil t) " . ((" (let ((all-variables diff --git a/lisp/bindings.el b/lisp/bindings.el index d45c561bb65..34820d70adc 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -446,10 +446,8 @@ a menu, so this function is not useful for non-menu keymaps." map))) ;; Sort the bindings and make a new keymap from them. (setq bindings - (sort bindings - (lambda (a b) - (string< (bindings--menu-item-string (cdr-safe a)) - (bindings--menu-item-string (cdr-safe b)))))) + (sort bindings :key (compose #'bindings--menu-item-string + #'cdr-safe))) (nconc (make-sparse-keymap prompt) bindings))) (defvar mode-line-major-mode-keymap diff --git a/lisp/bookmark.el b/lisp/bookmark.el index e3feabde5c9..e8f7117678e 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -549,7 +549,7 @@ copy of the alist. Otherwise, just return `bookmark-alist', which by default is ordered from most recently created to least recently created bookmark." (let ((copy (copy-alist bookmark-alist))) (cond ((eq bookmark-sort-flag t) - (sort copy (lambda (x y) (string-lessp (car x) (car y))))) + (sort copy)) ((eq bookmark-sort-flag 'last-modified) (sort copy (lambda (x y) (let ((tx (bookmark-get-last-modified x)) diff --git a/lisp/bs.el b/lisp/bs.el index 9db93ea0423..d6b2d16608f 100644 --- a/lisp/bs.el +++ b/lisp/bs.el @@ -960,8 +960,7 @@ WHAT is a value of nil, `never', or `always'." "Set text properties for the sort described by SORT-DESCRIPTION. SORT-DESCRIPTION is an element of `bs-sort-functions'. Default is `bs--current-sort-function'." - (let ((sort-description (or sort-description - bs--current-sort-function))) + (let ((sort-description (or sort-description bs--current-sort-function))) (save-excursion (goto-char (point-min)) (when (and (nth 2 sort-description) diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el index a21efc0238d..0bc222d9a03 100644 --- a/lisp/calc/calc-aent.el +++ b/lisp/calc/calc-aent.el @@ -659,9 +659,8 @@ The value t means abort and give an error message.") (setq p (cdr p))) (setq calc-user-tokens (mapconcat 'identity (sort (mapcar #'car math-toks) - (lambda (x y) - (> (length x) - (length y)))) + :key #'length + :reverse t) "\\|") calc-last-main-parse-table mtab calc-last-user-lang-parse-table ltab diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el index 191149892a8..1a9ca69278e 100644 --- a/lisp/calc/calc-ext.el +++ b/lisp/calc/calc-ext.el @@ -1919,8 +1919,7 @@ calc-kill calc-kill-region calc-yank)))) (interactive) (let* ((calc-z-prefix-msgs nil) (calc-z-prefix-buf "") - (kmap (sort (copy-sequence (calc-user-key-map)) - (lambda (x y) (< (car x) (car y))))) + (kmap (sort (copy-sequence (calc-user-key-map)))) (flags (apply #'logior (mapcar (lambda (k) (calc-user-function-classify (car k))) diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el index c5d050444e3..cd261832dc4 100644 --- a/lisp/calc/calc-forms.el +++ b/lisp/calc/calc-forms.el @@ -1994,7 +1994,7 @@ and ends on the last Sunday of October at 2 a.m." (setq math-holidays-cache (list (list -1) ; 0: days list (list -1) ; 1: inverse-days list nil ; 2: exprs - (sort weekdays '<) + (sort weekdays) (or limit '(intv 3 1 2737)) nil ; 5: (lo.hi) expanded years (cons exprs days) diff --git a/lisp/calc/calc-graph.el b/lisp/calc/calc-graph.el index fb817b1bc3d..c355b37346c 100644 --- a/lisp/calc/calc-graph.el +++ b/lisp/calc/calc-graph.el @@ -751,7 +751,7 @@ (let ((math-arglist nil)) (setq calc-graph-yvalue (math-evaluate-expr calc-graph-yvalue)) (calc-default-formula-arglist calc-graph-yvalue) - (setq math-arglist (sort math-arglist 'string-lessp)) + (setq math-arglist (sort math-arglist)) (or (cdr math-arglist) (error "%s does not contain enough unassigned variables" calc-graph-yname)) (and (cdr (cdr math-arglist)) diff --git a/lisp/calc/calc-help.el b/lisp/calc/calc-help.el index 6ba49137b73..9f7a222340e 100644 --- a/lisp/calc/calc-help.el +++ b/lisp/calc/calc-help.el @@ -265,8 +265,7 @@ (while (string-match "," notes) (aset notes (match-beginning 0) ? )) (setq notes (sort (car (read-from-string - (format "(%s)" notes))) - '<)) + (format "(%s)" notes))))) (with-output-to-temp-buffer "*Help*" (princ (format "%s\n\n" msg)) (set-buffer "*Calc Summary*") diff --git a/lisp/calc/calc-map.el b/lisp/calc/calc-map.el index f8dad435c75..b1716d0b100 100644 --- a/lisp/calc/calc-map.el +++ b/lisp/calc/calc-map.el @@ -603,7 +603,7 @@ (progn (calc-default-formula-arglist expr) (setq record-entry t - math-arglist (sort math-arglist 'string-lessp)) + math-arglist (sort math-arglist)) (if calc-verify-arglist (setq math-arglist (read-from-minibuffer "Function argument list: " diff --git a/lisp/calc/calc-poly.el b/lisp/calc/calc-poly.el index c5a7ee66cc8..2e148bfbc6d 100644 --- a/lisp/calc/calc-poly.el +++ b/lisp/calc/calc-poly.el @@ -201,8 +201,7 @@ "Sort the terms of a sum into canonical order." (if (memq (car-safe expr) '(+ -)) (math-list-to-sum - (sort (math-sum-to-list expr) - (lambda (a b) (math-beforep (car a) (car b))))) + (sort (math-sum-to-list expr) :key #'car :lessp #'math-beforep)) expr)) (defun math-list-to-sum (lst) diff --git a/lisp/calc/calc-prog.el b/lisp/calc/calc-prog.el index 8dff7f1f264..d5430203a72 100644 --- a/lisp/calc/calc-prog.el +++ b/lisp/calc/calc-prog.el @@ -186,7 +186,7 @@ (nreverse (cdr (reverse (cdr form))))) form (nth (1- (length form)) form)) (calc-default-formula-arglist form) - (setq math-arglist (sort math-arglist 'string-lessp))) + (setq math-arglist (sort math-arglist))) (message "Define user key: z-") (setq key (read-char)) (if (= (calc-user-function-classify key) 0) @@ -404,7 +404,7 @@ (if (setq entry (assq calc-language comps)) (put func 'math-compose-forms (delq entry comps))) (calc-default-formula-arglist comp) - (setq math-arglist (sort math-arglist 'string-lessp)) + (setq math-arglist (sort math-arglist)) (while (progn (setq calc-user-formula-alist diff --git a/lisp/calc/calc-rewr.el b/lisp/calc/calc-rewr.el index cc70ded17c2..cf5742ef712 100644 --- a/lisp/calc/calc-rewr.el +++ b/lisp/calc/calc-rewr.el @@ -722,9 +722,7 @@ (setq rules (cdr rules))) (if nil-rules (setq rule-set (cons (cons nil nil-rules) rule-set))) - (setq all-heads (mapcar #'car - (sort all-heads (lambda (x y) - (< (cdr x) (cdr y)))))) + (setq all-heads (mapcar #'car (sort all-heads :key #'cdr))) (let ((set rule-set) rule heads ptr) (while set @@ -744,7 +742,7 @@ (setq rule-set (cons (cons '- (cdr plus)) rule-set)))) (cons (list 'schedule math-iterations name (or math-schedule - (sort math-all-phases '<) + (sort math-all-phases) (list 1))) rule-set)))) diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index fba2b9c50fb..1449b98b084 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el @@ -1109,9 +1109,7 @@ If COMP or STD is non-nil, put that in the units table instead." (setq math-decompose-units-cache (cons entry (sort ulist - (lambda (x y) - (not (Math-lessp (nth 1 x) - (nth 1 y))))))))) + :key #'cadr :lessp #'Math-lessp :reverse t))))) (cdr math-decompose-units-cache)))) (defun math-decompose-unit-part (unit) diff --git a/lisp/calc/calcalg3.el b/lisp/calc/calcalg3.el index 26952b8b10c..88d01df6920 100644 --- a/lisp/calc/calcalg3.el +++ b/lisp/calc/calcalg3.el @@ -1910,8 +1910,7 @@ (while p (setq vars (delq (assoc (car-safe p) vars) vars) p (cdr p))) - (sort (mapcar #'car vars) - (lambda (x y) (string< (nth 1 x) (nth 1 y)))))) + (sort (mapcar #'car vars) :key #'cadr))) ;; The variables math-all-vars-vars (the vars for math-all-vars) and ;; math-all-vars-found are local to math-all-vars-in, but are used by diff --git a/lisp/calendar/appt.el b/lisp/calendar/appt.el index 7572e706283..69c09a76e3a 100644 --- a/lisp/calendar/appt.el +++ b/lisp/calendar/appt.el @@ -667,7 +667,7 @@ Any appointments made with `appt-add' are not affected by this function." (defun appt-sort-list (appt-list) "Sort an appointment list, putting earlier items at the front. APPT-LIST is a list of the same format as `appt-time-msg-list'." - (sort appt-list (lambda (e1 e2) (< (caar e1) (caar e2))))) + (sort appt-list :key #'caar)) (defun appt-convert-time (time2conv) diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index d7e62e1baf3..b8d5862f8c2 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -591,7 +591,7 @@ ALIST is a VTIMEZONE potentially containing historical records." (and (memq (car p) '(DTSTART RDATE)) (car (cddr p)))) n)) - 'string-greaterp)))) + :reverse t)))) (a-recent (funcall get-recent (car (cddr a)))) (b-recent (funcall get-recent (car (cddr b))))) (string-greaterp a-recent b-recent)))))))) @@ -1223,7 +1223,7 @@ Returns an alist." (p-sta (or (string-match "%t" icalendar-import-format) -1)) (p-url (or (string-match "%u" icalendar-import-format) -1)) (p-uid (or (string-match "%U" icalendar-import-format) -1)) - (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url p-uid) '<)) + (p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url p-uid))) (ct 0) pos-cla pos-des pos-loc pos-org pos-sta pos-url pos-uid) ;pos-sum (dotimes (i (length p-list)) diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 12287299a7f..a3fb3c32b27 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el @@ -76,9 +76,7 @@ truenames (those with the extension \".toda\")." (mapcar #'file-truename (directory-files todo-directory t (if archives "\\.toda\\'" "\\.todo\\'") t))))) - (sort files (lambda (s1 s2) (let ((cis1 (upcase s1)) - (cis2 (upcase s2))) - (string< cis1 cis2)))))) + (sort files :key #'upcase))) (defcustom todo-files-function #'todo-files "Function returning the value of the variable `todo-files'. diff --git a/lisp/cedet/ede/pmake.el b/lisp/cedet/ede/pmake.el index e6d989946db..e69660a9d69 100644 --- a/lisp/cedet/ede/pmake.el +++ b/lisp/cedet/ede/pmake.el @@ -468,7 +468,7 @@ These are removed with make clean." (let ((mc (ede-map-targets this #'ede-proj-makefile-garbage-patterns)) (uniq nil)) - (setq mc (sort (apply #'append mc) #'string<)) + (setq mc (sort (apply #'append mc))) ;; Filter out duplicates from the targets. (while mc (if (and (car uniq) (string= (car uniq) (car mc))) diff --git a/lisp/cedet/semantic/chart.el b/lisp/cedet/semantic/chart.el index a87ae19ee0c..dc3e84d9a31 100644 --- a/lisp/cedet/semantic/chart.el +++ b/lisp/cedet/semantic/chart.el @@ -83,7 +83,7 @@ TAGTABLE is passed to `semantic-something-to-tag-table'." dbt)) (nums nil) (fh (/ (- (frame-height) 7) 4))) - (setq numnuts (sort numnuts (lambda (a b) (> (car a) (car b))))) + (setq numnuts (sort numnuts :reverse t)) (setq names (mapcar #'cdr numnuts) nums (mapcar #'car numnuts)) (if (> (length names) fh) @@ -125,7 +125,7 @@ items are charted. TAGTABLE is passed to (namelabel (cdr (assoc 'function semantic-symbol->name-assoc-list))) (names nil) (nums nil)) - (setq cplx (sort cplx (lambda (a b) (> (cdr a) (cdr b))))) + (setq cplx (sort cplx :key #'cdr :reverse t)) (while (and cplx (<= (length names) (/ (- (frame-height) 7) 4))) (setq names (cons (semantic-tag-name (car (car cplx))) names) diff --git a/lisp/cedet/semantic/edit.el b/lisp/cedet/semantic/edit.el index 9dfb96f1fa1..d1c01e2670b 100644 --- a/lisp/cedet/semantic/edit.el +++ b/lisp/cedet/semantic/edit.el @@ -144,8 +144,7 @@ Optional argument BUFFER is the buffer to search for changes in." (when (overlay-get (car ol) 'semantic-change) (setq ret (cons (car ol) ret))) (setq ol (cdr ol))) - (sort ret (lambda (a b) (< (overlay-start a) - (overlay-start b))))))) + (sort ret :key #'overlay-start)))) (defun semantic-edits-change-function-handle-changes (start end _length) "Run whenever a buffer controlled by `semantic-mode' change. diff --git a/lisp/cedet/semantic/find.el b/lisp/cedet/semantic/find.el index 14fbcbc00f8..befe36320bd 100644 --- a/lisp/cedet/semantic/find.el +++ b/lisp/cedet/semantic/find.el @@ -80,8 +80,7 @@ from largest to smallest via the start location." (semantic-tag-p tmp)) (setq ret (cons tmp ret)))) (setq ol (cdr ol))) - (sort ret (lambda (a b) (< (semantic-tag-start a) - (semantic-tag-start b))))))) + (sort ret :key #'semantic-tag-start)))) ;;;###autoload (defun semantic-find-tag-by-overlay-in-region (start end &optional buffer) @@ -99,8 +98,7 @@ Optional BUFFER argument specifies the buffer to use." (semantic-tag-p tmp)) (setq ret (cons tmp ret)))) (setq ol (cdr ol))) - (sort ret (lambda (a b) (< (semantic-tag-start a) - (semantic-tag-start b))))))) + (sort ret :key #'semantic-tag-start)))) ;;;###autoload (defun semantic-find-tag-by-overlay-next (&optional start buffer) diff --git a/lisp/cedet/semantic/sort.el b/lisp/cedet/semantic/sort.el index 5e2dca03f64..2073d573ac6 100644 --- a/lisp/cedet/semantic/sort.el +++ b/lisp/cedet/semantic/sort.el @@ -90,68 +90,56 @@ each tag." (defun semantic-sort-tags-by-name-increasing (tags) "Sort TAGS by name in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (string-lessp (semantic-tag-name a) - (semantic-tag-name b))))) + (sort tags :key #'semantic-tag-name)) (defun semantic-sort-tags-by-name-decreasing (tags) "Sort TAGS by name in decreasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (string-lessp (semantic-tag-name b) - (semantic-tag-name a))))) + (sort tags :key #'semantic-tag-name :reverse t)) (defun semantic-sort-tags-by-type-increasing (tags) "Sort TAGS by type in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (string-lessp (semantic-sort-tag-type a) - (semantic-sort-tag-type b))))) + (sort tags :key #'semantic-sort-tag-type)) (defun semantic-sort-tags-by-type-decreasing (tags) "Sort TAGS by type in decreasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (string-lessp (semantic-sort-tag-type b) - (semantic-sort-tag-type a))))) + (sort tags :key #'semantic-sort-tag-type :reverse t)) (defun semantic-sort-tags-by-name-increasing-ci (tags) "Sort TAGS by name in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (semantic-string-lessp-ci (semantic-tag-name a) - (semantic-tag-name b))))) + (sort tags :key #'semantic-tag-name :lessp #'semantic-string-lessp-ci)) (defun semantic-sort-tags-by-name-decreasing-ci (tags) "Sort TAGS by name in decreasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (semantic-string-lessp-ci (semantic-tag-name b) - (semantic-tag-name a))))) + (sort tags + :key #'semantic-tag-name :lessp #'semantic-string-lessp-ci + :reverse t)) (defun semantic-sort-tags-by-type-increasing-ci (tags) "Sort TAGS by type in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (semantic-string-lessp-ci (semantic-sort-tag-type a) - (semantic-sort-tag-type b))))) + (sort tags :key #'semantic-sort-tag-type :lessp #'semantic-string-lessp-ci)) (defun semantic-sort-tags-by-type-decreasing-ci (tags) "Sort TAGS by type in decreasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) - (semantic-string-lessp-ci (semantic-sort-tag-type b) - (semantic-sort-tag-type a))))) + (sort tags + :key #'semantic-sort-tag-type :lessp #'semantic-string-lessp-ci + :reverse t)) (defun semantic-sort-tags-by-name-then-type-increasing (tags) "Sort TAGS by name, then type in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) (semantic-tag-lessp-name-then-type a b)))) + (sort tags #'semantic-tag-lessp-name-then-type)) (defun semantic-sort-tags-by-name-then-type-decreasing (tags) "Sort TAGS by name, then type in increasing order with side effects. Return the sorted list." - (sort tags (lambda (a b) (semantic-tag-lessp-name-then-type b a)))) + (sort tags #'semantic-tag-lessp-name-then-type)) ;;; Unique ;; diff --git a/lisp/cedet/semantic/util.el b/lisp/cedet/semantic/util.el index f3c33c16ebc..49be2e9e104 100644 --- a/lisp/cedet/semantic/util.el +++ b/lisp/cedet/semantic/util.el @@ -427,7 +427,7 @@ determining which symbols are considered." (setq completion (try-completion pattern collection predicate)) (if (string= pattern completion) (let ((list (all-completions pattern collection predicate))) - (setq list (sort list #'string<)) + (setq list (sort list)) (if (> (length list) 1) (with-output-to-temp-buffer "*Completions*" (display-completion-list diff --git a/lisp/comint.el b/lisp/comint.el index a8fe095e99c..83cb996e355 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -3473,7 +3473,7 @@ specifying a common substring for adding the faces `completions-first-difference' and `completions-common-part' to the completions." (let ((window (get-buffer-window "*Completions*" 0))) - (setq completions (sort completions 'string-lessp)) + (setq completions (sort completions)) (if (and (eq last-command this-command) window (window-live-p window) (window-buffer window) (buffer-name (window-buffer window)) diff --git a/lisp/cus-dep.el b/lisp/cus-dep.el index 55965841a76..b8b32693948 100644 --- a/lisp/cus-dep.el +++ b/lisp/cus-dep.el @@ -172,9 +172,9 @@ Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" (when found (push (cons (symbol-name symbol) (with-output-to-string - (prin1 (sort found #'string<)))) + (prin1 (sort found)))) alist)))))) - (dolist (e (sort alist (lambda (e1 e2) (string< (car e1) (car e2))))) + (dolist (e (sort alist)) (insert "(custom--add-custom-loads '" (car e) " '" (cdr e) ")\n"))) (insert "\ @@ -223,7 +223,7 @@ Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" (with-output-to-string (prin1 (get symbol 'custom-tag))))) groups))))))) - (dolist (e (sort groups (lambda (e1 e2) (string< (car e1) (car e2))))) + (dolist (e (sort groups)) (insert "(custom-put-if-not '" (car e) " 'custom-version '" (nth 1 e) ")\n") (insert "(custom-put-if-not '" (car e) " 'group-documentation " @@ -234,7 +234,7 @@ Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS" (insert "\n(defvar custom-versions-load-alist " (if version-alist "'" "")) - (prin1 (sort version-alist (lambda (e1 e2) (version< (car e1) (car e2)))) + (prin1 (sort version-alist :key #'car :lessp #'version<) (current-buffer)) (insert "\n \"For internal use by custom. This is an alist whose members have as car a version string, and as diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 0348bff2f56..18ca3ee3c83 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -5076,7 +5076,7 @@ This function does not save the buffer." (or (null (get symbol 'theme-value)) (eq 'user (caar (get symbol 'theme-value))))) (nconc saved-list (list symbol))))) - (setq saved-list (sort (cdr saved-list) 'string<)) + (setq saved-list (sort (cdr saved-list))) (unless (bolp) (princ "\n")) (princ "(custom-set-variables @@ -5156,7 +5156,7 @@ This function does not save the buffer." (if (and (get symbol 'saved-face) (eq 'user (car (car-safe (get symbol 'theme-face))))) (nconc saved-list (list symbol))))) - (setq saved-list (sort (cdr saved-list) 'string<)) + (setq saved-list (sort (cdr saved-list))) ;; The default face must be first, since it affects the others. (if (memq 'default saved-list) (setq saved-list (cons 'default (delq 'default saved-list)))) @@ -5804,8 +5804,7 @@ This stores EXP (without evaluating it) as the saved spec for SYMBOL." ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right.\n") - (dolist (value (sort values (lambda (s1 s2) - (string< (car s1) (car s2))))) + (dolist (value (sort values)) (unless (bolp) (insert "\n")) (insert " '") diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el index 63eba4b9991..6305540f691 100644 --- a/lisp/dabbrev.el +++ b/lisp/dabbrev.el @@ -408,7 +408,7 @@ then it searches *all* buffers." (table (lambda (s p a) (if (eq a 'metadata) - `(metadata (sort-function . ,#'identity) + '(metadata (sort-function . identity) (category . dabbrev)) (when (eq list 'uninitialized) (save-excursion diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 0b2e4e43c64..2b716b0b5b6 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -693,7 +693,7 @@ with a prefix argument." ;; and remove the versions not to be deleted. (let ((fval dired-file-version-alist)) (while fval - (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<))) + (let* ((sorted-v-list (cons 'q (sort (cdr (car fval))))) (v-count (length sorted-v-list))) (if (> v-count (+ early-retention late-retention)) (rplacd (nthcdr early-retention sorted-v-list) @@ -2720,7 +2720,7 @@ Optional arg HOW-TO determines how to treat the target. (dired-current-directory)))))) (delq (selected-window) (window-list-1 nil 'nomini 'visible))) - (lambda (a b) (> (car a) (car b)))))) + :reverse t))) (defun dired-dwim-target-directory () ;; Try to guess which target directory the user may want. @@ -3317,10 +3317,7 @@ This function takes some pains to conform to `ls -lR' output." (defun dired-alist-sort () ;; Keep the alist sorted on buffer position. (setq dired-subdir-alist - (sort dired-subdir-alist - (lambda (elt1 elt2) - (> (cdr elt1) - (cdr elt2)))))) + (sort dired-subdir-alist :key #'cdr :reverse t))) (defun dired-kill-tree (dirname &optional remember-marks kill-root) "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself. diff --git a/lisp/dnd.el b/lisp/dnd.el index 1fc1ab45b84..f7eb074076e 100644 --- a/lisp/dnd.el +++ b/lisp/dnd.el @@ -230,9 +230,7 @@ for it will be modified." ;; While unassessed handlers still exist... (while list ;; Sort list by the number of URLs assigned to each handler. - (setq list (sort list (lambda (first second) - (> (length (cdr first)) - (length (cdr second)))))) + (setq list (sort list :key (compose #'length #'cdr) :reverse t)) ;; Call the handler in its car before removing each URL from ;; URLs. (let ((handler (caar list)) diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index cc176821026..76e0a4fe11b 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -690,7 +690,7 @@ read, return an appropriate warning message as a string. Otherwise, return nil. For internal use only." ;; This is called from lread.c and therefore needs to be preloaded. (if lread--unescaped-character-literals - (let ((sorted (sort lread--unescaped-character-literals #'<))) + (let ((sorted (sort lread--unescaped-character-literals))) (format "unescaped character literals %s detected, %s expected!" (mapconcat (lambda (char) (format-message "`?%c'" char)) sorted ", ") diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el index 248fd8b7d57..5b497b1bd26 100644 --- a/lisp/emacs-lisp/cl-generic.el +++ b/lisp/emacs-lisp/cl-generic.el @@ -628,9 +628,8 @@ The set of acceptable TYPEs (also called \"specializers\") is defined (unless (member generalizer (cdr x)) (setf (cdr x) (sort (cons generalizer (cdr x)) - (lambda (x y) - (> (cl--generic-generalizer-priority x) - (cl--generic-generalizer-priority y))))))) + :key #'cl--generic-generalizer-priority + :reverse t)))) (setq i (1+ i)))) ;; We used to (setcar me method), but that can cause false positives in ;; the hash-consing table of the method-builder (bug#20644). diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el index cbfb9540f03..718217c38ac 100644 --- a/lisp/emacs-lisp/comp-cstr.el +++ b/lisp/emacs-lisp/comp-cstr.el @@ -344,8 +344,7 @@ Return them as multiple value." ;; "most general" to "least general" with typess = (sort (mapcar #'comp-supertypes (apply #'append typesets)) - (lambda (l1 l2) - (<= (length l1) (length l2)))) + :key #'length :lessp #'<=) with res = '() for types in typess ;; Don't keep this type if it's a subtype of one of diff --git a/lisp/emacs-lisp/eieio-opt.el b/lisp/emacs-lisp/eieio-opt.el index bf6be1690e4..08def2b0fbd 100644 --- a/lisp/emacs-lisp/eieio-opt.el +++ b/lisp/emacs-lisp/eieio-opt.el @@ -170,9 +170,7 @@ are not abstract." "Display a list of all the methods and what features are used." (interactive) (let* ((meth1 (cl-generic-all-functions)) - (meth (sort meth1 (lambda (a b) - (string< (symbol-name a) - (symbol-name b))))) + (meth (sort meth1)) (buff (get-buffer-create "*EIEIO Method List*")) (methidx 0) (standard-output buff) diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 24afd03fbe6..1a7dad4e026 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -900,8 +900,7 @@ the docstrings eventually produced, using (run-hook-with-args 'eldoc-display-functions (mapcar #'cdr (setq docs-registered - (sort docs-registered - (lambda (a b) (< (car a) (car b)))))) + (sort docs-registered))) interactive)) (make-callback (method origin) diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 8ab57d2b238..0f66cca2ca4 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -1800,7 +1800,7 @@ Ran \\([0-9]+\\) tests, \\([0-9]+\\) results as expected\ (unless (or (null tests) (zerop high)) (message "\nLONG-RUNNING TESTS") (message "------------------") - (setq tests (ntake high (sort tests (lambda (x y) (> (car x) (car y)))))) + (setq tests (ntake high (sort tests :reverse t))) (message "%s" (mapconcat #'cdr tests "\n"))) ;; More details on hydra and emba, where the logs are harder to get to. (when (and (or (getenv "EMACS_HYDRA_CI") (getenv "EMACS_EMBA_CI")) @@ -2771,8 +2771,7 @@ To be used in the ERT results buffer." collect (list test (float-time (time-subtract end-time start-time)))))) - (setq data (sort data (lambda (a b) - (> (cl-second a) (cl-second b))))) + (setq data (sort data :key #'cadr :reverse t)) (pop-to-buffer buffer) (let ((inhibit-read-only t)) (buffer-disable-undo) diff --git a/lisp/subr.el b/lisp/subr.el index 31610832ab9..94529ed959a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7577,4 +7577,14 @@ and return the value found in PLACE instead." ,(funcall setter val) ,val))))) +(defun compose (&rest funs) + "Return the function composition of FUNS. + +For example, (compose #\\='car #\\='car #\\='cdr) returns a function +that does the same thing as `caadr'." + (if funs + (lambda (x) + (funcall (car funs) (funcall (apply #'compose (cdr funs)) x))) + #'identity)) + ;;; subr.el ends here