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,7 +40,7 @@ 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))
(if-let* ((bounds (c-comments-bounds-at-point))
((or always-continue (not (nth 7 (syntax-ppss))))))
(progn
(when (c-comments--need-comment-terminator bounds)

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,11 +95,11 @@ 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))
(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))
(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))
@ -178,7 +178,7 @@ 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)
(when-let* ((pos)
(content (ctp--extract-content buffer width height)))
(setq ctp--popon
;; appear behind the auto-complete window, in case something
@ -212,7 +212,7 @@ 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)))
(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)))

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,7 +336,7 @@ Example:
(eshell-starship--limit-path-parts
3 (let ((cwd (or (file-remote-p default-directory 'localname)
default-directory)))
(if-let ((worktree (vc-root-dir))
(if-let* ((worktree (vc-root-dir))
(parent (file-name-parent-directory worktree)))
(file-relative-name cwd (or (file-remote-p parent 'localname)
parent))
@ -507,7 +507,7 @@ 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))
(when-let* ((backend (vc-responsible-backend default-directory t))
((not (eq backend 'Git))))
(downcase (symbol-name backend))))
@ -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,7 +834,7 @@ 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))
(if-let* ((start (if (string-prefix-p "." name) 1 0))
(idx (cl-position ?. name :start start :test '=)))
(substring name (1+ idx))
""))
@ -921,7 +921,7 @@ 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)
(when-let* ((result)
(output
(concat prefix
(eshell-starship--propertize-face
@ -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,7 +349,7 @@ 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))
(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))
@ -397,7 +397,7 @@ 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
(let ((dir (if-let* ((last-idx (cl-position ?/ current-input
:from-end t)))
(substring current-input 0 (1+ last-idx))
current-input)))
@ -471,7 +471,7 @@ 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)
(if-let* ((cache (gethash (cons ,adirname ,dirs)
firejail--relative-to-cache)))
cache
(let (,out)
@ -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,7 +681,7 @@ 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)
(when-let* ((handler (or (gethash (cons directive nil)
firejail-profile--keyword-handlers)
(gethash (cons directive cur-arg)
firejail-profile--keyword-handlers))))
@ -823,7 +823,7 @@ 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))
(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)

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,7 +215,7 @@ 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))
(when-let* (((inf-cc-font-lock-mode inf-cc--obj))
(proc (get-buffer-process (current-buffer)))
(start (process-mark proc))
(end (point-max))
@ -232,7 +232,7 @@ Note that this erases the buffer before doing anything."
(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,7 +328,7 @@ 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)
(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)))

View File

@ -36,7 +36,7 @@ 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))
(if-let* ((uid-list (khard--build-uid-email-phone-list))
(resp (completing-read (or prompt "Contact ") uid-list)))
(assoc resp uid-list)))
@ -110,7 +110,7 @@ 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))
(if-let* ((length (length list-str))
((>= length 2))
(no-braces (substring list-str 1 -1)))
(let ((output 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,7 +337,7 @@ 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
(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
@ -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,7 +658,7 @@ 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: "
(when-let* ((ans (completing-read (format "LaTeX Help%s: "
(if def-name
(format " (default %s)"
def-name)
@ -672,7 +672,7 @@ Prompt the user for an info topic or texdoc file, then open that thing."
(string-match (rx "(Info) " (group (+ (not " ")))
" - " (group (+ any)))
ans)
(when-let ((thing (match-string 2 ans))
(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)))))))

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,7 +74,7 @@ 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"))
(when-let* ((bounds (org-mu4e--bounds-of-mime-part "text/html"))
(real-buf (current-buffer)))
(save-excursion
(let ((content
@ -145,7 +145,7 @@ 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
(if-let* ((export-data (org-export-as
'html nil t nil
org-mime-export-options)))
(progn

62
init.el
View File

@ -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,7 +931,7 @@ 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)
(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))))
@ -1077,7 +1077,7 @@ 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
(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)))
@ -1184,7 +1184,7 @@ visual states."
(let ((help-buf (my/help-buffer-exists-p)))
(prog1
(apply oldfun args)
(when-let (((not help-buf))
(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
@ -1295,7 +1295,7 @@ 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))
(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)
@ -1307,7 +1307,7 @@ 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))
(when-let* (((bound-and-true-p jinx-mode))
(jinx-msg (jinx--get-overlays (point) (1+ (point)))))
(push "misspelled word" message))
(when message
@ -1348,7 +1348,7 @@ With PROJECT, return the candiadeets for that project."
(prog1
(seq-uniq
(append
(when-let (((bound-and-true-p flymake-mode))
(when-let* (((bound-and-true-p flymake-mode))
(diags (if project (flymake--project-diagnostics
project)
(flymake-diagnostics))))
@ -1432,14 +1432,14 @@ 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)))
(if-let* (((not (seq-empty-p info)))
(buff (current-buffer)))
(with-current-buffer my/-eglot-documentation-buffer
(let ((inhibit-read-only t))
@ -1645,7 +1645,7 @@ 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))
(if-let* ((proj (project-current prompt))
(default-directory (project-root proj))
(eshell-buffer-name
(concat "*eshell for project " default-directory "*")))
@ -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,7 +2250,7 @@ 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)))
(when-let* ((proc (get-buffer-process (current-buffer)))
(start (process-mark proc))
(end (point-max))
(input (buffer-substring-no-properties start end))
@ -2266,7 +2266,7 @@ Note that this erases the buffer before doing anything."
(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,11 +2302,11 @@ 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)))
(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"
(if-let* ((table-sym (intern-soft (format "%s-syntax-table"
non-ts))))
(symbol-value table-sym)
syntax-table))
@ -2375,7 +2375,7 @@ Note that this erases the buffer before doing anything."
(jupyter-kernel-language
jupyter-current-client))))))
(buffer-list))))
(when-let (((not res))
(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)))
@ -2384,7 +2384,7 @@ Note that this erases the buffer before doing anything."
(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)))
(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))))
@ -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,7 +2443,7 @@ 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))
(if-let* ((thing (treesit-thing-at-point "_" 'nested))
(code (treesit-node-text thing)))
(progn
(my/jupyter-eval-in-proper-buffer 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,7 +2687,7 @@ 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))
(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))))
@ -2843,7 +2843,7 @@ 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)))
(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)
@ -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
(when-let* ((from-current-hist
(member my/-helpful-last-entry
my/helpful-symbol-history))
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,7 +3487,7 @@ 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
(when-let* ((old-face (intern-soft
(format "rainbow-delimiters-depth-%d-face"
(1+ i))))
(new-face