Skip to content

Commit

Permalink
Migrate the if-let/when-let to the if-let*/when-let*
Browse files Browse the repository at this point in the history
Since the upstream Emacs marked the if-let/when-let as obsoleted, migrate to the
if-let*/when-let* form (Emacs bug#73853).
  • Loading branch information
sunlin7 authored and smile13241324 committed Nov 15, 2024
1 parent ec35306 commit 6f0d95f
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 63 deletions.
2 changes: 1 addition & 1 deletion core/core-compilation.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ When the UPDATE is t, it will force update the state."
(unless paths
(setq paths (list nil nil nil nil))
(push (cons name paths) afiles))
(if-let ((idx (cl-loop for i from 0
(if-let* ((idx (cl-loop for i from 0
for s in slist
until (string-suffix-p s file)
finally return i)))
Expand Down
4 changes: 2 additions & 2 deletions core/core-configuration-layer.el
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ Returns nil if the directory is not a category."
(defun configuration-layer//get-layer-parent-category (layer-name)
"Return a parent category symbol for given LAYER-NAME.
Returns nil if there is no layer named LAYER-NAME."
(when-let ((lp (configuration-layer/get-layer-path layer-name)))
(when-let* ((lp (configuration-layer/get-layer-path layer-name)))
(thread-last lp
directory-file-name
file-name-directory
Expand Down Expand Up @@ -2428,7 +2428,7 @@ depends on it."

(defun configuration-layer//package-delete (pkg-name)
"Delete package with name PKG-NAME."
(if-let ((pkg (car (alist-get pkg-name package-alist))))
(if-let* ((pkg (car (alist-get pkg-name package-alist))))
;; add force flag to ignore dependency checks in Emacs25
(if (configuration-layer//system-package-p pkg)
(message "Would have removed package %s but this is a system package so it has not been changed." pkg-name)
Expand Down
2 changes: 1 addition & 1 deletion core/core-dumper.el
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ When universal prefix argument is passed then display the process buffer."
(message "Cancel running dumping process to start a new one.")
(spinner-stop)
(delete-process spacemacs-dump-process))
(when-let ((buf (get-buffer spacemacs-dump-buffer-name)))
(when-let* ((buf (get-buffer spacemacs-dump-buffer-name)))
(with-current-buffer buf
(erase-buffer)))
(make-directory spacemacs-dump-directory t)
Expand Down
2 changes: 1 addition & 1 deletion core/core-spacebind.el
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ NOTE: You can override key labels and displayed key sequences with :label <TEXT>
(plist-get key))))
(seq-reduce
(lambda (acc pair)
(if-let ((stack (get-stack (car pair)))
(if-let* ((stack (get-stack (car pair)))
(stack-var (cadr pair)))
;; We do it this way because `nconc' should have
;; the shortest list as the first argument.
Expand Down
6 changes: 3 additions & 3 deletions core/core-spacemacs-buffer.el
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ LIST-SIZE is specified in `dotspacemacs-startup-lists' for recent entries."
(unless recentf-mode (recentf-mode))
(let (;; we need to remove `org-agenda-files' entries from recent files
(agenda-files
(when-let ((default-directory
(when-let* ((default-directory
(or (bound-and-true-p org-directory) "~/org"))
(files
(when (bound-and-true-p org-agenda-files)
Expand Down Expand Up @@ -1491,7 +1491,7 @@ version of `widget-button-press' since `widget-button-click' doesn't work."
(when (widget-event-point event)
(let ((pos (widget-event-point event)))
(goto-char pos)
(when-let ((button (get-char-property pos 'button)))
(when-let* ((button (get-char-property pos 'button)))
(widget-apply-action button)))))

(defun spacemacs-buffer/jump-to-number-startup-list-line ()
Expand Down Expand Up @@ -1657,7 +1657,7 @@ This function is intended to be used in `spacemacs-buffer-mode' only."
;; point on a button, press it
(widget-button-press (point))
;; point on an entry, press it
(if-let ((button (save-excursion
(if-let* ((button (save-excursion
(beginning-of-line-text)
(re-search-forward "[0-9]* +. " (point-at-eol) 'noerror))))
(widget-button-press button)
Expand Down
2 changes: 1 addition & 1 deletion core/core-spacemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ the final step of executing code in `emacs-startup-hook'.")
(dolist (dir (or path (list package-user-dir)))
(when (file-directory-p dir)
(dolist (pkg-dir (directory-files dir t "\\`[^.]"))
(when-let (((file-directory-p pkg-dir))
(when-let* (((file-directory-p pkg-dir))
(pkg-desc (package-load-descriptor pkg-dir)))
(let ((default-directory pkg-dir))
(mapc 'delete-file (file-expand-wildcards "*-autoloads.el" )))
Expand Down
12 changes: 6 additions & 6 deletions core/libs/package-build.el
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ Return (COMMIT-HASH COMMITTER-DATE VERSION-STRING REVDESC) or nil.
(list rcommit rtime (package-version-join version) rrevdesc tag)))))

(defun package-build--ensure-count-increase (rcp version ahead)
(if-let ((previous (cdr (assq (intern (oref rcp name))
(if-let* ((previous (cdr (assq (intern (oref rcp name))
(package-build-archive-alist)))))
;; Because upstream may have rewritten history, we cannot be certain
;; that appending the new count of commits would result in a version
Expand Down Expand Up @@ -1282,14 +1282,14 @@ is the same as the value of `export_file_name'."
"Invalid package name in dependency: %S" pkg))
(list pkg ver))
(eval deps)))
(when-let ((v (or (alist-get :url plist)
(when-let* ((v (or (alist-get :url plist)
(alist-get :homepage plist))))
(oset rcp webpage v))
(when-let ((v (alist-get :keywords plist)))
(when-let* ((v (alist-get :keywords plist)))
(oset rcp keywords v))
(when-let ((v (alist-get :maintainers plist)))
(when-let* ((v (alist-get :maintainers plist)))
(oset rcp maintainers v))
(when-let ((v (alist-get :authors plist)))
(when-let* ((v (alist-get :authors plist)))
(oset rcp authors v)))))))

(defun package-build--normalize-summary (summary)
Expand Down Expand Up @@ -1554,7 +1554,7 @@ in `package-build-archive-dir'."
(package-build--message "Running %s" command)
(package-build--call-sandboxed
rcp shell-file-name shell-command-switch command))
(when-let ((package-build-run-recipe-make-targets)
(when-let* ((package-build-run-recipe-make-targets)
(targets (oref rcp make-targets)))
(package-build--message "Running make %s" (string-join targets " "))
(apply #'package-build--call-sandboxed rcp "make" targets))
Expand Down
8 changes: 4 additions & 4 deletions core/libs/package-recipe.el
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ a message for each invalid recipe."
(cl-assert (not (plist-get plist :url)) ":url is redundant"))
(cl-assert (plist-get plist :url) ":url is missing")))
(dolist (key symbol-keys)
(when-let ((val (plist-get plist key)))
(when-let* ((val (plist-get plist key)))
(cl-assert (symbolp val) nil "%s must be a symbol but is %S" key val)))
(dolist (key list-keys)
(when-let ((val (plist-get plist key)))
(when-let* ((val (plist-get plist key)))
(cl-assert (listp val) nil "%s must be a list but is %S" key val)))
(dolist (key string-keys)
(when-let ((val (plist-get plist key)))
(when-let* ((val (plist-get plist key)))
(cl-assert (stringp val) nil "%s must be a string but is %S" key val)))
(when-let ((spec (plist-get plist :files)))
(when-let* ((spec (plist-get plist :files)))
;; `:defaults' is only allowed as the first element.
;; If we find it in that position, skip over it.
(when (eq (car spec) :defaults)
Expand Down
18 changes: 9 additions & 9 deletions core/libs/quelpa.el
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ On error return nil."
OP is taking two version list and comparing."
(let ((ver (if version (version-to-list version) quelpa--min-ver))
(pkg-ver
(or (when-let ((pkg-desc (cdr (assq name package-alist)))
(or (when-let* ((pkg-desc (cdr (assq name package-alist)))
(pkg-ver (package-desc-version (car pkg-desc))))
pkg-ver)
(alist-get name package--builtin-versions)
Expand Down Expand Up @@ -294,7 +294,7 @@ already and should not be upgraded etc)."
((or (not (equal ver-type 'elpa)) quelpa-stable-p) melpa-ver)
(melpa-ver
(let ((base-ver
(if-let ((info (quelpa-build--pkg-info (symbol-name name)
(if-let* ((info (quelpa-build--pkg-info (symbol-name name)
files build-dir)))
(aref info 3)
'(0 0 0))))
Expand Down Expand Up @@ -326,7 +326,7 @@ already and should not be upgraded etc)."
(or (funcall package-strip-rcs-id-orig (lm-header "package-version"))
(funcall package-strip-rcs-id-orig (lm-header "version"))
"0"))))
(concat (if-let ((desc (quelpa-get-package-desc file-path)))
(concat (if-let* ((desc (quelpa-get-package-desc file-path)))
(mapconcat #'number-to-string (package-desc-version desc) ".")
"0")
(pcase version
Expand Down Expand Up @@ -932,7 +932,7 @@ Return a cons cell whose `car' is the root and whose `cdr' is the repository."
(repo (plist-get config :url))
(remote (or (plist-get config :remote) "origin"))
(commit (or (plist-get config :commit)
(when-let ((branch (plist-get config :branch)))
(when-let* ((branch (plist-get config :branch)))
(concat remote "/" branch))))
(depth (or (plist-get config :depth) quelpa-git-clone-depth))
(partial (and (or (plist-get config :partial) quelpa-git-clone-partial)
Expand Down Expand Up @@ -964,7 +964,7 @@ Return a cons cell whose `car' is the root and whose `cdr' is the repository."
(when (and depth (not (plist-get config :commit)))
`("--depth" ,(int-to-string depth)
"--no-single-branch"))
(when-let ((branch (plist-get config :branch)))
(when-let* ((branch (plist-get config :branch)))
`("--branch" ,branch))))))
(if quelpa-build-stable
(let* ((min-bound (goto-char (point-max)))
Expand Down Expand Up @@ -1324,7 +1324,7 @@ If KEEP-VERSION is set, don't override with version 0."
(extras (let (alist)
(while rest-plist
(unless (memq (car rest-plist) '(:kind :archive))
(when-let ((value (cadr rest-plist)))
(when-let* ((value (cadr rest-plist)))
(push (cons (car rest-plist)
(if (eq (car-safe value) 'quote)
(cadr value)
Expand Down Expand Up @@ -1900,7 +1900,7 @@ Return new package version."
"Delete obsoleted packages with name NAME.
With NEW-VERSION, will delete obsoleted packages that are not in same
version."
(when-let ((all-pkgs (alist-get name package-alist))
(when-let* ((all-pkgs (alist-get name package-alist))
(new-pkg-version (or new-version
(package-desc-version (car all-pkgs)))))
(with-demoted-errors "Error deleting package: %S"
Expand All @@ -1911,7 +1911,7 @@ version."
(package-delete pkg-desc 'force))))
all-pkgs))
;; Only packages with same version remained. Just pick the first one.
(when-let (all-pkgs (alist-get name package-alist))
(when-let* (all-pkgs (alist-get name package-alist))
(setf (cdr all-pkgs) nil))))

;; --- public interface ------------------------------------------------------
Expand Down Expand Up @@ -2003,7 +2003,7 @@ given package and remove any old versions of it even if the
(cache-item (quelpa-arg-rcp arg)))
(quelpa-parse-plist plist)
(quelpa-parse-stable cache-item)
(when-let ((ver (apply #'quelpa-package-install arg plist)))
(when-let* ((ver (apply #'quelpa-package-install arg plist)))
(when quelpa-autoremove-p
(quelpa--delete-obsoleted-package (car cache-item) ver))
(quelpa-update-cache cache-item))))
Expand Down
2 changes: 1 addition & 1 deletion layers/+checkers/syntax-checking/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Toggle flycheck's error list window.
If the error list is visible, hide it. Otherwise, show it."
(interactive)
(if-let ((window (flycheck-get-error-list-window)))
(if-let* ((window (flycheck-get-error-list-window)))
(save-selected-window (quit-window nil window))
(flycheck-list-errors)))

Expand Down
4 changes: 2 additions & 2 deletions layers/+completion/compleseus/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ and with narrowing key \"B\".")
:enabled ,(lambda () consult-project-function)
:items
,(lambda ()
(when-let (root (consult--project-root))
(when-let* ((root (consult--project-root)))
(consult--buffer-query
:sort 'visibility
:directory root
Expand All @@ -160,7 +160,7 @@ and with narrowing key \"B\".")
:enabled ,(lambda () consult-project-function)
:items
,(lambda ()
(when-let (root (consult--project-root))
(when-let* ((root (consult--project-root)))
(consult--buffer-query
:sort 'visibility
:directory root
Expand Down
2 changes: 1 addition & 1 deletion layers/+completion/compleseus/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
;; Optionally configure a function which returns the project root directory.
(setq consult-project-root-function
(lambda ()
(when-let (project (project-current))
(when-let* ((project (project-current)))
(car (project-root project)))))

(dolist (command '(consult-org-agenda
Expand Down
2 changes: 1 addition & 1 deletion layers/+emacs/org/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Will work on both org-mode and any mode that accepts plain html."
"aof" "feeds"
"aoC" (org-clocks-prefix))
;; org-agenda
(unless (when-let ((pkg (configuration-layer/get-package 'helm-org-rifle)))
(unless (when-let* ((pkg (configuration-layer/get-package 'helm-org-rifle)))
;; TODO: `configuration-layer/package-used-p' doesn't check
;; :toggle status. When it is fixed, we can use it again.
(cfgl-package-used-p pkg))
Expand Down
4 changes: 2 additions & 2 deletions layers/+lang/python/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ ROOT-DIR should be the path for the environemnt, `nil' for clean up"
(if-let* ((root-dir)
(default-directory root-dir))
(dolist (x '("pylint" "flake8"))
(when-let ((exe (spacemacs/pyenv-executable-find x)))
(when-let* ((exe (spacemacs/pyenv-executable-find x)))
(flycheck-set-checker-executable (concat "python-" x) exe)))
;; else root-dir is nil
(dolist (x '("pylint" "flake8"))
Expand Down Expand Up @@ -530,7 +530,7 @@ If region is not active then send line."
(defun spacemacs/python-start-or-switch-repl ()
"Start and/or switch to the REPL."
(interactive)
(if-let ((shell-process (or (python-shell-get-process)
(if-let* ((shell-process (or (python-shell-get-process)
(call-interactively #'run-python))))
(progn
(pop-to-buffer (process-buffer shell-process))
Expand Down
26 changes: 13 additions & 13 deletions layers/+spacemacs/spacemacs-defaults/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ by `magit' and `dired'.
Returns:
- A string containing the directory path in case of success.
- `nil' in case the current buffer does not have a directory."
(when-let (directory-name (if-let (file-name (buffer-file-name))
(file-name-directory file-name)
list-buffers-directory))
(when-let* ((directory-name (if-let* ((file-name (buffer-file-name)))
(file-name-directory file-name)
list-buffers-directory)))
(file-truename directory-name)))

(defun spacemacs--file-path ()
Expand All @@ -815,7 +815,7 @@ Returns:
Returns:
- A string containing the file path in case of success.
- `nil' in case the current buffer does not have a directory."
(when-let (file-path (buffer-file-name))
(when-let* ((file-path (buffer-file-name)))
(file-truename file-path)))

(defun spacemacs--file-path-with-line ()
Expand All @@ -824,7 +824,7 @@ Returns:
Returns:
- A string containing the file path in case of success.
- `nil' in case the current buffer does not have a directory."
(when-let (file-path (spacemacs--file-path))
(when-let* ((file-path (spacemacs--file-path)))
(concat file-path ":" (number-to-string (line-number-at-pos)))))

(defun spacemacs--file-path-with-line-column ()
Expand All @@ -836,7 +836,7 @@ This function respects the `column-number-indicator-zero-based' variable.
Returns:
- A string containing the file path in case of success.
- `nil' in case the current buffer does not have a directory."
(when-let (file-path (spacemacs--file-path-with-line))
(when-let* ((file-path (spacemacs--file-path-with-line)))
(format "%s:%s" file-path
(+ (current-column) (if column-number-indicator-zero-based 0 1)))))

Expand All @@ -847,7 +847,7 @@ If the buffer is not visiting a file, use the `list-buffers-directory'
variable as a fallback to display the directory, useful in buffers like the
ones created by `magit' and `dired'."
(interactive)
(if-let (directory-path (spacemacs--directory-path))
(if-let* ((directory-path (spacemacs--directory-path)))
(progn
(kill-new directory-path)
(message "%s" directory-path))
Expand All @@ -856,7 +856,7 @@ ones created by `magit' and `dired'."
(defun spacemacs/copy-file-path ()
"Copy and show the file path of the current buffer."
(interactive)
(if-let (file-path (spacemacs--file-path))
(if-let* ((file-path (spacemacs--file-path)))
(progn
(kill-new file-path)
(message "%s" file-path))
Expand All @@ -882,7 +882,7 @@ ones created by `magit' and `dired'."
"Copy and show the file name without its final extension of the current
buffer."
(interactive)
(if-let (file-name (file-name-base (spacemacs--file-path)))
(if-let* ((file-name (file-name-base (spacemacs--file-path))))
(progn
(kill-new file-name)
(message "%s" file-name))
Expand All @@ -891,7 +891,7 @@ buffer."
(defun spacemacs/copy-file-path-with-line ()
"Copy and show the file path of the current buffer, including line number."
(interactive)
(if-let (file-path (spacemacs--file-path-with-line))
(if-let* ((file-path (spacemacs--file-path-with-line)))
(progn
(kill-new file-path)
(message "%s" file-path))
Expand All @@ -904,7 +904,7 @@ including line and column number.
This function respects the value of the `column-number-indicator-zero-based'
variable."
(interactive)
(if-let (file-path (spacemacs--file-path-with-line-column))
(if-let* ((file-path (spacemacs--file-path-with-line-column)))
(progn
(kill-new file-path)
(message "%s" file-path))
Expand Down Expand Up @@ -1783,7 +1783,7 @@ if prefix argument ARG is given, switch to it in an other, possibly new window."
(defun spacemacs/show-hide-compilation-window ()
"Show/Hide the window containing the compilation buffer."
(interactive)
(when-let ((buffer next-error-last-buffer))
(when-let* ((buffer next-error-last-buffer))
(if (get-buffer-window buffer 'visible)
(delete-windows-on buffer)
(spacemacs/switch-to-compilation-buffer))))
Expand Down Expand Up @@ -1835,7 +1835,7 @@ line numbers, with respect to `dotspacemacs-line-numbers'."
This is controlled by the `:size-limit-kb' property of
`dotspacemacs-line-numbers'."
(if-let ((size-limit-kb
(if-let* ((size-limit-kb
(and (listp dotspacemacs-line-numbers)
(spacemacs/mplist-get-value dotspacemacs-line-numbers
:size-limit-kb))))
Expand Down
2 changes: 1 addition & 1 deletion layers/+spacemacs/spacemacs-layouts/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ If perspective NAME does not already exist, create it and add any
buffers that belong to the current buffer's project."
(if (persp-with-name-exists-p name)
(message "There is already a perspective named %s" name)
(if-let ((project (projectile-project-p)))
(if-let* ((project (projectile-project-p)))
(spacemacs||switch-layout name
:init
(persp-add-buffer (projectile-project-buffers project)
Expand Down
Loading

0 comments on commit 6f0d95f

Please sign in to comment.