From 7a6c9dbd4bd916945280f5f4ab1a9bbbe12396c2 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 25 Jan 2026 18:18:56 -0800 Subject: [PATCH] Change to when-let* and if-let* --- elisp/c-comments.el | 4 +- elisp/corfu-terminal-popupinfo.el | 42 ++++---- elisp/eshell-starship.el | 50 ++++----- elisp/firejail-mode.el | 28 ++--- elisp/inferior-cc.el | 32 +++--- elisp/khard.el | 16 +-- elisp/latex-help.el | 50 ++++----- elisp/ltex-eglot.el | 4 +- elisp/org-mu4e-compose.el | 10 +- init.el | 164 +++++++++++++++--------------- 10 files changed, 200 insertions(+), 200 deletions(-) diff --git a/elisp/c-comments.el b/elisp/c-comments.el index d73b60f..83ebaa9 100644 --- a/elisp/c-comments.el +++ b/elisp/c-comments.el @@ -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 diff --git a/elisp/corfu-terminal-popupinfo.el b/elisp/corfu-terminal-popupinfo.el index 7ebfd43..380b492 100644 --- a/elisp/corfu-terminal-popupinfo.el +++ b/elisp/corfu-terminal-popupinfo.el @@ -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 diff --git a/elisp/eshell-starship.el b/elisp/eshell-starship.el index fd44bec..e3dc5cd 100644 --- a/elisp/eshell-starship.el +++ b/elisp/eshell-starship.el @@ -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)))) diff --git a/elisp/firejail-mode.el b/elisp/firejail-mode.el index 7f163a7..6549618 100644 --- a/elisp/firejail-mode.el +++ b/elisp/firejail-mode.el @@ -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 diff --git a/elisp/inferior-cc.el b/elisp/inferior-cc.el index f61f173..73cf8ed 100644 --- a/elisp/inferior-cc.el +++ b/elisp/inferior-cc.el @@ -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 diff --git a/elisp/khard.el b/elisp/khard.el index dc4857e..0c3b089 100644 --- a/elisp/khard.el +++ b/elisp/khard.el @@ -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)) diff --git a/elisp/latex-help.el b/elisp/latex-help.el index 4a94207..53abc2b 100644 --- a/elisp/latex-help.el +++ b/elisp/latex-help.el @@ -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) diff --git a/elisp/ltex-eglot.el b/elisp/ltex-eglot.el index cb76db3..2680f30 100644 --- a/elisp/ltex-eglot.el +++ b/elisp/ltex-eglot.el @@ -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) diff --git a/elisp/org-mu4e-compose.el b/elisp/org-mu4e-compose.el index bbf544f..a3255ee 100644 --- a/elisp/org-mu4e-compose.el +++ b/elisp/org-mu4e-compose.el @@ -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) diff --git a/init.el b/init.el index ea98d3d..ffc1c6d 100644 --- a/init.el +++ b/init.el @@ -508,7 +508,7 @@ directory. Otherwise, run `find-file' on that file." (unless name (error "No bookmark specified")) (bookmark-maybe-historicize-string name) - (when-let ((file (bookmark-get-filename name))) + (when-let* ((file (bookmark-get-filename name))) (if (file-directory-p file) (let ((default-directory (file-name-as-directory file))) (call-interactively 'find-file)) @@ -931,13 +931,13 @@ environment variable accordingly." (xdg-runtime-dir) nil nil 'nosort) (cdr found)) (cl-destructuring-bind (name . attrs) entry - (when-let (((string-match (rx bos "wayland-" (group (+ (any "0-9"))) eos) - name)) - (id (string-to-number (match-string 1 name))) - ((or (not (car found)) (< id (car found)))) + (when-let* (((string-match (rx bos "wayland-" (group (+ (any "0-9"))) eos) + name)) + (id (string-to-number (match-string 1 name))) + ((or (not (car found)) (< id (car found)))) - ;; socket - ((string-prefix-p "s" (file-attribute-modes attrs)))) + ;; socket + ((string-prefix-p "s" (file-attribute-modes attrs)))) (setq found (cons id name))))))) (unless (getenv "WAYLAND_DISPLAY") (setenv "WAYLAND_DISPLAY" (my/detect-wayland-display))) @@ -1077,8 +1077,8 @@ visual states." "R" 'repunctuate-sentences) (defun my/embark-target-string () "Target the string at point." - (if-let (((not (eobp))) ; prevent next line from causing errors - (bounds (bounds-of-thing-at-point 'string))) + (if-let* (((not (eobp))) ; prevent next line from causing errors + (bounds (bounds-of-thing-at-point 'string))) (append (list 'string (buffer-substring-no-properties (car bounds) (cdr bounds))) bounds))) @@ -1184,8 +1184,8 @@ visual states." (let ((help-buf (my/help-buffer-exists-p))) (prog1 (apply oldfun args) - (when-let (((not help-buf)) - (buf (help-buffer))) + (when-let* (((not help-buf)) + (buf (help-buffer))) ;; Ensure that, even if `help-buffer' returns nil in the future, we ;; don't kill the current buffer (kill-buffer buf)))) @@ -1295,8 +1295,8 @@ If BUFFER is nil, the current buffer is used." "Show the diagnostics under point." (interactive) (let ((message)) - (when-let (((bound-and-true-p flymake-mode)) - (diag (get-char-property (point) 'flymake-diagnostic))) + (when-let* (((bound-and-true-p flymake-mode)) + (diag (get-char-property (point) 'flymake-diagnostic))) (cl-callf nconc message (string-split (flymake--diag-text diag) "\n" t))) (when (bound-and-true-p flycheck-mode) (cl-callf nconc message @@ -1307,8 +1307,8 @@ If BUFFER is nil, the current buffer is used." (plist-get note :message)) (my/sly-notes-at-point)))) ;; jinx - (when-let (((bound-and-true-p jinx-mode)) - (jinx-msg (jinx--get-overlays (point) (1+ (point))))) + (when-let* (((bound-and-true-p jinx-mode)) + (jinx-msg (jinx--get-overlays (point) (1+ (point))))) (push "misspelled word" message)) (when message (my/floating-tooltip " *my-diagnostic-posframe*" @@ -1348,10 +1348,10 @@ With PROJECT, return the candiadeets for that project." (prog1 (seq-uniq (append - (when-let (((bound-and-true-p flymake-mode)) - (diags (if project (flymake--project-diagnostics - project) - (flymake-diagnostics)))) + (when-let* (((bound-and-true-p flymake-mode)) + (diags (if project (flymake--project-diagnostics + project) + (flymake-diagnostics)))) (setq had-errors t) (my/-consult-replace-flymake-error-level (consult-flymake--candidates diags))) @@ -1432,15 +1432,15 @@ With PROJECT, give diagnostics for all buffers in the current project." (defun my/eglot-documentation-at-point () "Show documentation for a symbol at point." (interactive) - (if-let (server (eglot-current-server)) + (if-let* ((server (eglot-current-server))) (progn (unless (buffer-live-p my/-eglot-documentation-buffer) (setq my/-eglot-documentation-buffer (get-buffer-create "*eglot documentation*"))) (eglot-hover-eldoc-function (lambda (info _ _) - (if-let (((not (seq-empty-p info))) - (buff (current-buffer))) + (if-let* (((not (seq-empty-p info))) + (buff (current-buffer))) (with-current-buffer my/-eglot-documentation-buffer (let ((inhibit-read-only t)) (unless (derived-mode-p 'my/eglot-documentation-mode) @@ -1645,10 +1645,10 @@ With PROJECT, give diagnostics for all buffers in the current project." (defun my/project-eshell (prompt &optional arg) "Switch to or create an eshell buffer in the current projects root." (interactive (list t current-prefix-arg)) - (if-let ((proj (project-current prompt)) - (default-directory (project-root proj)) - (eshell-buffer-name - (concat "*eshell for project " default-directory "*"))) + (if-let* ((proj (project-current prompt)) + (default-directory (project-root proj)) + (eshell-buffer-name + (concat "*eshell for project " default-directory "*"))) (eshell arg))) (defun my/project-eshell-or-default (&optional arg) "Open an eshell for the current project, otherwise, open a normal eshell." @@ -1713,7 +1713,7 @@ COMMAND and COMINT are like `compile'." (setq my/project-run-command command)))) :config (defun my/project-try-dotfile (dir) - (if-let (root (locate-dominating-file dir my/project-root-marker)) + (if-let* ((root (locate-dominating-file dir my/project-root-marker))) (list 'vc nil root))) (add-hook 'project-find-functions #'my/project-try-dotfile) ;; `project-try-vc' causes consult file previews to break! @@ -2120,7 +2120,7 @@ This is :around advice, so OLDFUN is the real function (save-excursion (let ((start (point))) (beginning-of-defun) - (when-let ((sexp (nth 1 (parse-partial-sexp (point) start)))) + (when-let* ((sexp (nth 1 (parse-partial-sexp (point) start)))) (goto-char sexp) (looking-at (rx "(" (* (syntax whitespace)) ":")))))) @@ -2169,7 +2169,7 @@ line in the block and manually deal with indentation." (when (= (pos-bol) (pos-eol)) (beginning-of-line 2)) (<= (count-lines (match-beginning 0) (pos-eol)) - (if-let ((match (match-string 1))) + (if-let* ((match (match-string 1))) (string-to-number match) 1)))) (save-excursion @@ -2250,23 +2250,23 @@ Note that this erases the buffer before doing anything." (defun my/-sly-fontify-current-input () "Function called from `post-command-hook' to fontify the current input." (let ((deactivate-mark nil)) - (when-let ((proc (get-buffer-process (current-buffer))) - (start (process-mark proc)) - (end (point-max)) - (input (buffer-substring-no-properties start end)) - (fontified (my/-sly-with-font-lock-buffer - (insert input) - (font-lock-ensure) - (buffer-string))) - (len (length fontified)) - (i 0)) + (when-let* ((proc (get-buffer-process (current-buffer))) + (start (process-mark proc)) + (end (point-max)) + (input (buffer-substring-no-properties start end)) + (fontified (my/-sly-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) @@ -2302,12 +2302,12 @@ Note that this erases the buffer before doing anything." (defun my/-jupyter-dont-use-ts-modes (retval) "Prevent `jupyter-kernel-language-mode-properties' from selecting TS modes." (cl-destructuring-bind (mode syntax-table) retval - (if-let (((string-suffix-p "-ts-mode" (symbol-name mode))) - (non-ts (car (rassq mode major-mode-remap-alist))) - ((not (string-suffix-p "-ts-mode" (symbol-name non-ts))))) + (if-let* (((string-suffix-p "-ts-mode" (symbol-name mode))) + (non-ts (car (rassq mode major-mode-remap-alist))) + ((not (string-suffix-p "-ts-mode" (symbol-name non-ts))))) (list non-ts - (if-let ((table-sym (intern-soft (format "%s-syntax-table" - non-ts)))) + (if-let* ((table-sym (intern-soft (format "%s-syntax-table" + non-ts)))) (symbol-value table-sym) syntax-table)) retval))) @@ -2375,18 +2375,18 @@ Note that this erases the buffer before doing anything." (jupyter-kernel-language jupyter-current-client)))))) (buffer-list)))) - (when-let (((not res)) - (real (alist-get lang my/jupyter-extra-language-associations nil - nil #'cl-equalp))) + (when-let* (((not res)) + (real (alist-get lang my/jupyter-extra-language-associations nil + nil #'cl-equalp))) (setq res (my/-find-jupyter-buffer-for-lang real))) res)) (defun my/-jupyter-buffer-for-major-mode (&optional mode) "Return a Jupyter buffer that can evaluate the code MODE is editing. MODE defaults to `major-mode'." - (when-let ((name (symbol-name (or mode major-mode))) - ((string-match (rx bos (group (+? any)) (? "-ts") "-mode" eos) - name))) + (when-let* ((name (symbol-name (or mode major-mode))) + ((string-match (rx bos (group (+? any)) (? "-ts") "-mode" eos) + name))) (my/-find-jupyter-buffer-for-lang (match-string 1 name)))) (defun my/-jupyter-find-proper-buffer () @@ -2400,12 +2400,12 @@ MODE defaults to `major-mode'." "Eval CODE a buffer suitable for `major-mode'. If NO-ERROR is non-nil, signal an error if a buffer fails to be found. If the current buffer is a Jupyter buffer, just use that." - (interactive (list (if-let ((buffer (my/-jupyter-find-proper-buffer))) + (interactive (list (if-let* ((buffer (my/-jupyter-find-proper-buffer))) (with-current-buffer buffer (jupyter-read-expression)) (user-error "No Jupyter buffer found for mode: %s" major-mode)))) - (if-let ((buffer (my/-jupyter-find-proper-buffer))) + (if-let* ((buffer (my/-jupyter-find-proper-buffer))) (with-current-buffer buffer (let ((jupyter-repl-echo-eval-p t)) (jupyter-eval-string code))) @@ -2415,7 +2415,7 @@ current buffer is a Jupyter buffer, just use that." (defun my/jupyter-eval-defun () "Eval the defun under point by sending it to a Jupyter repl." (interactive) - (if-let ((code (thing-at-point 'defun))) + (if-let* ((code (thing-at-point 'defun))) (progn (my/jupyter-eval-in-proper-buffer code) (message "Evaluated defun")) @@ -2443,8 +2443,8 @@ current buffer is a Jupyter buffer, just use that." (back-to-indentation) (unless (> (point) start) (goto-char start))) - (if-let ((thing (treesit-thing-at-point "_" 'nested)) - (code (treesit-node-text thing))) + (if-let* ((thing (treesit-thing-at-point "_" 'nested)) + (code (treesit-node-text thing))) (progn (my/jupyter-eval-in-proper-buffer code) (message "Evaluated: %s" code)) @@ -2523,7 +2523,7 @@ current buffer is a Jupyter buffer, just use that." "Display calculator icons and info." (concat (doom-modeline-spc) - (when-let ((icon (doom-modeline-icon 'faicon "nf-fa-calculator" "🖩" ""))) + (when-let* ((icon (doom-modeline-icon 'faicon "nf-fa-calculator" "🖩" ""))) (concat (doom-modeline-display-icon icon) (doom-modeline-vspc))) @@ -2687,8 +2687,8 @@ Actually, return the method name." (defun my/project-eat (&optional arg prompt) "Switch to or create a eat buffer in the current projects root." (interactive (list current-prefix-arg t)) - (if-let ((proj (project-current prompt)) - (default-directory (project-root proj))) + (if-let* ((proj (project-current prompt)) + (default-directory (project-root proj))) (let ((eat-buffer-name (format "*eat for project %s*" default-directory))) (eat (my/-eat-shell-for-cwd) arg)))) (defun my/project-eat-or-default (&optional arg) @@ -2843,15 +2843,15 @@ If no name is given, list all bookmarks instead." arg) (let ((bm-name (match-string 1 arg)) (after-path (match-string 2 arg))) - (when-let ((base (ignore-errors (bookmark-get-filename bm-name))) - ((file-directory-p base)) - (abs-path (expand-file-name after-path base)) - (dir-path (if (string-empty-p after-path) - abs-path - (file-name-directory abs-path))) - (path-end (if (string-empty-p after-path) - "" - (file-name-nondirectory abs-path)))) + (when-let* ((base (ignore-errors (bookmark-get-filename bm-name))) + ((file-directory-p base)) + (abs-path (expand-file-name after-path base)) + (dir-path (if (string-empty-p after-path) + abs-path + (file-name-directory abs-path))) + (path-end (if (string-empty-p after-path) + "" + (file-name-nondirectory abs-path)))) (pcomplete-here (mapcan (lambda (entry) (unless (member (car entry) '(".." ".")) @@ -2994,7 +2994,7 @@ ARG is the same as for either of the above functions." (hash-table-p (cdr my/-dirvish-uid-name-cache))) (setq my/-dirvish-uid-name-cache (cons root (make-hash-table :test 'equal)))) - (if-let ((name (gethash uid (cdr my/-dirvish-uid-name-cache)))) + (if-let* ((name (gethash uid (cdr my/-dirvish-uid-name-cache)))) (setq uid name) (let* ((new-attrs (file-attributes f-name 'string)) (new-name (file-attribute-user-id new-attrs))) @@ -3390,7 +3390,7 @@ buffers `helpful--sym' to `my/helpful-symbol-history'." (not (eq buf helpful-buf)) (eq (buffer-local-value 'major-mode buf) 'helpful-mode)) do - (when-let (cur-window (get-buffer-window buf nil)) + (when-let* ((cur-window (get-buffer-window buf nil))) (setq window cur-window)) (kill-buffer buf) finally @@ -3398,9 +3398,9 @@ buffers `helpful--sym' to `my/helpful-symbol-history'." (buffer-local-value 'helpful--callable-p helpful-buf)))) (unless my/-helpful-inhibit-history - (when-let (from-current-hist - (member my/-helpful-last-entry - my/helpful-symbol-history)) + (when-let* ((from-current-hist + (member my/-helpful-last-entry + my/helpful-symbol-history))) (setq my/helpful-symbol-history from-current-hist)) (cl-pushnew entry my/helpful-symbol-history :test 'equal) (setq my/helpful-symbol-history @@ -3487,15 +3487,15 @@ Color can be any color which can be passed to `color-values'." (defun my/-rainbow-delimiters-recalc-dark-faces (&optional frame) (unless frame (setq frame (selected-frame))) (dotimes (i 9) - (when-let ((old-face (intern-soft - (format "rainbow-delimiters-depth-%d-face" - (1+ i)))) - (new-face - (intern - (format "my/rainbow-delimiters-depth-%d-dark-face" - (1+ i)))) - (old-color (face-attribute old-face :foreground frame)) - (new-color (my/greyify-color old-color 50 frame))) + (when-let* ((old-face (intern-soft + (format "rainbow-delimiters-depth-%d-face" + (1+ i)))) + (new-face + (intern + (format "my/rainbow-delimiters-depth-%d-dark-face" + (1+ i)))) + (old-color (face-attribute old-face :foreground frame)) + (new-color (my/greyify-color old-color 50 frame))) (set-face-attribute new-face frame :foreground new-color)))) (add-hook 'after-make-frame-functions #'my/-rainbow-delimiters-recalc-dark-faces)