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