1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-01 19:30:45 -08:00

Sort character ranges properly

Fix #85
This commit is contained in:
justbur 2015-11-17 21:50:55 -05:00
parent aa60a2364e
commit ef44d0771a

View file

@ -974,36 +974,40 @@ width) in lines and characters respectively."
(defun which-key--key-description< (a b &optional alpha)
"Sorting function used for `which-key-key-order' and
`which-key-key-order-alpha'."
(let* ((aem? (string-equal a ""))
(bem? (string-equal b ""))
(a1? (= 1 (length a)))
(b1? (= 1 (length b)))
(srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
(asp? (string-match-p srgxp a))
(bsp? (string-match-p srgxp b))
(prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
(apr? (string-match-p prrgxp a))
(bpr? (string-match-p prrgxp b))
(afn? (string-match-p "<f[0-9]+>" a))
(bfn? (string-match-p "<f[0-9]+>" b)))
(cond ((or aem? bem?) (and aem? (not bem?)))
((and asp? bsp?)
(if (string-equal (substring a 0 3) (substring b 0 3))
(which-key--key-description< (substring a 3) (substring b 3) alpha)
(string-lessp a b)))
((or asp? bsp?) asp?)
((and a1? b1?) (which-key--string< a b alpha))
((or a1? b1?) a1?)
((and afn? bfn?)
(< (string-to-number (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
(string-to-number (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
((or afn? bfn?) afn?)
((and apr? bpr?)
(if (string-equal (substring a 0 2) (substring b 0 2))
(which-key--key-description< (substring a 2) (substring b 2) alpha)
(string-lessp a b)))
((or apr? bpr?) apr?)
(t (string-lessp a b)))))
(save-match-data
(let* ((rngrgxp "^\\([^ ]+\\) \\.\\. [^ ]+")
(a (if (string-match rngrgxp a) (match-string 1 a) a))
(b (if (string-match rngrgxp b) (match-string 1 b) b))
(aem? (string-equal a ""))
(bem? (string-equal b ""))
(a1? (= 1 (length a)))
(b1? (= 1 (length b)))
(srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
(asp? (string-match-p srgxp a))
(bsp? (string-match-p srgxp b))
(prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
(apr? (string-match-p prrgxp a))
(bpr? (string-match-p prrgxp b))
(afn? (string-match-p "<f[0-9]+>" a))
(bfn? (string-match-p "<f[0-9]+>" b)))
(cond ((or aem? bem?) (and aem? (not bem?)))
((and asp? bsp?)
(if (string-equal (substring a 0 3) (substring b 0 3))
(which-key--key-description< (substring a 3) (substring b 3) alpha)
(string-lessp a b)))
((or asp? bsp?) asp?)
((and a1? b1?) (which-key--string< a b alpha))
((or a1? b1?) a1?)
((and afn? bfn?)
(< (string-to-number (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" a))
(string-to-number (replace-regexp-in-string "<f\\([0-9]+\\)>" "\\1" b))))
((or afn? bfn?) afn?)
((and apr? bpr?)
(if (string-equal (substring a 0 2) (substring b 0 2))
(which-key--key-description< (substring a 2) (substring b 2) alpha)
(string-lessp a b)))
((or apr? bpr?) apr?)
(t (string-lessp a b))))))
(defsubst which-key-key-order-alpha (acons bcons)
"Order key descriptions A and B.