diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2026-01-04 12:08:45 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2026-01-04 12:08:45 +0100 |
| commit | fb338f771f1693436da0472a8a4d230b28af14f3 (patch) | |
| tree | 330a11c8fb342ac4d45b75c307e0e854dffb9436 | |
| parent | aba87f2576e1d61e8f60ce8acdf6aca5c2da370c (diff) | |
Use when-let*
| -rw-r--r-- | orderless-kwd.el | 76 | ||||
| -rw-r--r-- | orderless.el | 18 |
2 files changed, 48 insertions, 46 deletions
diff --git a/orderless-kwd.el b/orderless-kwd.el index 6341819..9624080 100644 --- a/orderless-kwd.el +++ b/orderless-kwd.el @@ -39,7 +39,9 @@ ;;; Code: (require 'orderless) -(eval-when-compile (require 'cl-lib)) +(eval-when-compile + (require 'cl-lib) + (require 'subr-x)) (defcustom orderless-kwd-prefix ?: "Keyword dispatcher prefix character." @@ -85,7 +87,7 @@ as a flag and does not require input." (defsubst orderless-kwd--get-buffer (str) "Return buffer from candidate STR taking `multi-category' into account." - (when-let ((cat (get-text-property 0 'multi-category str))) + (when-let* ((cat (get-text-property 0 'multi-category str))) (setq str (and (eq (car cat) 'buffer) (cdr cat)))) (and str (get-buffer str))) @@ -96,20 +98,20 @@ as a flag and does not require input." (defun orderless-kwd-category (pred regexp) "Match candidate category against PRED and REGEXP." (lambda (str) - (when-let ((cat (car (get-text-property 0 'multi-category str)))) + (when-let* ((cat (car (get-text-property 0 'multi-category str)))) (orderless--match-p pred regexp (symbol-name cat))))) (defun orderless-kwd-group (pred regexp) "Match candidate group title against PRED and REGEXP." - (when-let ((fun (compat-call completion-metadata-get - (orderless--metadata) 'group-function))) + (when-let* ((fun (compat-call completion-metadata-get + (orderless--metadata) 'group-function))) (lambda (str) (orderless--match-p pred regexp (funcall fun str nil))))) (defun orderless-kwd-content (_pred regexp) "Match buffer content against REGEXP." (lambda (str) - (when-let ((buf (orderless-kwd--get-buffer str))) + (when-let* ((buf (orderless-kwd--get-buffer str))) (with-current-buffer buf (save-excursion (save-restriction @@ -120,7 +122,7 @@ as a flag and does not require input." (defun orderless-kwd-documentation (pred regexp) "Match documentation against PRED and REGEXP." (lambda (str) - (when-let ((sym (orderless-kwd--get-symbol str))) + (when-let* ((sym (orderless-kwd--get-symbol str))) (orderless--match-p pred regexp (or (ignore-errors (documentation sym)) @@ -134,9 +136,9 @@ as a flag and does not require input." "Match command key binding against PRED and REGEXP." (let ((buf (orderless-kwd--orig-buffer))) (lambda (str) - (when-let ((sym (orderless-kwd--get-symbol str)) - ((fboundp sym)) - (keys (with-current-buffer buf (where-is-internal sym)))) + (when-let* ((sym (orderless-kwd--get-symbol str)) + ((fboundp sym)) + (keys (with-current-buffer buf (where-is-internal sym)))) (cl-loop for key in keys thereis (orderless--match-p pred regexp (key-description key))))))) @@ -145,18 +147,18 @@ as a flag and does not require input." "Match variable value against PRED and REGEXP." (let ((buf (orderless-kwd--orig-buffer))) (lambda (str) - (when-let ((sym (intern-soft str)) - ((boundp sym))) - (let ((print-level 10) - (print-length 1000)) - (orderless--match-p - pred regexp (prin1-to-string (buffer-local-value sym buf)))))))) + (when-let* ((sym (intern-soft str)) + ((boundp sym)) + (print-level 10) + (print-length 1000)) + (orderless--match-p + pred regexp (prin1-to-string (buffer-local-value sym buf))))))) (defun orderless-kwd-off (_) "Match disabled minor modes." (let ((buf (orderless-kwd--orig-buffer))) (lambda (str) - (when-let ((sym (orderless-kwd--get-symbol str))) + (when-let* ((sym (orderless-kwd--get-symbol str))) (and (boundp sym) (memq sym minor-mode-list) (not (buffer-local-value sym buf))))))) @@ -165,7 +167,7 @@ as a flag and does not require input." "Match enabled minor modes." (let ((buf (orderless-kwd--orig-buffer))) (lambda (str) - (when-let ((sym (orderless-kwd--get-symbol str))) + (when-let* ((sym (orderless-kwd--get-symbol str))) (and (boundp sym) (memq sym minor-mode-list) (buffer-local-value sym buf)))))) @@ -173,32 +175,32 @@ as a flag and does not require input." (defun orderless-kwd-modified (_) "Match modified buffers." (lambda (str) - (when-let ((buf (orderless-kwd--get-buffer str))) + (when-let* ((buf (orderless-kwd--get-buffer str))) (buffer-modified-p buf)))) (defun orderless-kwd-read-only (_) "Match read-only buffers." (lambda (str) - (when-let ((buf (orderless-kwd--get-buffer str))) + (when-let* ((buf (orderless-kwd--get-buffer str))) (buffer-local-value 'buffer-read-only buf)))) (defun orderless-kwd-mode (pred regexp) "Match buffer mode or bookmark type against PRED and REGEXP." (declare-function bookmark-prop-get "bookmark") (lambda (str) - (if-let ((buf (orderless-kwd--get-buffer str))) - (when-let ((mode (buffer-local-value 'major-mode buf))) + (if-let* ((buf (orderless-kwd--get-buffer str))) + (when-let* ((mode (buffer-local-value 'major-mode buf))) (or (orderless--match-p pred regexp (symbol-name mode)) (orderless--match-p pred regexp (format-mode-line (buffer-local-value 'mode-name buf))))) - (when-let ((name (if-let ((cat (get-text-property 0 'multi-category str))) + (when-let* ((name (if-let* ((cat (get-text-property 0 'multi-category str))) (and (eq (car cat) 'bookmark) (cdr cat)) str)) - (bm (assoc name (bound-and-true-p bookmark-alist))) - (handler (or (bookmark-prop-get bm 'handler) - 'bookmark-default-handler)) - ((symbolp handler))) + (bm (assoc name (bound-and-true-p bookmark-alist))) + (handler (or (bookmark-prop-get bm 'handler) + 'bookmark-default-handler)) + ((symbolp handler))) (orderless--match-p pred regexp (or (get handler 'bookmark-handler-type) (symbol-name handler))))))) @@ -206,14 +208,14 @@ as a flag and does not require input." (defun orderless-kwd-directory (pred regexp) "Match `default-directory' against PRED and REGEXP." (lambda (str) - (when-let ((buf (orderless-kwd--get-buffer str))) + (when-let* ((buf (orderless-kwd--get-buffer str))) (orderless--match-p pred regexp (buffer-local-value 'default-directory buf))))) (defun orderless-kwd-file (pred regexp) "Match `buffer-file-truename' against PRED and REGEXP." (lambda (str) - (when-let ((buf (orderless-kwd--get-buffer str))) + (when-let* ((buf (orderless-kwd--get-buffer str))) (orderless--match-p pred regexp (buffer-local-value 'buffer-file-truename buf))))) @@ -222,14 +224,14 @@ as a flag and does not require input." "Match COMPONENT against the keywords in `orderless-kwd-alist'." (when (and (not (equal component "")) (= (aref component 0) orderless-kwd-prefix)) - (if-let ((len (length component)) - (pos (or (string-match-p - (rx-to-string `(any ,orderless-kwd-separator)) - component 1) - len)) - (sym (intern-soft (substring component 1 pos))) - (style (alist-get sym orderless-kwd-alist)) - ((or (< (1+ pos) len) (cadr style)))) + (if-let* ((len (length component)) + (pos (or (string-match-p + (rx-to-string `(any ,orderless-kwd-separator)) + component 1) + len)) + (sym (intern-soft (substring component 1 pos))) + (style (alist-get sym orderless-kwd-alist)) + ((or (< (1+ pos) len) (cadr style)))) (cons (car style) (substring component (min (1+ pos) len))) #'ignore))) diff --git a/orderless.el b/orderless.el index 4cd03da..fd72a61 100644 --- a/orderless.el +++ b/orderless.el @@ -173,10 +173,10 @@ style associated to the character." ;; Ignore single dispatcher character ((and (= len 1) (alist-get (aref component 0) alist)) #'ignore) ;; Prefix - ((when-let ((style (alist-get (aref component 0) alist))) + ((when-let* ((style (alist-get (aref component 0) alist))) (cons style (substring component 1)))) ;; Suffix - ((when-let ((style (alist-get (aref component (1- len)) alist))) + ((when-let* ((style (alist-get (aref component (1- len)) alist))) (cons style (substring component 0 -1)))))))) (defcustom orderless-style-dispatchers (list #'orderless-affix-dispatch) @@ -312,8 +312,8 @@ which can invert any predicate or regexp." (defun orderless--metadata () "Return completion metadata iff inside minibuffer." - (when-let (((minibufferp)) - (table minibuffer-completion-table)) + (when-let* (((minibufferp)) + (table minibuffer-completion-table)) ;; Return non-nil metadata iff inside minibuffer (or (completion-metadata (buffer-substring-no-properties (minibuffer-prompt-end) (point)) @@ -323,11 +323,11 @@ which can invert any predicate or regexp." (defun orderless-annotation (pred regexp) "Match candidates where the annotation matches PRED and REGEXP." (let ((md (orderless--metadata))) - (if-let ((fun (compat-call completion-metadata-get md 'affixation-function))) + (if-let* ((fun (compat-call completion-metadata-get md 'affixation-function))) (lambda (str) (cl-loop for s in (cdar (funcall fun (list str))) thereis (orderless--match-p pred regexp s))) - (when-let ((fun (compat-call completion-metadata-get md 'annotation-function))) + (when-let* ((fun (compat-call completion-metadata-get md 'annotation-function))) (lambda (str) (orderless--match-p pred regexp (funcall fun str))))))) ;;; Highlighting matches @@ -425,8 +425,8 @@ DEFAULT as the list of styles." for res = (condition-case nil (funcall style newcomp) (wrong-number-of-arguments - (when-let ((res (orderless--compile-component - newcomp index total styles dispatchers))) + (when-let* ((res (orderless--compile-component + newcomp index total styles dispatchers))) (funcall style (car res) (cdr res))))) if (functionp res) do (cl-callf orderless--predicate-and pred res) else if res collect (if (stringp res) `(regexp ,res) res) into regexps @@ -553,7 +553,7 @@ matching portions of each candidate are highlighted. This function is part of the `orderless' completion style." (pcase-let ((`(,prefix ,regexps ,ignore-case ,pred) (orderless--compile string table pred))) - (when-let ((completions (orderless--filter prefix regexps ignore-case table pred))) + (when-let* ((completions (orderless--filter prefix regexps ignore-case table pred))) (if completion-lazy-hilit (setq completion-lazy-hilit-fn (apply-partially #'orderless--highlight regexps ignore-case)) |
