Change to when-let* and if-let*
This commit is contained in:
164
init.el
164
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)
|
||||
|
||||
Reference in New Issue
Block a user