branch: externals/cape
commit f8682a046a57525754ebc812ba3ae9c973db083b
Author: Daniel Mendler <[email protected]>
Commit: Daniel Mendler <[email protected]>

    Use when-let*
---
 README.org      |  4 +--
 cape-char.el    | 72 ++++++++++++++++++++++++-------------------------
 cape-keyword.el | 12 ++++-----
 cape.el         | 84 ++++++++++++++++++++++++++++-----------------------------
 4 files changed, 86 insertions(+), 86 deletions(-)

diff --git a/README.org b/README.org
index f7f3591f7f..90df8366bd 100644
--- a/README.org
+++ b/README.org
@@ -139,8 +139,8 @@ small example completion backend, which can be used with 
both
 (defun demo-backend (action &optional arg &rest _)
   (pcase action
     ('prefix
-     (when-let (beg (save-excursion
-                      (and (re-search-backward "[;:]" (pos-bol) t) (point))))
+     (when-let* ((beg (save-excursion
+                        (and (re-search-backward "[;:]" (pos-bol) t) 
(point)))))
        (list (buffer-substring-no-properties beg (point)) "" t)))
     ('candidates (all-completions arg demo-alist))
     ('annotation (concat " " (cdr (assoc arg demo-alist))))
diff --git a/cape-char.el b/cape-char.el
index 54dc185acd..b4d0aa78e0 100644
--- a/cape-char.el
+++ b/cape-char.el
@@ -36,36 +36,36 @@
 PREFIX are the prefix characters. Names (hash keys) that map to
 multiple candidates (hash values) in the quail translation map
 are not included. Hash values are either char or strings."
-    (when-let ((im (assoc method input-method-alist))
-               ((eq #'quail-use-package (nth 2 im))))
-      (let ((hash (make-hash-table :test #'equal))
-            (dm (list 'decode-map)))
-        (require 'quail)
-        (apply #'quail-use-package method (nthcdr 5 im))
-        (quail-build-decode-map (list (quail-map)) "" dm 0)
-        (pcase-dolist (`(,name . ,val) (cdr dm))
-          (when (equal method "emoji")
-            (setq name (replace-regexp-in-string
-                        ": " "-"
-                        (replace-regexp-in-string
-                         "[’“”!()]" ""
-                         (replace-regexp-in-string
-                          "[_ &.]+" "-" name))))
-            (when (string-match-p "\\`[[:alnum:]-]*\\'" name)
-              (setq name (format ":%s:" name))))
-          (when (memq (aref name 0) prefix)
-            (puthash name (if (vectorp val) (aref val 0) val) hash)))
-        (quail-deactivate)
-        hash))))
+    (when-let* ((im (assoc method input-method-alist))
+                ((eq #'quail-use-package (nth 2 im)))
+                (hash (make-hash-table :test #'equal))
+                (dm (list 'decode-map)))
+      (require 'quail)
+      (apply #'quail-use-package method (nthcdr 5 im))
+      (quail-build-decode-map (list (quail-map)) "" dm 0)
+      (pcase-dolist (`(,name . ,val) (cdr dm))
+        (when (equal method "emoji")
+          (setq name (replace-regexp-in-string
+                      ": " "-"
+                      (replace-regexp-in-string
+                       "[’“”!()]" ""
+                       (replace-regexp-in-string
+                        "[_ &.]+" "-" name))))
+          (when (string-match-p "\\`[[:alnum:]-]*\\'" name)
+            (setq name (format ":%s:" name))))
+        (when (memq (aref name 0) prefix)
+          (puthash name (if (vectorp val) (aref val 0) val) hash)))
+      (quail-deactivate)
+      hash)))
 
 (defun cape-char--annotation (hash name)
   "Lookup NAME in HASH and return annotation."
-  (when-let ((char (gethash name hash)))
+  (when-let* ((char (gethash name hash)))
     (format (if (stringp char) " %s " " %c ") char)))
 
 (defun cape-char--signature (hash name)
   "Lookup NAME in HASH and return signature."
-  (when-let ((val (gethash name hash)))
+  (when-let* ((val (gethash name hash)))
     (concat
      (and (stringp val) (concat val " = "))
      (mapconcat
@@ -81,8 +81,8 @@ are not included. Hash values are either char or strings."
 
 (defun cape-char--exit (hash name status)
   "Exit function given completion STATUS, looks-up NAME in HASH."
-  (when-let (((not (eq status 'exact)))
-             (char (gethash name hash)))
+  (when-let* (((not (eq status 'exact)))
+              (char (gethash name hash)))
     (delete-region (max (point-min) (- (point) (length name))) (point))
     (insert char)))
 
@@ -91,12 +91,12 @@ are not included. Hash values are either char or strings."
 NAME is the name of the Capf.
 METHOD is the input method.
 PREFIX are the prefix characters."
-  (when-let ((capf (intern (format "cape-%s" name)))
-             (pre-req (intern (format "cape-%s-prefix-required" name)))
-             (props (intern (format "cape--%s-properties" name)))
-             (pre-rx (concat (regexp-opt (mapcar #'char-to-string prefix)) "[^ 
\n\t]*" ))
-             (hash (intern (format "cape--%s-hash" name)))
-             (hash-val (cape-char--translation method prefix)))
+  (when-let* ((capf (intern (format "cape-%s" name)))
+              (pre-req (intern (format "cape-%s-prefix-required" name)))
+              (props (intern (format "cape--%s-properties" name)))
+              (pre-rx (concat (regexp-opt (mapcar #'char-to-string prefix)) 
"[^ \n\t]*" ))
+              (hash (intern (format "cape--%s-hash" name)))
+              (hash-val (cape-char--translation method prefix)))
     `(progn
        (defvar ,hash ,hash-val)
        (defcustom ,pre-req t
@@ -124,11 +124,11 @@ function acts like a Capf." method method)
                           (not (looking-back ,pre-rx (pos-bol))))
                  (self-insert-command 1 last-input-event))
                (cape-interactive #',capf))
-           (when-let ((bounds
-                       (cond
-                        ((looking-back ,pre-rx (pos-bol))
-                         (cons (match-beginning 0) (point)))
-                        ((not ,pre-req) (cons (point) (point))))))
+           (when-let* ((bounds
+                        (cond
+                         ((looking-back ,pre-rx (pos-bol))
+                          (cons (match-beginning 0) (point)))
+                         ((not ,pre-req) (cons (point) (point))))))
              (append (list (car bounds) (cdr bounds) ,hash) ,props)))))))
 
 ;;;###autoload (autoload 'cape-tex "cape-char" nil t)
diff --git a/cape-keyword.el b/cape-keyword.el
index 2e5d1f1d7d..3142819b16 100644
--- a/cape-keyword.el
+++ b/cape-keyword.el
@@ -403,9 +403,9 @@
 
 (defun cape--keyword-list ()
   "Return keywords for current major mode."
-  (when-let ((kw (or (alist-get major-mode cape-keyword-list)
-                     (when-let ((remap (rassq major-mode 
major-mode-remap-alist)))
-                       (alist-get (car remap) cape-keyword-list)))))
+  (when-let* ((kw (or (alist-get major-mode cape-keyword-list)
+                      (when-let* ((remap (rassq major-mode 
major-mode-remap-alist)))
+                        (alist-get (car remap) cape-keyword-list)))))
     (if (symbolp (car kw)) (alist-get (car kw) cape-keyword-list) kw)))
 
 (defvar cape--keyword-properties
@@ -423,9 +423,9 @@ If INTERACTIVE is nil the function acts like a capf."
   (interactive (list t))
   (if interactive
       (cape-interactive #'cape-keyword)
-    (when-let (keywords (cape--keyword-list))
-      (let ((bounds (cape--bounds 'symbol)))
-        `(,(car bounds) ,(cdr bounds) ,keywords ,@cape--keyword-properties)))))
+    (when-let* ((keywords (cape--keyword-list))
+                (bounds (cape--bounds 'symbol)))
+      `(,(car bounds) ,(cdr bounds) ,keywords ,@cape--keyword-properties))))
 
 (provide 'cape-keyword)
 ;;; cape-keyword.el ends here
diff --git a/cape.el b/cape.el
index 197dcb7940..bb18a80248 100644
--- a/cape.el
+++ b/cape.el
@@ -473,14 +473,14 @@ If INTERACTIVE is nil the function acts like a Capf."
 (defun cape--elisp-symbol-exit (sym status)
   "Wrap symbol SYM with `cape-elisp-symbol-wrapper' buffers.
 STATUS is the exit status."
-  (when-let (((not (eq status 'exact)))
-             (c (cl-loop for (m . c) in cape-elisp-symbol-wrapper
-                         if (derived-mode-p m) return c))
-             ((or (not (derived-mode-p 'emacs-lisp-mode))
-                  ;; Inside comment or string
-                  (let ((s (syntax-ppss))) (or (nth 3 s) (nth 4 s)))))
-             (x (if (stringp (car c)) (car c) (string (car c))))
-             (y (if (stringp (cadr c)) (cadr c) (string (cadr c)))))
+  (when-let* (((not (eq status 'exact)))
+              (c (cl-loop for (m . c) in cape-elisp-symbol-wrapper
+                          if (derived-mode-p m) return c))
+              ((or (not (derived-mode-p 'emacs-lisp-mode))
+                   ;; Inside comment or string
+                   (let ((s (syntax-ppss))) (or (nth 3 s) (nth 4 s)))))
+              (x (if (stringp (car c)) (car c) (string (car c))))
+              (y (if (stringp (cadr c)) (cadr c) (string (cadr c)))))
     (save-excursion
       (backward-char (length sym))
       (unless (save-excursion
@@ -525,15 +525,15 @@ If INTERACTIVE is nil the function acts like a Capf."
 
 (defun cape--inside-block-p (&rest langs)
   "Return non-nil if inside LANGS code block."
-  (when-let ((face (get-text-property (point) 'face))
-             (lang (or (and (if (listp face)
-                                (memq 'org-block face)
-                              (eq 'org-block face))
-                            (plist-get (cadr (org-element-context)) :language))
-                       (and (if (listp face)
-                                (memq 'markdown-code-face face)
-                              (eq 'markdown-code-face face))
-                            (save-excursion
+  (when-let* ((face (get-text-property (point) 'face))
+              (lang (or (and (if (listp face)
+                                 (memq 'org-block face)
+                               (eq 'org-block face))
+                             (plist-get (cadr (org-element-context)) 
:language))
+                        (and (if (listp face)
+                                 (memq 'markdown-code-face face)
+                               (eq 'markdown-code-face face))
+                             (save-excursion
                               (markdown-code-block-lang))))))
     (member lang langs)))
 
@@ -720,9 +720,9 @@ If INTERACTIVE is nil the function acts like a Capf."
       ;; No cycling since it breaks the :exit-function.
       (let (completion-cycle-threshold)
         (cape-interactive #'cape-abbrev))
-    (when-let (abbrevs (cape--abbrev-list))
-      (let ((bounds (cape--bounds 'symbol)))
-        `(,(car bounds) ,(cdr bounds) ,abbrevs ,@cape--abbrev-properties)))))
+    (when-let* ((abbrevs (cape--abbrev-list))
+                (bounds (cape--bounds 'symbol)))
+      `(,(car bounds) ,(cdr bounds) ,abbrevs ,@cape--abbrev-properties))))
 
 ;;;;; cape-line
 
@@ -824,9 +824,9 @@ again if the input prefix changed."
       (funcall backend 'init)
       (put backend 'company-init t)
       (setf (alist-get backend cape--company-init) t))
-    (when-let ((pre (pcase (cape--company-call backend 'prefix)
-                      ((or `(,p ,_s) (and (pred stringp) p)) (cons p (length 
p)))
-                      ((or `(,p ,_s ,l) `(,p . ,l)) (cons p l)))))
+    (when-let* ((pre (pcase (cape--company-call backend 'prefix)
+                       ((or `(,p ,_s) (and (pred stringp) p)) (cons p (length 
p)))
+                       ((or `(,p ,_s ,l) `(,p . ,l)) (cons p l)))))
       (let* ((end (point)) (beg (- end (length (car pre))))
              (valid (if (cape--company-call backend 'no-cache (car pre))
                         #'equal (or valid #'string-prefix-p)))
@@ -858,7 +858,7 @@ again if the input prefix changed."
               :display-sort-function sort-fun
               :cycle-sort-function sort-fun
               :annotation-function (lambda (x)
-                                     (when-let (ann (cape--company-call 
backend 'annotation x))
+                                     (when-let* ((ann (cape--company-call 
backend 'annotation x)))
                                        (concat " " (string-trim ann))))
               :exit-function (lambda (x _status)
                                ;; Restore the candidate string including
@@ -914,9 +914,9 @@ the `completion-at-point-functions':
 
 See the dual `cape-wrap-choose' if you want to try multiple Capfs in
 turn."
-  (when-let ((results (cl-loop for capf in capfs until (eq capf :with)
-                               for res = (funcall capf)
-                               if res collect (cons t res))))
+  (when-let* ((results (cl-loop for capf in capfs until (eq capf :with)
+                                for res = (funcall capf)
+                                if res collect (cons t res))))
     (pcase-let* ((results (nconc results
                                  (cl-loop for capf in (cdr (memq :with capfs))
                                           for res = (funcall capf)
@@ -936,7 +936,7 @@ turn."
                  (push (list main (plist-get plist :predicate) table
                              ;; Plist attached to the candidates
                              (mapcan (lambda (f)
-                                       (when-let ((v (plist-get plist f)))
+                                       (when-let* ((v (plist-get plist f)))
                                          (list f v)))
                                      cape--super-functions))
                        tables)
@@ -1010,11 +1010,11 @@ turn."
             (lambda (prop)
               (list prop
                     (lambda (cand &rest args)
-                      (if-let ((ref (get-text-property 0 'cape-capf-super 
cand)))
-                          (when-let ((fun (plist-get (cdr ref) prop)))
+                      (if-let* ((ref (get-text-property 0 'cape-capf-super 
cand)))
+                          (when-let* ((fun (plist-get (cdr ref) prop)))
                             (apply fun (car ref) args))
-                        (when-let ((plist (and cand-ht (gethash cand cand-ht)))
-                                   (fun (plist-get plist prop)))
+                        (when-let* ((plist (and cand-ht (gethash cand 
cand-ht)))
+                                    (fun (plist-get plist prop)))
                           (apply fun cand args))))))
             cape--super-functions)))))
 
@@ -1072,7 +1072,7 @@ meaningful debugging output."
      `( ,beg ,end
         ,(cape--debug-table
           table name (copy-marker beg) (copy-marker end t))
-        ,@(when-let ((exit (plist-get plist :exit-function)))
+        ,@(when-let* ((exit (plist-get plist :exit-function)))
             (list :exit-function
                   (lambda (str status)
                     (cape--debug-message "%s:exit(status=%s string=%S)"
@@ -1162,7 +1162,7 @@ The PREDICATE is passed the candidate symbol or string."
     (`(,beg ,end ,table . ,plist)
      `( ,beg ,end ,table
         :predicate
-        ,(if-let (pred (plist-get plist :predicate))
+        ,(if-let* ((pred (plist-get plist :predicate)))
              ;; First argument is key, second is value for hash tables.
              ;; The first argument can be a cons cell for alists. Then
              ;; the candidate itself is either a string or a symbol. We
@@ -1213,11 +1213,11 @@ If the prefix is long enough, enforce auto completion."
 ;;;###autoload
 (defun cape-wrap-inside-faces (capf &rest faces)
   "Call CAPF only if inside FACES."
-  (when-let (((> (point) (point-min)))
-             (fs (get-text-property (1- (point)) 'face))
-             ((if (listp fs)
-                  (cl-loop for f in fs thereis (memq f faces))
-                (memq fs faces))))
+  (when-let* (((> (point) (point-min)))
+              (fs (get-text-property (1- (point)) 'face))
+              ((if (listp fs)
+                   (cl-loop for f in fs thereis (memq f faces))
+                 (memq fs faces))))
     (funcall capf)))
 
 ;;;###autoload
@@ -1258,8 +1258,8 @@ Example:
   (setq corfu-auto-trigger \"/\"
         completion-at-point-functions
         (list (cape-capf-trigger \\='cape-abbrev ?/)))"
-  (when-let ((pos (save-excursion (search-backward (char-to-string trigger) 
(pos-bol) 'noerror)))
-             ((save-excursion (not (re-search-backward "\\s-" pos 'noerror)))))
+  (when-let* ((pos (save-excursion (search-backward (char-to-string trigger) 
(pos-bol) 'noerror)))
+              ((save-excursion (not (re-search-backward "\\s-" pos 
'noerror)))))
     (pcase
         ;; Treat the trigger character as punctuation.
         (with-syntax-table cape--trigger-syntax-table
@@ -1275,7 +1275,7 @@ Example:
                    (end (copy-marker (1+ pos))))
                (lambda (str status)
                  (delete-region pos end)
-                 (when-let ((exit (plist-get plist :exit-function)))
+                 (when-let* ((exit (plist-get plist :exit-function)))
                    (funcall exit str status))))
             . ,plist))))))
 

Reply via email to