branch: externals/vertico
commit 0e8b10bc90d4ef3c91ecf7a90277144c58d0e09c
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>

    Use when-let*
---
 extensions/vertico-buffer.el    | 10 +++++-----
 extensions/vertico-directory.el | 34 +++++++++++++++++-----------------
 extensions/vertico-flat.el      |  4 ++--
 extensions/vertico-grid.el      |  4 ++--
 extensions/vertico-mouse.el     |  8 ++++----
 extensions/vertico-multiform.el |  4 ++--
 extensions/vertico-repeat.el    | 20 ++++++++++----------
 extensions/vertico-reverse.el   |  2 +-
 extensions/vertico-sort.el      |  8 ++++----
 extensions/vertico-suspend.el   | 10 +++++-----
 vertico.el                      | 28 ++++++++++++++--------------
 11 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/extensions/vertico-buffer.el b/extensions/vertico-buffer.el
index d4ec474076..ef49748d9c 100644
--- a/extensions/vertico-buffer.el
+++ b/extensions/vertico-buffer.el
@@ -94,10 +94,10 @@
 
 (defun vertico-buffer--redisplay (_)
   "Redisplay buffer window."
-  (when-let ((mbwin (active-minibuffer-window))
-             ((eq (window-buffer mbwin) (current-buffer)))
-             ((overlayp vertico--candidates-ov))
-             (win (overlay-get vertico--candidates-ov 'window)))
+  (when-let* ((mbwin (active-minibuffer-window))
+              ((eq (window-buffer mbwin) (current-buffer)))
+              ((overlayp vertico--candidates-ov))
+              (win (overlay-get vertico--candidates-ov 'window)))
     (setq-local truncate-lines (< (window-point win)
                                   (* 0.8 (window-width win)))
                 vertico-count (- (/ (window-pixel-height win)
@@ -203,7 +203,7 @@
   "Display Vertico like a regular buffer in a large window."
   :global t :group 'vertico
   ;; Shrink current minibuffer window
-  (when-let ((win (active-minibuffer-window)))
+  (when-let* ((win (active-minibuffer-window)))
     (unless (frame-root-window-p win)
       (window-resize win (- (window-pixel-height win)) nil nil 'pixelwise))
     (with-selected-window win
diff --git a/extensions/vertico-directory.el b/extensions/vertico-directory.el
index 35aad4ee66..19680803fe 100644
--- a/extensions/vertico-directory.el
+++ b/extensions/vertico-directory.el
@@ -55,23 +55,23 @@
   "Enter directory or exit completion with current candidate.
 Exit with current input if prefix ARG is given."
   (interactive "P")
-  (if-let (((not arg))
-           ((>= vertico--index 0))
-           ((eq 'file (vertico--metadata-get 'category)))
-           ;; Check vertico--base for stepwise file path completion
-           ((not (equal vertico--base "")))
-           (cand (vertico--candidate))
-           ((or (string-suffix-p "/" cand)
-                (and (vertico--remote-p cand)
-                     (string-suffix-p ":" cand))))
-           ;; Handle /./ and /../ manually instead of via `expand-file-name'
-           ;; and `abbreviate-file-name', such that we don't accidentally
-           ;; perform unwanted substitutions in the existing completion.
-           ((progn
-              (setq cand (string-replace "/./" "/" cand))
-              (unless (string-suffix-p "/../../" cand)
-                (setq cand (replace-regexp-in-string "/[^/|:]+/\\.\\./\\'" "/" 
cand)))
-              (not (equal (minibuffer-contents-no-properties) cand)))))
+  (if-let* (((not arg))
+            ((>= vertico--index 0))
+            ((eq 'file (vertico--metadata-get 'category)))
+            ;; Check vertico--base for stepwise file path completion
+            ((not (equal vertico--base "")))
+            (cand (vertico--candidate))
+            ((or (string-suffix-p "/" cand)
+                 (and (vertico--remote-p cand)
+                      (string-suffix-p ":" cand))))
+            ;; Handle /./ and /../ manually instead of via `expand-file-name'
+            ;; and `abbreviate-file-name', such that we don't accidentally
+            ;; perform unwanted substitutions in the existing completion.
+            ((progn
+               (setq cand (string-replace "/./" "/" cand))
+               (unless (string-suffix-p "/../../" cand)
+                 (setq cand (replace-regexp-in-string "/[^/|:]+/\\.\\./\\'" 
"/" cand)))
+               (not (equal (minibuffer-contents-no-properties) cand)))))
       (progn
         (delete-minibuffer-contents)
         (insert cand))
diff --git a/extensions/vertico-flat.el b/extensions/vertico-flat.el
index 724117d5f5..0e597971af 100644
--- a/extensions/vertico-flat.el
+++ b/extensions/vertico-flat.el
@@ -77,7 +77,7 @@
   "Flat, horizontal display for Vertico."
   :global t :group 'vertico
   ;; Shrink current minibuffer window
-  (when-let ((win (active-minibuffer-window)))
+  (when-let* ((win (active-minibuffer-window)))
     (unless (frame-root-window-p win)
       (window-resize win (- (window-pixel-height win)) nil nil 'pixelwise)))
   (cl-callf2 rassq-delete-all vertico-flat-map minor-mode-map-alist)
@@ -94,7 +94,7 @@
            (cond
             ((and (not candidates) (plist-get vertico-flat-format :no-match)))
             ((and (= vertico--total 1) (= vertico--index 0)
-                  (when-let ((fmt (plist-get vertico-flat-format :single)))
+                  (when-let* ((fmt (plist-get vertico-flat-format :single)))
                     (format fmt (substring-no-properties (car candidates))))))
             (t (format (plist-get vertico-flat-format (if (< vertico--index 0) 
:prompt :multiple))
                        (string-join candidates (plist-get vertico-flat-format 
:separator))))))))
diff --git a/extensions/vertico-grid.el b/extensions/vertico-grid.el
index 917594489f..73402e9995 100644
--- a/extensions/vertico-grid.el
+++ b/extensions/vertico-grid.el
@@ -109,7 +109,7 @@ When scrolling beyond this limit, candidates may be 
truncated."
   "Grid display for Vertico."
   :global t :group 'vertico
   ;; Shrink current minibuffer window
-  (when-let ((win (active-minibuffer-window)))
+  (when-let* ((win (active-minibuffer-window)))
     (unless (frame-root-window-p win)
       (window-resize win (- (window-pixel-height win)) nil nil 'pixelwise)))
   (cl-callf2 rassq-delete-all vertico-grid-map minor-mode-map-alist)
@@ -157,7 +157,7 @@ When scrolling beyond this limit, candidates may be 
truncated."
     (cl-loop for row from 0 to (1- (min vertico-count vertico--total)) collect
              (let ((line (list "\n")))
                (cl-loop for col from (1- vertico-grid--columns) downto 0 do
-                        (when-let ((cand (nth (+ row (* col vertico-count)) 
cands)))
+                        (when-let* ((cand (nth (+ row (* col vertico-count)) 
cands)))
                           (push cand line)
                           (when (> col 0)
                             (push vertico-grid-separator line)
diff --git a/extensions/vertico-mouse.el b/extensions/vertico-mouse.el
index 765f9217d8..8b3bde6b22 100644
--- a/extensions/vertico-mouse.el
+++ b/extensions/vertico-mouse.el
@@ -39,8 +39,8 @@
 
 (defun vertico-mouse--index (event)
   "Return candidate index at EVENT."
-  (when-let ((object (posn-object (event-end event)))
-             ((consp object)))
+  (when-let* ((object (posn-object (event-end event)))
+              ((consp object)))
     (get-text-property (cdr object) 'vertico-mouse--index (car object))))
 
 (defun vertico-mouse--click (key)
@@ -49,8 +49,8 @@
     (interactive "e")
     ;; Mouse clicks can even happen if another window is selected.
     (with-selected-window (active-minibuffer-window)
-      (when-let ((vertico--index (vertico-mouse--index event))
-                 (cmd (keymap-local-lookup key)))
+      (when-let* ((vertico--index (vertico-mouse--index event))
+                  (cmd (keymap-local-lookup key)))
         (funcall cmd)))))
 
 (defvar-keymap vertico-mouse-map
diff --git a/extensions/vertico-multiform.el b/extensions/vertico-multiform.el
index 95581574ee..89a4aeb6f8 100644
--- a/extensions/vertico-multiform.el
+++ b/extensions/vertico-multiform.el
@@ -84,8 +84,8 @@ category settings have lower precedence than
 
 (defun vertico-multiform--toggle (arg)
   "Toggle modes from stack depending on ARG."
-  (when-let ((win (active-minibuffer-window))
-             (modes (car vertico-multiform--stack)))
+  (when-let* ((win (active-minibuffer-window))
+              (modes (car vertico-multiform--stack)))
     (when (> arg 0) (setq modes (reverse modes)))
     (with-selected-window win
       (dolist (m modes)
diff --git a/extensions/vertico-repeat.el b/extensions/vertico-repeat.el
index 2819f43307..f495df9767 100644
--- a/extensions/vertico-repeat.el
+++ b/extensions/vertico-repeat.el
@@ -88,8 +88,8 @@
 
 (defun vertico-repeat--remove-long (session)
   "Remove overly long candidate from SESSION."
-  (when-let ((cand (caddr session))
-             ((and (stringp cand) (length> cand 200))))
+  (when-let* ((cand (caddr session))
+              ((and (stringp cand) (length> cand 200))))
     (setf (cddr session) (cdddr session)))
   session)
 
@@ -127,17 +127,17 @@
   (delete-minibuffer-contents)
   (insert (cadr session))
   (setq vertico--lock-candidate
-        (when-let ((cand (seq-find #'stringp (cddr session))))
+        (when-let* ((cand (seq-find #'stringp (cddr session))))
           (vertico--update)
-          (when-let ((idx (seq-position vertico--candidates cand)))
+          (when-let* ((idx (seq-position vertico--candidates cand)))
             (setq vertico--index idx)
             t)))
   ;; Restore display modes if not modifying the current session
-  (when-let (((not (and vertico-repeat--command
-                        (eq vertico-repeat--command (car session)))))
-             (mode (seq-find #'symbolp (cddr session)))
-             ((bound-and-true-p vertico-multiform-mode))
-             ((not (and (boundp mode) (symbol-value mode)))))
+  (when-let* (((not (and vertico-repeat--command
+                         (eq vertico-repeat--command (car session)))))
+              (mode (seq-find #'symbolp (cddr session)))
+              ((bound-and-true-p vertico-multiform-mode))
+              ((not (and (boundp mode) (symbol-value mode)))))
     (declare-function vertico-multiform--toggle-mode "ext:vertico-multiform")
     (vertico-multiform--toggle-mode mode))
   (vertico--exhibit))
@@ -187,7 +187,7 @@ selected candidate for the current command."
       ((= vertico-repeat--pos 0)
        (setcar vertico-repeat--step (vertico-repeat--current))))
      (cl-incf n vertico-repeat--pos)
-     (when-let (((>= n 0)) (session (nth n vertico-repeat--step)))
+     (when-let* (((>= n 0)) (session (nth n vertico-repeat--step)))
        (setq vertico-repeat--pos n)
        session))))
 
diff --git a/extensions/vertico-reverse.el b/extensions/vertico-reverse.el
index 9f8f899762..9683e9660d 100644
--- a/extensions/vertico-reverse.el
+++ b/extensions/vertico-reverse.el
@@ -59,7 +59,7 @@
   :global t :group 'vertico
   ;; Reset overlays
   (dolist (buf (buffer-list))
-    (when-let ((ov (buffer-local-value 'vertico--candidates-ov buf)))
+    (when-let* ((ov (buffer-local-value 'vertico--candidates-ov buf)))
       (overlay-put ov 'before-string nil)))
   (cl-callf2 rassq-delete-all vertico-reverse-map minor-mode-map-alist)
   (when vertico-reverse-mode
diff --git a/extensions/vertico-sort.el b/extensions/vertico-sort.el
index 875ff9bd86..a195a5bcbb 100644
--- a/extensions/vertico-sort.el
+++ b/extensions/vertico-sort.el
@@ -67,8 +67,8 @@ The shift will decay away after 
`vertico-sort-history-duplicate' times
              (ht (make-hash-table :test #'equal :size (length hist)))
              (file-p (and (> base-len 0) ;; Step-wise completion, unlike 
`project-find-file'
                           (eq minibuffer-history-variable 'file-name-history)))
-             (curr-file (when-let ((win (and file-p 
(minibuffer-selected-window)))
-                                   (file (buffer-file-name (window-buffer 
win))))
+             (curr-file (when-let* ((win (and file-p 
(minibuffer-selected-window)))
+                                    (file (buffer-file-name (window-buffer 
win))))
                           (abbreviate-file-name file)))
              (decay (/ -1.0 (* vertico-sort-history-duplicate 
vertico-sort-history-decay))))
         (cl-loop for elem in hist for idx from 0 do
@@ -80,7 +80,7 @@ The shift will decay away after 
`vertico-sort-history-duplicate' times
                      ;; Drop base string from history elements & special file 
handling.
                      (when (or (> base-len 0) file-sep)
                        (setq elem (substring elem base-len (and file-sep (1+ 
file-sep)))))
-                     (let ((r (if-let ((r (gethash elem ht)))
+                     (let ((r (if-let* ((r (gethash elem ht)))
                                   ;; Reduce duplicate rank with exponential 
decay.
                                   (- r (round (* vertico-sort-history-duplicate
                                                  (exp (* decay idx)))))
@@ -109,7 +109,7 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
PRED."
        (dolist (% candidates)
          ;; Find recent candidate in history or fill bucket
          (,@(if (not (eq (car by) 'history)) `(progn)
-              `(if-let ((idx (gethash % hhash))) (push (cons idx %) hcands)))
+              `(if-let* ((idx (gethash % hhash))) (push (cons idx %) hcands)))
           (let ((i ,bindex)) (if (< i ,bsize) (push % (aref buckets i)) (push 
% last)))))
        (nconc ,@(and (eq (car by) 'history) '((vertico-sort--decorated 
hcands)))
               (mapcan (lambda (bucket) (sort bucket #',bpred)) buckets)
diff --git a/extensions/vertico-suspend.el b/extensions/vertico-suspend.el
index 1870adb449..a0c9c2fb23 100644
--- a/extensions/vertico-suspend.el
+++ b/extensions/vertico-suspend.el
@@ -64,9 +64,9 @@ or the latest completion session is restored."
   (unless enable-recursive-minibuffers
     (user-error "Recursive minibuffers must be enabled"))
   (advice-add #'set-minibuffer-message :around #'vertico-suspend--message)
-  (if-let ((win (active-minibuffer-window))
-           (buf (window-buffer win))
-           ((buffer-local-value 'vertico--input buf)))
+  (if-let* ((win (active-minibuffer-window))
+            (buf (window-buffer win))
+            ((buffer-local-value 'vertico--input buf)))
       (cond
        ((minibufferp)
         (add-hook 'pre-redisplay-functions #'vertico-suspend--unselect nil 
'local)
@@ -101,8 +101,8 @@ or the latest completion session is restored."
 
 (defun vertico-suspend--message (&rest app)
   "Apply APP in non-suspended minibuffers, otherwise bail out."
-  (when-let ((win (active-minibuffer-window))
-             ((not (buffer-local-value 'vertico-suspend--ov (window-buffer 
win)))))
+  (when-let* ((win (active-minibuffer-window))
+              ((not (buffer-local-value 'vertico-suspend--ov (window-buffer 
win)))))
     (apply app)))
 
 (provide 'vertico-suspend)
diff --git a/vertico.el b/vertico.el
index 5f6b176c04..2799174db4 100644
--- a/vertico.el
+++ b/vertico.el
@@ -198,9 +198,9 @@ The value should lie between 0 and vertico-count/2."
 
 (defun vertico--affixate (cands)
   "Annotate CANDS with annotation function."
-  (if-let ((aff (vertico--metadata-get 'affixation-function)))
+  (if-let* ((aff (vertico--metadata-get 'affixation-function)))
       (funcall aff cands)
-    (if-let ((ann (vertico--metadata-get 'annotation-function)))
+    (if-let* ((ann (vertico--metadata-get 'annotation-function)))
         (cl-loop for cand in cands collect
                  (let ((suff (or (funcall ann cand) "")))
                    ;; The default completion UI adds the 
`completions-annotations'
@@ -212,7 +212,7 @@ The value should lie between 0 and vertico-count/2."
 
 (defun vertico--move-to-front (elem list)
   "Move ELEM to front of LIST."
-  (if-let ((found (member elem list))) ;; No duplicates, compare with Corfu.
+  (if-let* ((found (member elem list))) ;; No duplicates, compare with Corfu.
       (nconc (list (car found)) (delq (setcar found nil) list))
     list))
 
@@ -272,7 +272,7 @@ The value should lie between 0 and vertico-count/2."
                ;; bug#75910: category instead of 
`minibuffer-completing-file-name'
                (completing-file (eq 'file (vertico--metadata-get 'category)))
                (`(,all . ,hl) (vertico--filter-completions content table pred 
pt vertico--metadata))
-               (base (or (when-let ((z (last all))) (prog1 (cdr z) (setcdr z 
nil))) 0))
+               (base (or (when-let* ((z (last all))) (prog1 (cdr z) (setcdr z 
nil))) 0))
                (vertico--base (substring content 0 base))
                (def (or (car-safe minibuffer-default) minibuffer-default))
                (groups) (def-missing) (lock))
@@ -288,7 +288,7 @@ The value should lie between 0 and vertico-count/2."
     (when (and completing-file (not (string-suffix-p "/" field)))
       (setq all (vertico--move-to-front (concat field "/") all)))
     (setq all (vertico--move-to-front field all))
-    (when-let ((fun (and all (vertico--metadata-get 'group-function))))
+    (when-let* ((fun (and all (vertico--metadata-get 'group-function))))
       (setq groups (vertico--group-by fun all) all (car groups)))
     (setq def-missing (and def (equal content "") (not (member def all)))
           lock (and vertico--lock-candidate ;; Locked position of old 
candidate.
@@ -329,15 +329,15 @@ The value should lie between 0 and vertico-count/2."
     ;; Build hash table of groups
     (cl-loop for elem on elems
              for title = (funcall fun (car elem) nil) do
-             (if-let ((group (gethash title ht)))
+             (if-let* ((group (gethash title ht)))
                  (setcdr group (setcdr (cdr group) elem)) ;; Append to tail of 
group
                (puthash title (cons elem elem) ht) ;; New group element (head 
. tail)
                (push title titles)))
     (setq titles (nreverse titles))
     ;; Cycle groups if `vertico--lock-groups' is set
-    (when-let ((vertico--lock-groups)
-               (group (seq-find (lambda (group) (gethash group ht))
-                                vertico--all-groups)))
+    (when-let* ((vertico--lock-groups)
+                (group (seq-find (lambda (group) (gethash group ht))
+                                 vertico--all-groups)))
       (setq titles (vertico--cycle titles (seq-position titles group))))
     ;; Build group list
     (dolist (title titles)
@@ -466,7 +466,7 @@ The value should lie between 0 and vertico-count/2."
   "Remove FACE between BEG and END from OBJ."
   (while (< beg end)
     (let ((next (next-single-property-change beg 'face obj end)))
-      (when-let ((val (get-text-property beg 'face obj)))
+      (when-let* ((val (get-text-property beg 'face obj)))
         (put-text-property beg next 'face (remq face (ensure-list val)) obj))
       (setq beg next))))
 
@@ -559,7 +559,7 @@ the stack trace is shown in the *Messages* buffer."
              (cl-loop repeat vertico-count for c in (nthcdr index 
vertico--candidates)
                       collect (vertico--hilit c)))))
       (pcase-dolist ((and cand `(,str . ,_)) candidates)
-        (when-let ((new-title (and group-fun (funcall group-fun str nil))))
+        (when-let* ((new-title (and group-fun (funcall group-fun str nil))))
           (unless (equal title new-title)
             (setq title new-title)
             (push (vertico--format-group-title title str) lines))
@@ -609,9 +609,9 @@ the stack trace is shown in the *Messages* buffer."
 
 (cl-defgeneric vertico--prepare ()
   "Ensure that the state is prepared before running the next command."
-  (when-let ((cmd (and (symbolp this-command) (symbol-name this-command)))
-             ((string-prefix-p "vertico-" cmd))
-             ((not (and vertico--metadata (string-prefix-p 
"vertico-directory-" cmd)))))
+  (when-let* ((cmd (and (symbolp this-command) (symbol-name this-command)))
+              ((string-prefix-p "vertico-" cmd))
+              ((not (and vertico--metadata (string-prefix-p 
"vertico-directory-" cmd)))))
     (vertico--update)))
 
 (cl-defgeneric vertico--setup ()

Reply via email to