branch: externals/marginalia
commit fc0cee1151fced42db6014e1d29a61ed63de81d9
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>
Use when-let*
---
marginalia.el | 158 +++++++++++++++++++++++++++++-----------------------------
1 file changed, 79 insertions(+), 79 deletions(-)
diff --git a/marginalia.el b/marginalia.el
index 6300614510..cc6a8d8eab 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -386,7 +386,7 @@ for performance profiling of the annotators.")
(defun marginalia--truncate (str width)
"Truncate string STR to WIDTH."
(when (floatp width) (setq width (round (* width marginalia-field-width))))
- (when-let (pos (string-search "\n" str))
+ (when-let* ((pos (string-search "\n" str)))
(setq str (substring str 0 pos)))
(let* ((face (and (not (equal str ""))
(get-text-property (1- (length str)) 'face str)))
@@ -449,8 +449,8 @@ Otherwise stay within current buffer."
(defun marginalia-annotate-binding (cand)
"Annotate command CAND with keybinding."
- (when-let ((sym (intern-soft cand))
- (key (and (commandp sym) (where-is-internal sym nil
'first-only))))
+ (when-let* ((sym (intern-soft cand))
+ (key (and (commandp sym) (where-is-internal sym nil
'first-only))))
(format #(" (%s)" 1 5 (face marginalia-key)) (key-description key))))
(defun marginalia--annotator (cat)
@@ -471,8 +471,8 @@ Otherwise stay within current buffer."
(if-let* ((fun (marginalia--orig-completion-metadata-get
marginalia--metadata 'affixation-function)))
(caddar (funcall fun (list cand)))
- (when-let ((fun (marginalia--orig-completion-metadata-get
- marginalia--metadata 'annotation-function)))
+ (when-let* ((fun (marginalia--orig-completion-metadata-get
+ marginalia--metadata 'annotation-function)))
(funcall fun cand)))))
(defconst marginalia--advice-regexp
@@ -580,8 +580,8 @@ t cl-type"
Sometimes symbols which are not yet loaded appear in completion tables
if `help-enable-completion-autoload' is enabled. These symbols
originate from the `definition-prefixes' hash table."
- (when-let (((bound-and-true-p help-enable-completion-autoload))
- (files (gethash (symbol-name sym) definition-prefixes)))
+ (when-let* (((bound-and-true-p help-enable-completion-autoload))
+ (files (gethash (symbol-name sym) definition-prefixes)))
(format "[Not yet loaded from %s. See `help-enable-completion-autoload'.]"
(string-join files ", "))))
@@ -615,7 +615,7 @@ originate from the `definition-prefixes' hash table."
(defun marginalia-annotate-symbol (cand)
"Annotate symbol CAND with its documentation string."
- (when-let (sym (intern-soft cand))
+ (when-let* ((sym (intern-soft cand)))
(marginalia--fields
(:left (marginalia-annotate-binding cand))
((marginalia--symbol-class sym) :face 'marginalia-type)
@@ -634,7 +634,7 @@ originate from the `definition-prefixes' hash table."
(defun marginalia-annotate-command (cand)
"Annotate command CAND with its documentation string.
Similar to `marginalia-annotate-symbol', but does not show symbol class."
- (when-let (sym (intern-soft cand))
+ (when-let* ((sym (intern-soft cand)))
(concat
(marginalia-annotate-binding cand)
(marginalia--documentation (marginalia--function-doc sym)))))
@@ -643,7 +643,7 @@ Similar to `marginalia-annotate-symbol', but does not show
symbol class."
"Annotate Embark keybinding CAND with its documentation string.
Similar to `marginalia-annotate-command', but does not show the
keybinding since CAND includes it."
- (when-let (cmd (get-text-property 0 'embark-command cand))
+ (when-let* ((cmd (get-text-property 0 'embark-command cand)))
(marginalia--documentation (marginalia--function-doc cmd))))
(defun marginalia-annotate-imenu (cand)
@@ -654,7 +654,7 @@ keybinding since CAND includes it."
(defun marginalia-annotate-function (cand)
"Annotate function CAND with its documentation string."
- (when-let (sym (intern-soft cand))
+ (when-let* ((sym (intern-soft cand)))
(marginalia--fields
(:left (marginalia-annotate-binding cand))
((marginalia--symbol-class sym) :face 'marginalia-type)
@@ -737,7 +737,7 @@ keybinding since CAND includes it."
(defun marginalia-annotate-variable (cand)
"Annotate variable CAND with its documentation string."
- (when-let (sym (intern-soft cand))
+ (when-let* ((sym (intern-soft cand)))
(marginalia--fields
((marginalia--symbol-class sym) :face 'marginalia-type)
((marginalia--variable-value sym) :truncate 0.5)
@@ -747,13 +747,13 @@ keybinding since CAND includes it."
(defun marginalia-annotate-environment-variable (cand)
"Annotate environment variable CAND with its current value."
- (when-let (val (getenv cand))
+ (when-let* ((val (getenv cand)))
(marginalia--fields
(val :truncate 1.0 :face 'marginalia-value))))
(defun marginalia-annotate-face (cand)
"Annotate face CAND with its documentation string and face example."
- (when-let (sym (intern-soft cand))
+ (when-let* ((sym (intern-soft cand)))
(marginalia--fields
;; HACK: Manual alignment to fix misalignment due to face
((concat marginalia--pangram #(" " 0 1 (display (space :align-to
center))))
@@ -763,7 +763,7 @@ keybinding since CAND includes it."
(defun marginalia-annotate-color (cand)
"Annotate face CAND with its documentation string and face example."
- (when-let (rgb (color-name-to-rgb cand))
+ (when-let* ((rgb (color-name-to-rgb cand)))
(pcase-let* ((`(,r ,g ,b) rgb)
(`(,h ,s ,l) (apply #'color-rgb-to-hsl rgb))
(cr (color-rgb-to-hex r 0 0))
@@ -791,7 +791,7 @@ keybinding since CAND includes it."
(defun marginalia-annotate-char (cand)
"Annotate character CAND with its general character category and character
code."
- (when-let (char (char-from-name cand t))
+ (when-let* ((char (char-from-name cand t)))
(marginalia--fields
(:left char :format" (%c)" :face 'marginalia-char)
(char :format "%06X" :face 'marginalia-number)
@@ -820,21 +820,21 @@ keybinding since CAND includes it."
(defun marginalia-annotate-package (cand)
"Annotate package CAND with its description summary."
- (when-let ((pkg-alist (bound-and-true-p package-alist))
- ;; See `package-get-version'.
- (name (replace-regexp-in-string
- "-[0-9]\\(?:[0-9.]\\|pre\\|beta\\|alpha\\|snapshot\\)+\\'"
"" cand))
- (pkg (intern-soft name))
- (desc (or (unless (equal name cand)
- (cl-loop with version = (substring cand (1+ (length
name)))
- for d in (alist-get pkg pkg-alist)
- if (equal (package-version-join
(package-desc-version d)) version)
- return d))
- ;; taken from `describe-package-1'
- (car (alist-get pkg pkg-alist))
- (if-let* ((built-in (assq pkg package--builtins)))
- (package--from-builtin built-in)
- (car (alist-get pkg package-archive-contents))))))
+ (when-let* ((pkg-alist (bound-and-true-p package-alist))
+ ;; See `package-get-version'.
+ (name (replace-regexp-in-string
+
"-[0-9]\\(?:[0-9.]\\|pre\\|beta\\|alpha\\|snapshot\\)+\\'" "" cand))
+ (pkg (intern-soft name))
+ (desc (or (unless (equal name cand)
+ (cl-loop with version = (substring cand (1+ (length
name)))
+ for d in (alist-get pkg pkg-alist)
+ if (equal (package-version-join
(package-desc-version d)) version)
+ return d))
+ ;; taken from `describe-package-1'
+ (car (alist-get pkg pkg-alist))
+ (if-let* ((built-in (assq pkg package--builtins)))
+ (package--from-builtin built-in)
+ (car (alist-get pkg package-archive-contents))))))
(marginalia--fields
((package-version-join (package-desc-version desc)) :truncate 16 :face
'marginalia-version)
((cond
@@ -864,7 +864,7 @@ The string is transformed according to
`marginalia--bookmark-type-transforms'."
(defun marginalia-annotate-bookmark (cand)
"Annotate bookmark CAND with its file name and front context string."
- (when-let ((bm (assoc cand (bound-and-true-p bookmark-alist))))
+ (when-let* ((bm (assoc cand (bound-and-true-p bookmark-alist))))
(marginalia--fields
((marginalia--bookmark-type bm) :width 10 :face 'marginalia-type)
((or (bookmark-prop-get bm 'filename)
@@ -916,8 +916,8 @@ The string is transformed according to
`marginalia--bookmark-type-transforms'."
(or (cond
;; see ibuffer-buffer-file-name
((buffer-file-name buffer))
- ((when-let (dir (and (local-variable-p 'dired-directory buffer)
- (buffer-local-value 'dired-directory buffer)))
+ ((when-let* ((dir (and (local-variable-p 'dired-directory buffer)
+ (buffer-local-value 'dired-directory
buffer))))
(expand-file-name (if (stringp dir) dir (car dir))
(buffer-local-value 'default-directory
buffer))))
((local-variable-p 'list-buffers-directory buffer)
@@ -927,9 +927,9 @@ The string is transformed according to
`marginalia--bookmark-type-transforms'."
(defun marginalia-annotate-buffer (cand)
"Annotate buffer CAND with modification status, file name and major mode."
;; Emacs 31: `project--read-project-buffer' uses `uniquify-get-unique-names'
- (when-let ((buffer (or (and (stringp cand)
- (get-text-property 0 'uniquify-orig-buffer cand))
- (get-buffer cand))))
+ (when-let* ((buffer (or (and (stringp cand)
+ (get-text-property 0 'uniquify-orig-buffer
cand))
+ (get-buffer cand))))
(if (buffer-live-p buffer)
(marginalia--fields
((marginalia--buffer-status buffer))
@@ -967,11 +967,11 @@ e.g., the protocol."
(defun marginalia--annotate-local-file (cand)
"Annotate local file CAND."
(marginalia--in-minibuffer
- (when-let (attrs (ignore-errors
- ;; may throw permission denied errors
- (file-attributes (substitute-in-file-name
- (marginalia--full-candidate cand))
- 'integer)))
+ (when-let* ((attrs (ignore-errors
+ ;; may throw permission denied errors
+ (file-attributes (substitute-in-file-name
+ (marginalia--full-candidate cand))
+ 'integer))))
;; HACK: Format differently accordingly to alignment, since the file
owner
;; is usually not displayed. Otherwise we will see an excessive amount of
;; whitespace in front of the file permissions. Furthermore the alignment
@@ -996,7 +996,7 @@ e.g., the protocol."
"Annotate file CAND with its size, modification time and other attributes.
These annotations are skipped for remote paths."
(if-let* ((remote (or (marginalia--remote-file-p cand)
- (when-let (win (active-minibuffer-window))
+ (when-let* ((win (active-minibuffer-window)))
(with-current-buffer (window-buffer win)
(marginalia--remote-file-p
(minibuffer-contents-no-properties)))))))
(marginalia--fields (remote :format "*%s*" :face
'marginalia-documentation))
@@ -1088,7 +1088,7 @@ These annotations are skipped for remote paths."
"\\`\\(?:Dired\\|Find file\\) in \\(.*\\): \\'"
prompt)
(match-string 1 prompt)))
- (when-let (proj (project-current))
+ (when-let* ((proj (project-current)))
(project-root proj)))))
marginalia--project-root))
@@ -1097,7 +1097,7 @@ These annotations are skipped for remote paths."
;; Absolute project directories also report project-file category
(if (file-name-absolute-p cand)
(marginalia-annotate-file cand)
- (when-let (root (marginalia--project-root))
+ (when-let* ((root (marginalia--project-root)))
(marginalia-annotate-file (expand-file-name cand root)))))
(defvar-local marginalia--library-cache nil)
@@ -1156,11 +1156,11 @@ These annotations are skipped for remote paths."
(defun marginalia-annotate-library (cand)
"Annotate library CAND with documentation and path."
(setq cand (marginalia--library-name cand))
- (when-let (file (gethash cand (marginalia--library-cache)))
+ (when-let* ((file (gethash cand (marginalia--library-cache))))
(marginalia--fields
;; Display if the corresponding feature is loaded.
;; feature/=library file, but better than nothing.
- ((when-let (sym (intern-soft cand))
+ ((when-let* ((sym (intern-soft cand)))
(when (memq sym features)
(propertize "Loaded" 'face 'marginalia-on)))
:width 8)
@@ -1171,7 +1171,7 @@ These annotations are skipped for remote paths."
(defun marginalia-annotate-theme (cand)
"Annotate theme CAND with documentation and path."
- (when-let (file (gethash (concat cand "-theme") (marginalia--library-cache)))
+ (when-let* ((file (gethash (concat cand "-theme")
(marginalia--library-cache))))
(marginalia--fields
((marginalia--library-doc file)
:truncate 1.0 :face 'marginalia-documentation)
@@ -1180,10 +1180,10 @@ These annotations are skipped for remote paths."
(defun marginalia-annotate-tab (cand)
"Annotate named tab CAND with tab index, window and buffer information."
- (when-let ((tabs (funcall tab-bar-tabs-function))
- (index (seq-position
- tabs nil
- (lambda (tab _) (equal (alist-get 'name tab) cand)))))
+ (when-let* ((tabs (funcall tab-bar-tabs-function))
+ (index (seq-position
+ tabs nil
+ (lambda (tab _) (equal (alist-get 'name tab) cand)))))
(let* ((tab (nth index tabs))
(ws (alist-get 'ws tab))
(bufs (window-state-buffers ws)))
@@ -1208,20 +1208,20 @@ These annotations are skipped for remote paths."
(and marginalia--command
(or (alist-get marginalia--command marginalia-command-categories)
;; The command can be an alias, e.g., `recentf' -> `recentf-open'.
- (when-let ((chain (function-alias-p marginalia--command)))
+ (when-let* ((chain (function-alias-p marginalia--command)))
(alist-get (car (last chain)) marginalia-command-categories)))))
(defun marginalia-classify-original-category ()
"Return original category reported by completion metadata."
;; Bypass our `marginalia--completion-metadata-get' advice.
- (when-let (cat (marginalia--orig-completion-metadata-get
marginalia--metadata 'category))
+ (when-let* ((cat (marginalia--orig-completion-metadata-get
marginalia--metadata 'category)))
;; Ignore `symbol-help' category in order to ensure that the categories are
;; refined to our categories function and variable.
(and (not (eq cat 'symbol-help)) cat)))
(defun marginalia-classify-symbol ()
"Determine if currently completing symbols."
- (when-let (mct minibuffer-completion-table)
+ (when-let* ((mct minibuffer-completion-table))
(when (or (eq mct 'help--symbol-completion-table)
(obarrayp mct)
(and (not (functionp mct)) (consp mct) (symbolp (car mct)))) ;
assume list of symbols
@@ -1231,7 +1231,7 @@ These annotations are skipped for remote paths."
"Determine category by matching regexps against the minibuffer prompt.
This runs through the `marginalia-prompt-categories' alist
looking for a regexp that matches the prompt."
- (when-let (prompt (minibuffer-prompt))
+ (when-let* ((prompt (minibuffer-prompt)))
(setq prompt
(replace-regexp-in-string "(.*?default.*?)\\|\\[.*?\\]" "" prompt))
(cl-loop with case-fold-search = t
@@ -1267,7 +1267,7 @@ completion UIs like Vertico or Icomplete."
"Align annotations of CANDS according to `marginalia-align'."
(cl-loop
for (cand . ann) in cands do
- (when-let (align (text-property-any 0 (length ann) 'marginalia--align t
ann))
+ (when-let* ((align (text-property-any 0 (length ann) 'marginalia--align t
ann)))
(setq marginalia--cand-width-max
(max marginalia--cand-width-max
(* (ceiling (+ (string-width cand) (string-width ann 0 align))
@@ -1276,7 +1276,7 @@ completion UIs like Vertico or Icomplete."
(cl-loop
for (cand . ann) in cands collect
(progn
- (when-let (align (text-property-any 0 (length ann) 'marginalia--align t
ann))
+ (when-let* ((align (text-property-any 0 (length ann) 'marginalia--align t
ann)))
(put-text-property
align (1+ align) 'display
`(space :align-to
@@ -1320,8 +1320,8 @@ PROP is the property which is looked up."
(pcase prop
('affixation-function
;; We do want the advice triggered for `completion-metadata-get'.
- (when-let ((cat (completion-metadata-get metadata 'category))
- (annotator (marginalia--annotator cat)))
+ (when-let* ((cat (completion-metadata-get metadata 'category))
+ (annotator (marginalia--annotator cat)))
(apply-partially #'marginalia--affixate metadata annotator)))
('category
;; Find the completion category by trying each of our classifiers.
@@ -1408,25 +1408,25 @@ Remember `this-command' for
`marginalia-classify-by-command-name'."
(defun marginalia--context-menu (menu _event)
"Add Marginalia commands to context MENU."
- (when-let ((md (marginalia--completion-metadata))
- (cat (completion-metadata-get md 'category))
- (ann (assq cat marginalia-annotators))
- (items (cl-loop
- for fun in (cdr ann) for i from 0
- if (or (not (eq fun 'builtin))
(marginalia--builtin-annotator-p md))
- collect
- (vector
- (thread-last (symbol-name fun)
- (replace-regexp-in-string ".*?-+annotate-+"
"")
- (replace-regexp-in-string "-+" " ")
- capitalize)
- (let ((i i))
- (lambda ()
- (interactive)
- (setcdr ann (append (drop i (cdr ann)) (take i (cdr
ann))))
- (marginalia--cache-reset)
- (message "Marginalia: Use annotator `%s' for
category `%s'" (cadr ann) cat)))
- :style 'radio :selected (eq fun (cadr ann))))))
+ (when-let* ((md (marginalia--completion-metadata))
+ (cat (completion-metadata-get md 'category))
+ (ann (assq cat marginalia-annotators))
+ (items (cl-loop
+ for fun in (cdr ann) for i from 0
+ if (or (not (eq fun 'builtin))
(marginalia--builtin-annotator-p md))
+ collect
+ (vector
+ (thread-last (symbol-name fun)
+ (replace-regexp-in-string
".*?-+annotate-+" "")
+ (replace-regexp-in-string "-+" " ")
+ capitalize)
+ (let ((i i))
+ (lambda ()
+ (interactive)
+ (setcdr ann (append (drop i (cdr ann)) (take i (cdr
ann))))
+ (marginalia--cache-reset)
+ (message "Marginalia: Use annotator `%s' for
category `%s'" (cadr ann) cat)))
+ :style 'radio :selected (eq fun (cadr ann))))))
(define-key menu [marginalia]
`("Marginalia" . ,(easy-menu-create-menu
"" `(["Cycle" marginalia-cycle] "---"
,@items)))))