Change to when-let* and if-let*

This commit is contained in:
2026-01-25 18:18:56 -08:00
parent 4502284adc
commit 7a6c9dbd4b
10 changed files with 200 additions and 200 deletions

View File

@ -40,8 +40,8 @@ from inside a C++-style single-line comment."
(interactive "*Pi")
(when (and arg (< (prefix-numeric-value arg) 0))
(user-error "Count cannot be negative"))
(if-let ((bounds (c-comments-bounds-at-point))
((or always-continue (not (nth 7 (syntax-ppss))))))
(if-let* ((bounds (c-comments-bounds-at-point))
((or always-continue (not (nth 7 (syntax-ppss))))))
(progn
(when (c-comments--need-comment-terminator bounds)
(save-excursion

View File

@ -49,7 +49,7 @@ As this is :around advice, OLDFUN is the real (advised) function to call."
(defun ctp--load-content (candidate buffer)
"Load the documentation for CANDIDATE into BUFFER."
(when-let ((content (funcall corfu-popupinfo--function candidate)))
(when-let* ((content (funcall corfu-popupinfo--function candidate)))
;; A bunch of this comes straight from `corfu-popupinfo--show'
(with-current-buffer buffer
(dolist (var corfu-popupinfo--buffer-parameters)
@ -86,7 +86,7 @@ As this is :around advice, OLDFUN is the real (advised) function to call."
(forward-line))))
(goto-char (point-min))
(put-text-property (point-min) (point-max) 'face 'corfu-popupinfo)
(when-let ((m (memq 'corfu-default (alist-get 'default face-remapping-alist))))
(when-let* ((m (memq 'corfu-default (alist-get 'default face-remapping-alist))))
(setcar m 'corfu-popupinfo)))
;; We succeeded in loading the data
t))
@ -95,20 +95,20 @@ As this is :around advice, OLDFUN is the real (advised) function to call."
"Find a good position to open the popon for BUFFER's content.
Return a list of the position, the max line length that can be shown, and the
max height that can be shown. Each line of BUFFER _MUST_ be the same lenght."
(when-let ((point-posn (posn-at-point))
(point-x (car (posn-x-y point-posn)))
(point-y (cdr (posn-x-y point-posn))))
(when-let* ((point-posn (posn-at-point))
(point-x (car (posn-x-y point-posn)))
(point-y (cdr (posn-x-y point-posn))))
(with-current-buffer buffer
(when-let ((completion-pos (popon-position corfu-terminal--popon))
(completion-size (popon-size corfu-terminal--popon))
(comp-x (car completion-pos))
(comp-y (cdr completion-pos))
(comp-w (car completion-size))
(comp-h (cdr completion-size))
(win-w (window-max-chars-per-line))
(win-h (window-body-height))
(line-len (- (pos-eol) (pos-bol)))
(num-lines (count-lines (point-min) (point-max))))
(when-let* ((completion-pos (popon-position corfu-terminal--popon))
(completion-size (popon-size corfu-terminal--popon))
(comp-x (car completion-pos))
(comp-y (cdr completion-pos))
(comp-w (car completion-size))
(comp-h (cdr completion-size))
(win-w (window-max-chars-per-line))
(win-h (window-body-height))
(line-len (- (pos-eol) (pos-bol)))
(num-lines (count-lines (point-min) (point-max))))
(let* ((align 'row)
(width (min line-len corfu-popupinfo-max-width))
(pop-x (cond
@ -178,8 +178,8 @@ The content extracted is for a popon of size WIDTH by HEIGHT."
(cl-destructuring-bind (&optional pos width height)
(ctp--popon-position buffer)
(popon-kill ctp--popon)
(when-let ((pos)
(content (ctp--extract-content buffer width height)))
(when-let* ((pos)
(content (ctp--extract-content buffer width height)))
(setq ctp--popon
;; appear behind the auto-complete window, in case something
;; happens
@ -212,10 +212,10 @@ CANDIDATE is the same as for `corfu-popupinfo--show'. As this is meant to be
(defun ctp--move-away-from-eob ()
"Ensure the point isn't too close to the end of the buffer."
(if-let ((total-lines (count-lines (point-min) (point-max)))
((> total-lines corfu-popupinfo-max-height))
(rem-lines (count-lines (point) (point-max)))
((< rem-lines corfu-popupinfo-max-height)))
(if-let* ((total-lines (count-lines (point-min) (point-max)))
((> total-lines corfu-popupinfo-max-height))
(rem-lines (count-lines (point) (point-max)))
((< rem-lines corfu-popupinfo-max-height)))
(forward-line (- (- corfu-popupinfo-max-height rem-lines)))))
(defun ctp--corfu-popupinfo-scroll-up-advice

View File

@ -92,7 +92,7 @@ Note that the foreground color will be overridden by the module."
(defun eshell-starship--module-by (field key)
"Lookup a list of modules with a FIELD corresponding to KEY.
FIELD should be one of the keys in `eshell-starship--modules-by'."
(when-let ((table (plist-get eshell-starship--modules-by field)))
(when-let* ((table (plist-get eshell-starship--modules-by field)))
(gethash key table)))
(defvar eshell-starship--extra-module-files ()
@ -302,7 +302,7 @@ The number is rounded to PLACES before being rendered."
MODULES can also be a single module."
(dolist (module (ensure-list modules))
(when (symbolp module) (setq module (symbol-name module)))
(when-let ((cur-entry (gethash module eshell-starship--module-cache)))
(when-let* ((cur-entry (gethash module eshell-starship--module-cache)))
(setf (car cur-entry) nil))))
@ -336,8 +336,8 @@ Example:
(eshell-starship--limit-path-parts
3 (let ((cwd (or (file-remote-p default-directory 'localname)
default-directory)))
(if-let ((worktree (vc-root-dir))
(parent (file-name-parent-directory worktree)))
(if-let* ((worktree (vc-root-dir))
(parent (file-name-parent-directory worktree)))
(file-relative-name cwd (or (file-remote-p parent 'localname)
parent))
(eshell-starship--replace-home-with-tilda cwd))))
@ -507,8 +507,8 @@ For example, a revert. If there is no current operation, return nil."
;;; Non-git VC module
(defun eshell-starship--vc-status ()
"Get vc status for `eshell-starship--prompt-function'."
(when-let ((backend (vc-responsible-backend default-directory t))
((not (eq backend 'Git))))
(when-let* ((backend (vc-responsible-backend default-directory t))
((not (eq backend 'Git))))
(downcase (symbol-name backend))))
(eshell-starship-defmodule vc
@ -672,12 +672,12 @@ This requires pyvenv.el or pyenv-mode to work."
(and (bound-and-true-p pyvenv-virtual-env-name)
(format " (%s)" pyvenv-virtual-env-name))
(and (fboundp 'pyenv-mode-version)
(when-let ((ver (pyenv-mode-version)))
(when-let* ((ver (pyenv-mode-version)))
(format " (%s)" ver)))))
(defun eshell-starship--python-status ()
"Return the prompt string for the python module."
(when-let
(when-let*
((python-exec (or (bound-and-true-p python-interpreter) "python"))
(output (process-lines-ignore-status python-exec "--version"))
((string-match "^Python \\([0-9.]+\\)" (car output))))
@ -834,8 +834,8 @@ That is, if EXT is \"pkg.tar.gz\", this will return
(defun eshell-starship--file-name-extension (name)
"Return the extension for a file name NAME."
(if-let ((start (if (string-prefix-p "." name) 1 0))
(idx (cl-position ?. name :start start :test '=)))
(if-let* ((start (if (string-prefix-p "." name) 1 0))
(idx (cl-position ?. name :start start :test '=)))
(substring name (1+ idx))
""))
@ -921,19 +921,19 @@ Also cache the time it took to run it and its output."
(setq start-time (float-time)
result (funcall action)
end-time (float-time))
(when-let ((result)
(output
(concat prefix
(eshell-starship--propertize-face
icon t
(when color
(list (list :foreground color)))
'eshell-starship-icon-face)
(if color
(eshell-starship--propertize-face
result t (list :foreground color))
result)
postfix)))
(when-let* ((result)
(output
(concat prefix
(eshell-starship--propertize-face
icon t
(when color
(list (list :foreground color)))
'eshell-starship-icon-face)
(if color
(eshell-starship--propertize-face
result t (list :foreground color))
result)
postfix)))
(puthash name (list t output (cons (- end-time start-time)
(take 9 oldtimes)))
eshell-starship--module-cache)
@ -1163,7 +1163,7 @@ If NO-OUTPUT is non-nil, don't insert the modules previous output."
:test 'equal)
(if (eq cur-name t)
(setq rest-point (point))
(when-let ((module (gethash cur-name eshell-starship-modules)))
(when-let* ((module (gethash cur-name eshell-starship-modules)))
(eshell-starship--explain-insert-module module)
(remhash cur-name rest-modules)))))
(save-excursion
@ -1196,7 +1196,7 @@ If NO-OUTPUT is non-nil, don't insert the modules previous output."
(insert (heading "There are no disabled modules."))
(insert (heading "The following modules are disabled:\n"))
(dolist (name eshell-starship-disabled-modules)
(when-let ((module (gethash name eshell-starship-modules)))
(when-let* ((module (gethash name eshell-starship-modules)))
(eshell-starship--explain-insert-module module t)))
;; get rid of newline
(delete-char -1))))

View File

@ -349,9 +349,9 @@ The completion table contains just the last component. Therefore, the capf
should specify the START position of this table to be the first character after
the last slash (/) on the line. If none of that made sense, see the
documentation for `completion-at-point-functions'."
(if-let ((last-slash (cl-position ?/ current-input :from-end t))
(base (file-truename
(substring current-input 0 (1+ last-slash)))))
(if-let* ((last-slash (cl-position ?/ current-input :from-end t))
(base (file-truename
(substring current-input 0 (1+ last-slash)))))
(let ((default-directory base))
(firejail--collect-includes default-directory))
(firejail--collect-includes)))
@ -397,8 +397,8 @@ in it."
CURRENT-INPUT is the current text of the argument to complete. With DIR-ONLY,
only report directory completions."
(ignore-error file-missing
(let ((dir (if-let ((last-idx (cl-position ?/ current-input
:from-end t)))
(let ((dir (if-let* ((last-idx (cl-position ?/ current-input
:from-end t)))
(substring current-input 0 (1+ last-idx))
current-input)))
(cl-loop for (name type) in (directory-files-and-attributes dir)
@ -471,8 +471,8 @@ With NO-ABSOLUTE, don't complete absolute file names."
(let ((,idirs (cl-remove-if-not #'file-directory-p
(ensure-list ',evaled-dirs)))
(,adirname (file-name-directory (cl-third (nth ,index ,args)))))
(if-let ((cache (gethash (cons ,adirname ,dirs)
firejail--relative-to-cache)))
(if-let* ((cache (gethash (cons ,adirname ,dirs)
firejail--relative-to-cache)))
cache
(let (,out)
(dolist (,dir ,idirs)
@ -511,7 +511,7 @@ With NO-ABSOLUTE, don't complete absolute file names."
(defun firejail--get-all-env-keys ()
"Return the name of every current environment variable."
(mapcar (lambda (elt)
(if-let ((sep (cl-position ?= elt)))
(if-let* ((sep (cl-position ?= elt)))
(substring elt 0 sep)
elt))
process-environment))
@ -681,10 +681,10 @@ argument character on the current line."
(let* ((cur-arg (if (firejail--multi-arg-directive-p directive)
(firejail--count-args arg-start (point))
1)))
(when-let ((handler (or (gethash (cons directive nil)
firejail-profile--keyword-handlers)
(gethash (cons directive cur-arg)
firejail-profile--keyword-handlers))))
(when-let* ((handler (or (gethash (cons directive nil)
firejail-profile--keyword-handlers)
(gethash (cons directive cur-arg)
firejail-profile--keyword-handlers))))
(funcall handler (1- cur-arg)
(firejail--current-args directive arg-start)
directive))))
@ -823,8 +823,8 @@ Return a list of the formatted doc and a summary."
(defun firejail-eldoc-documentation-function (callback &rest _args)
"Call CALLBACK with the documentation of the directive under point."
(save-excursion
(when-let ((name (firejail--directive-at-point))
(doc (firejail--documentation-for name)))
(when-let* ((name (firejail--directive-at-point))
(doc (firejail--documentation-for name)))
(cl-destructuring-bind (clean-doc summary)
(firejail--format-doc-string-and-get-summary name doc)
(funcall callback clean-doc `(:thing ,name

View File

@ -100,7 +100,7 @@ languages supported by this interpreter."))
(back-to-indentation)
(unless (> (point) start)
(goto-char start)))
(when-let ((thing (treesit-thing-at-point "_" 'nested)))
(when-let* ((thing (treesit-thing-at-point "_" 'nested)))
(inf-cc--remove-trailing-semicolon (treesit-node-text thing)))))
(defun inf-cc--java-ts-exp-at-point ()
@ -215,24 +215,24 @@ Note that this erases the buffer before doing anything."
(defun inf-cc--fontify-current-input ()
"Function called from `post-command-hook' to fontify the current input."
(when-let (((inf-cc-font-lock-mode inf-cc--obj))
(proc (get-buffer-process (current-buffer)))
(start (process-mark proc))
(end (point-max))
(input (buffer-substring-no-properties start end))
(fontified (inf-cc--with-font-lock-buffer
(insert input)
(font-lock-ensure)
(buffer-string)))
(len (length fontified))
(i 0))
(when-let* (((inf-cc-font-lock-mode inf-cc--obj))
(proc (get-buffer-process (current-buffer)))
(start (process-mark proc))
(end (point-max))
(input (buffer-substring-no-properties start end))
(fontified (inf-cc--with-font-lock-buffer
(insert input)
(font-lock-ensure)
(buffer-string)))
(len (length fontified))
(i 0))
;; mostly from:
;; `python-shell-font-lock-post-command-hook'
(while (not (= i len))
(let* ((props (text-properties-at i fontified))
(change-i (or (next-property-change i fontified)
len)))
(when-let ((face (plist-get props 'face)))
(when-let* ((face (plist-get props 'face)))
(setf (plist-get props 'face) nil
(plist-get props 'font-lock-face) face))
(set-text-properties (+ start i) (+ start change-i) props)
@ -328,9 +328,9 @@ You MUST set `inf-cc--obj' before activating this major mode."
indent-line-function #'inf-cc--indent-line-function
electric-indent-chars '(?\n ?})
mode-name (concat "Inferior " (upcase-initials name)))
(when-let ((font-lock-mode)
(sym (intern-soft (format "%s-syntax-table" font-lock-mode)))
(syntax-table (symbol-value sym)))
(when-let* ((font-lock-mode)
(sym (intern-soft (format "%s-syntax-table" font-lock-mode)))
(syntax-table (symbol-value sym)))
(set-syntax-table syntax-table)))
(add-hook 'comint-preoutput-filter-functions
#'inf-cc--preoutput-filter-function

View File

@ -36,8 +36,8 @@ This exists so that Emacs doesn't slow down while running
(defun khard--prompt-contact (&optional prompt)
"Prompt user for a contact, optionally make the prompt text PROMPT."
(if-let ((uid-list (khard--build-uid-email-phone-list))
(resp (completing-read (or prompt "Contact ") uid-list)))
(if-let* ((uid-list (khard--build-uid-email-phone-list))
(resp (completing-read (or prompt "Contact ") uid-list)))
(assoc resp uid-list)))
(defun khard--process-sentinel (proc status)
@ -110,9 +110,9 @@ When called interactively, prompt the user."
(defun khard--parse-email-list (list-str)
"Parse LIST-STR, a python dictionary and array string of emails."
(if-let ((length (length list-str))
((>= length 2))
(no-braces (substring list-str 1 -1)))
(if-let* ((length (length list-str))
((>= length 2))
(no-braces (substring list-str 1 -1)))
(let ((output nil)
(in-quote nil)
(backslash nil)
@ -167,8 +167,8 @@ With FORCE, rebuild the cache no matter what."
(defun khard-insert-email-contact ()
"Use `completing-read' to prompt for and insert a khard contact."
(interactive)
(if-let (contact (completing-read "Insert Contact "
(khard--contacts-cache t)))
(if-let* ((contact (completing-read "Insert Contact "
(khard--contacts-cache t))))
(insert contact)))
(defun khard--message-in-header-p (name &optional testfn)
@ -185,7 +185,7 @@ The name is compared with the field name using TESTFN (defaults to `equal')."
(defun khard-message-mode-capf ()
"Completion at point function for khard contacts in message mode."
(interactive)
(when-let ((field-start (khard--message-in-header-p "To")))
(when-let* ((field-start (khard--message-in-header-p "To")))
(save-excursion
(let ((end (point)))
(re-search-backward (rx (any "\n" "," ":") (* whitespace))

View File

@ -185,7 +185,7 @@ return t. Otherwise, kill the buffer and return nil."
(kill-buffer (current-buffer))
(user-error "File \"%s\" is binary" file)))
;; we are good to go
(when-let (old-buffer (get-buffer latex-help-texdoc-buffer-name))
(when-let* ((old-buffer (get-buffer latex-help-texdoc-buffer-name)))
(kill-buffer old-buffer))
(rename-buffer latex-help-texdoc-buffer-name)
(pop-to-buffer (current-buffer))))))
@ -337,9 +337,9 @@ This returns a list of conses of the display name of the entry and the file it
belongs to. The first item the the returned list is the default value when
prompting with `completing-read'."
(with-temp-buffer
(when-let ((exit-code (call-process latex-help-texdoc-program nil t
nil "-Ml" entry))
((not (zerop exit-code))))
(when-let* ((exit-code (call-process latex-help-texdoc-program nil t
nil "-Ml" entry))
((not (zerop exit-code))))
;; try to get the programs output without the normal Emacs process
;; sentinel message
(goto-char (point-max))
@ -427,11 +427,11 @@ This is done by parsing the index for `latex-help-info-manual'."
(*? any) ":" (+ " ")
(group (+? any)) ".")))))
(push (list "(SPACE)" "\\(SPACE)") found)
(when-let (entry (assoc "(...\\)" found))
(when-let* ((entry (assoc "(...\\)" found)))
(setq found (assoc-delete-all "(...\\)" found))
(push (cons "(" (cdr entry)) found)
(push (cons ")" (cdr entry)) found))
(when-let (entry (assoc "[...\\]" found))
(when-let* ((entry (assoc "[...\\]" found)))
(setq found (assoc-delete-all "[...\\]" found))
(push (cons "[" (cdr entry)) found)
(push (cons "]" (cdr entry)) found))
@ -497,7 +497,7 @@ they want to use.
If DEFAULT is non-nil, use that instead of prompting. If it does not exist,
return nil."
(when-let (entries (cdr (assoc name (latex-help--get-cache-for-type type))))
(when-let* ((entries (cdr (assoc name (latex-help--get-cache-for-type type)))))
(cond
(default
(assoc default entries))
@ -531,7 +531,7 @@ This returns the name of the thing that was prompted."
Unless NODE is non-nil, if NAME is in more than one node, prompt the user for
which to use. If NODE is non-nil, use that instead."
(interactive (list (latex-help--prompt-for 'command)))
(when-let (entry (latex-help--maybe-prompt-entry name 'command node))
(when-let* ((entry (latex-help--maybe-prompt-entry name 'command node)))
(latex-help--info-goto-entry entry)))
;;;###autoload
@ -540,7 +540,7 @@ which to use. If NODE is non-nil, use that instead."
Unless NODE is non-nil, if NAME is in more than one node, prompt the user for
which to use. If NODE is non-nil, use that instead."
(interactive (list (latex-help--prompt-for 'environment)))
(when-let (entry (latex-help--maybe-prompt-entry name 'environment node))
(when-let* ((entry (latex-help--maybe-prompt-entry name 'environment node)))
(latex-help--info-goto-entry entry)))
;;;###autoload
@ -549,7 +549,7 @@ which to use. If NODE is non-nil, use that instead."
Unless NODE is non-nil, if NAME is in more than one node, prompt the user for
which to use. If NODE is non-nil, use that instead."
(interactive (list (latex-help--prompt-for 'package)))
(when-let (entry (latex-help--maybe-prompt-entry name 'package node))
(when-let* ((entry (latex-help--maybe-prompt-entry name 'package node)))
(latex-help--info-goto-entry entry)))
;;;###autoload
@ -558,7 +558,7 @@ which to use. If NODE is non-nil, use that instead."
Unless NODE is non-nil, if NAME is in more than one node, prompt the user for
which to use. If NODE is non-nil, use that instead."
(interactive (list (latex-help--prompt-for 'class)))
(when-let (entry (latex-help--maybe-prompt-entry name 'class node))
(when-let* ((entry (latex-help--maybe-prompt-entry name 'class node)))
(latex-help--info-goto-entry entry)))
;;;###autoload
@ -567,7 +567,7 @@ which to use. If NODE is non-nil, use that instead."
When used interactively, prompt for NAME."
(interactive (list (latex-help--prompt-texdoc-entry)))
(latex-help--maybe-init-caches)
(when-let ((file (latex-help--texdoc-prompt-for-entry-file name)))
(when-let* ((file (latex-help--texdoc-prompt-for-entry-file name)))
(latex-help--texdoc-open-file file)))
(defun latex-help--prompt-info-and-texdoc (info-entry texdoc-entry)
@ -604,7 +604,7 @@ point. If that thing at point is valid, it will open an info buffer to the
documentation for that thing."
(interactive)
(latex-help--maybe-init-caches)
(if-let (thing (latex-help--get-thing-at-point))
(if-let* ((thing (latex-help--get-thing-at-point)))
(let ((info-entry (assoc (car thing) (latex-help--get-cache-for-type
(cdr thing))))
(texdoc-entry (and (member (cdr thing) '(class package environment))
@ -658,23 +658,23 @@ Prompt the user for an info topic or texdoc file, then open that thing."
(equal entry (car tap)))
(setq def-entry (car prompts)
def-name entry)))
(when-let ((ans (completing-read (format "LaTeX Help%s: "
(if def-name
(format " (default %s)"
def-name)
""))
prompts
nil t nil 'latex-help--general-history
def-entry))
((not (zerop (length ans)))))
(when-let* ((ans (completing-read (format "LaTeX Help%s: "
(if def-name
(format " (default %s)"
def-name)
""))
prompts
nil t nil 'latex-help--general-history
def-entry))
((not (zerop (length ans)))))
(if (string-prefix-p "(Texdoc) " ans)
(latex-help-texdoc (seq-subseq ans (length "(Texdoc) ")))
(string-match (rx "(Info) " (group (+ (not " ")))
" - " (group (+ any)))
ans)
(when-let ((thing (match-string 2 ans))
(type (intern (downcase (match-string 1 ans))))
(entry (latex-help--maybe-prompt-entry thing type)))
(when-let* ((thing (match-string 2 ans))
(type (intern (downcase (match-string 1 ans))))
(entry (latex-help--maybe-prompt-entry thing type)))
(latex-help--info-goto-entry entry)))))))
(provide 'latex-help)

View File

@ -264,7 +264,7 @@ SERVER is the server from which to get the rules."
"Setup up SERVER for the first time."
;; make sure that dir local stuff is picked up
(save-current-buffer
(when-let ((buf (cl-first (eglot--managed-buffers server))))
(when-let* ((buf (cl-first (eglot--managed-buffers server))))
(set-buffer buf))
(setf
;; merger of global values is mediated elsewhere
@ -392,7 +392,7 @@ language setting in any file."
current-prefix-arg))
(unless (ltex-eglot-server-p server)
(user-error "Current server is not an LTeX server!"))
(when-let ((server (eglot-current-server)))
(when-let* ((server (eglot-current-server)))
(setf (ltex-eglot-server--language server) language)
(let ((ltex-eglot-variable-save-method
(and (not no-save)

View File

@ -74,8 +74,8 @@ about this change."
(defun org-mu4e--pretty-print-fontify-html-part ()
"Pretty print and fontify the HTML part of the current buffer."
(when-let ((bounds (org-mu4e--bounds-of-mime-part "text/html"))
(real-buf (current-buffer)))
(when-let* ((bounds (org-mu4e--bounds-of-mime-part "text/html"))
(real-buf (current-buffer)))
(save-excursion
(let ((content
(with-temp-buffer
@ -145,9 +145,9 @@ Return the newly created buffer."
(default-directory org-preview-latex-image-directory)
(org-html-postamble nil))
(narrow-to-region start (point-max))
(if-let ((export-data (org-export-as
'html nil t nil
org-mime-export-options)))
(if-let* ((export-data (org-export-as
'html nil t nil
org-mime-export-options)))
(progn
(with-current-buffer buffer
(special-mode)