From: Stefan Monnier Date: Sat, 25 Jan 2025 15:39:12 +0000 (-0500) Subject: (when-let*): Warn if body is empty X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d91b8bb06bae4a109c526c0eaeb63b8f42f5cae2;p=emacs.git (when-let*): Warn if body is empty * 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) --- diff --git a/lisp/subr.el b/lisp/subr.el index e6c30c8eca5..4a0d3896a53 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -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. diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index a112cfc1179..877b46cbc0f 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -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