]> git.eshelyaron.com Git - emacs.git/commitdiff
(when-let*): Warn if body is empty
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 25 Jan 2025 15:39:12 +0000 (10:39 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sat, 25 Jan 2025 18:01:51 +0000 (19:01 +0100)
* lisp/subr.el (when-let*): Warn if body is empty.
* lisp/textmodes/tex-mode.el (xref-backend-references): Fix use of
`when-let*`.

(cherry picked from commit 442d04081bbe9913def50b543e499422c4ad9ece)

lisp/subr.el
lisp/textmodes/tex-mode.el

index e6c30c8eca53cf4fd810610e5cfb2348355c7777..4a0d3896a5385445cf9865553547df20855c946d 100644 (file)
@@ -2652,7 +2652,10 @@ The variable list VARLIST is the same as in `if-let*'.
 
 See also `and-let*'."
   (declare (indent 1) (debug if-let*))
-  (list 'if-let* varlist (macroexp-progn body)))
+  (let ((res (list 'if-let* varlist (macroexp-progn body))))
+    (if body res
+      (macroexp-warn-and-return "Avoid `when-let*' with empty body"
+                                res 'empty-body))))
 
 (defmacro and-let* (varlist &rest body)
   "Bind variables according to VARLIST and conditionally evaluate BODY.
index a112cfc11792e8ae3aa23f216c6d54a450ed67ad..877b46cbc0f342b6f9c02a529cc1d956456d412c 100644 (file)
@@ -3961,12 +3961,12 @@ There might be text before point."
                            (seq-union amalist extlist #'string-match-p))))
         (setq tex--buffers-list bufs)
         (dolist (buf bufs)
-          (when-let ((fbuf (buffer-file-name buf))
-                     (ext (file-name-extension fbuf))
-                     (finext (concat "*." ext))
-                     ((not (seq-find (lambda (elt) (string-match-p elt finext))
-                                     extlist-new)))
-                     ((push finext extlist-new)))))
+          (when-let* ((fbuf (buffer-file-name buf))
+                      (ext (file-name-extension fbuf))
+                      (finext (concat "*." ext))
+                      ((not (seq-find (lambda (elt) (string-match-p elt finext))
+                                      extlist-new))))
+            (push finext extlist-new)))
         (unless (seq-set-equal-p extlist-new extlist)
           (alist-set mode grep-filepattern-alist extlist-new))))
     (let* (setsyntax