Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated if-let and when-let #3

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix3-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ This command discard the exit code or output of the command."

(defun nix3-config-lookup (key)
"Look up the configuration of Nix."
(if-let (h (map-elt (nix3--config-memoized) key))
(if-let* ((h (map-elt (nix3--config-memoized) key)))
(map-elt h "value")
(error "Key %s is not found in the nix conf" key)))

Expand Down
6 changes: 3 additions & 3 deletions nix3-flake-input.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

(defun nix3-flake-input-at-point ()
"Return a cons cell of (NAME . DATA) of the input."
(when-let (section (magit-current-section))
(when-let* ((section (magit-current-section)))
(when (eq (slot-value section 'type) 'flake-input)
(oref section value))))

Expand Down Expand Up @@ -178,15 +178,15 @@
(defun nix3-flake-input-update-to-rev (rev)
(interactive "sRevision: ")
(let ((alist (alist-get 'original (cdr nix3-flake-input))))
(if-let (cell (assq 'rev alist))
(if-let* ((cell (assq 'rev alist)))
(setcdr cell rev)
(setq alist (cons (cons 'rev rev) alist)))
(nix3-flake-input-update alist)))

(defun nix3-flake-input-update-to-ref (ref)
(interactive "sRef: ")
(let ((alist (alist-get 'original (cdr nix3-flake-input))))
(if-let (cell (assq 'ref alist))
(if-let* ((cell (assq 'ref alist)))
(setcdr cell ref)
(setq alist (cons (cons 'ref ref) alist)))
(nix3-flake-input-update alist)))
Expand Down
4 changes: 2 additions & 2 deletions nix3-flake-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@

;;;###autoload
(defun nix3-flake-lock-diff-section ()
(when-let (files (nix3-flake-lock-magit-sections))
(when-let* ((files (nix3-flake-lock-magit-sections)))
(cl-flet*
((format-mtime (locked)
(format-time-string "%Y-%m-%d" (alist-get 'lastModified locked)))
Expand Down Expand Up @@ -194,7 +194,7 @@
(defun nix3-flake-lock-source-at-point ()
"Display the source at point."
(interactive)
(when-let (section (magit-current-section))
(when-let* ((section (magit-current-section)))
(pcase (oref section value)
(`(,_id ,old ,new)
(cond
Expand Down
48 changes: 24 additions & 24 deletions nix3-flake.el
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ If DIR is non-nil, the function returns a flake at or above the
directory. It implies LOCAL."
(or (unless (or local dir)
nix3-flake-url)
(if-let (root (locate-dominating-file (or dir default-directory) "flake.nix"))
(if-let* ((root (locate-dominating-file (or dir default-directory) "flake.nix")))
(nix3-normalize-path root)
(unless allow-missing
(error "No flake.nix is found")))))
Expand Down Expand Up @@ -324,12 +324,12 @@ directory. It implies LOCAL."
(pcase \.type
("indirect"
(require 'nix3-registry)
(if-let (entry (thread-last
(if-let* ((entry (thread-last
(nix3-registry--collect-entries)
(cl-remove-if (lambda (x)
(equal (cdr (assq 'type (cddr x)))
"path")))
(assoc \.id)))
(assoc \.id))))
(to-url (cddr entry))
(error "Failed to find a registry entry for %s" \.id)))
("github"
Expand Down Expand Up @@ -445,7 +445,7 @@ directory. It implies LOCAL."
type)
result))
("unknown"
(when-let (match (seq-find (apply-partially #'prefixp path) extra-derivations))
(when-let* ((match (seq-find (apply-partially #'prefixp path) extra-derivations)))
(let ((rest (seq-drop match (length path))))
(go2 path rest))))))
(go2 (path rest)
Expand Down Expand Up @@ -510,7 +510,7 @@ directory. It implies LOCAL."

(defun nix3-flake-insert-metadata ()
(magit-insert-section (flake-metadata nil)
(when-let (metadata (nix3-flake--get-metadata-result))
(when-let* ((metadata (nix3-flake--get-metadata-result)))
(let-alist metadata
(nix3-section-dlist 0
nil
Expand Down Expand Up @@ -539,14 +539,14 @@ directory. It implies LOCAL."

(defun nix3-flake-output-return ()
(interactive)
(when-let (output (nix3-flake-output-path-at-point))
(when-let* ((output (nix3-flake-output-path-at-point)))
(setq nix3-transient-flake (nix3-flake--buffer-url))
(setq nix3-transient-flake-output output)
(setq nix3-transient-flake-output-type (nix3-flake-output-type))
(nix3-transient-on-output)))

(defun nix3-flake-output-path-at-point ()
(when-let (section (magit-current-section))
(when-let* ((section (magit-current-section)))
(when (eq (oref section type) 'flake-output)
(oref section value))))

Expand All @@ -558,7 +558,7 @@ directory. It implies LOCAL."
(while (setq section (magit-current-section))
(when (eq (oref section type) 'flake-output-type)
(throw 'output-type (oref section value)))
(if-let (parent (oref section parent))
(if-let* ((parent (oref section parent)))
(let ((pos (point)))
(magit-section-goto parent)
;; If there is no heading for the parent branch, the position
Expand Down Expand Up @@ -618,7 +618,7 @@ directory. It implies LOCAL."

(defun nix3-flake-insert-header (url)
(insert (propertize "Flake: " 'face 'magit-section-heading))
(if-let (metadata (nix3-flake-metadata--get url))
(if-let* ((metadata (nix3-flake-metadata--get url)))
(if (member (nix3-lookup-tree '(original type) metadata)
'("indirect" "path" "git"))
(insert (cdr (assq 'originalUrl metadata)))
Expand All @@ -632,7 +632,7 @@ directory. It implies LOCAL."
(let (result)
(cl-labels
((go (rev-path node)
(if-let (type (cdr (assq 'type node)))
(if-let* ((type (cdr (assq 'type node))))
(push (cons type rev-path) result)
(pcase-dolist (`(,name . ,child) node)
(go (cons name rev-path) child)))))
Expand All @@ -645,7 +645,7 @@ directory. It implies LOCAL."
(seq-sort-by #'car #'string<))))

(defun nix3-flake--direct-inputs ()
(if-let (result (nix3-flake--get-metadata-result))
(if-let* ((result (nix3-flake--get-metadata-result)))
(let* ((nodes (nix3-lookup-tree '(locks nodes) result))
(names (mapcar #'car (nix3-lookup-tree '(root inputs) nodes))))
(mapcar (lambda (name)
Expand All @@ -656,7 +656,7 @@ directory. It implies LOCAL."

(defun nix3-flake-insert-inputs ()
(require 'nix3-flake-input)
(when-let (result (nix3-flake--get-metadata-result))
(when-let* ((result (nix3-flake--get-metadata-result)))
(nix3-section-with-keymap nix3-flake-input-map
(magit-insert-section (flake-inputs nil (nix3-flake--fold-toplevel-p))
(magit-insert-heading "Flake inputs")
Expand Down Expand Up @@ -783,7 +783,7 @@ directory. It implies LOCAL."
(read-only-mode 1))

(defun nix3-flake-show-eldoc (callback)
(when-let (help (get-char-property (point) 'help-echo))
(when-let* ((help (get-char-property (point) 'help-echo)))
(when (stringp help)
(funcall callback help))))

Expand Down Expand Up @@ -921,7 +921,7 @@ directory. It implies LOCAL."
"Go to the flake buffer."
(interactive)
(when (eq major-mode 'nix3-flake-show-mode)
(when-let (buffer (pop nix3-flake-show-history))
(when-let* ((buffer (pop nix3-flake-show-history)))
(switch-to-buffer buffer))))

;;;; Bookmark integration
Expand All @@ -937,9 +937,9 @@ directory. It implies LOCAL."

;;;###autoload
(defun nix3-flake-show-bookmark-handler (bookmark)
(if-let (url (bookmark-prop-get bookmark 'url))
(if-let* ((url (bookmark-prop-get bookmark 'url)))
(nix3-flake-show-url url)
(if-let (dir (bookmark-prop-get bookmark 'default-directory))
(if-let* ((dir (bookmark-prop-get bookmark 'default-directory)))
(if (file-directory-p dir)
(nix3-flake-show dir)
(user-error "Trying to open a bookmark on a non-existent directory: %s" bookmark))
Expand Down Expand Up @@ -1005,11 +1005,11 @@ If NO-CONFIRM is non-nil, "
(then `(lambda (_)
(let (message-log-max)
(message nil))
(if-let (templates (thread-last
(nix3-flake-show--get ,url)
;; Since Nix 2.7, the default template is templates.default, so we
;; won't consider defaultTemplate.
(alist-get 'templates)))
(if-let* ((templates (thread-last
(nix3-flake-show--get ,url)
;; Since Nix 2.7, the default template is templates.default, so we
;; won't consider defaultTemplate.
(alist-get 'templates))))
(concat ,name-or-url
"#" (nix3-flake--complete-template ,prompt templates))
(error "No template"))))
Expand Down Expand Up @@ -1065,7 +1065,7 @@ If NO-CONFIRM is non-nil, "
templates)))
(cl-labels
((annotator (candidate)
(if-let (description (cdr (assoc candidate template-alist)))
(if-let* ((description (cdr (assoc candidate template-alist))))
(concat " " description)
""))
(group (candidate transform)
Expand Down Expand Up @@ -1098,7 +1098,7 @@ then runs `nix3-flake-init'."
(interactive)
(when nix3-flake-url
(user-error "You must run this command inside a local flake"))
(if-let (dir (locate-dominating-file default-directory "flake.nix"))
(if-let* ((dir (locate-dominating-file default-directory "flake.nix")))
(funcall nix3-flake-edit-find-file-fn (expand-file-name "flake.nix" dir))
(let ((default-directory (or (vc-git-root default-directory)
(progn
Expand All @@ -1122,7 +1122,7 @@ then runs `nix3-flake-init'."

(defun nix3-flake-remember-this-project ()
"Remember the current project."
(when-let (pr (project-current))
(when-let* ((pr (project-current)))
(project-remember-project pr)))

;;;; Manage relationships between remote repositories and local copies
Expand Down
4 changes: 2 additions & 2 deletions nix3-help.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
last-end start))))
(when (string-match capture string)
(push (cons (match-string 1 string)
(when-let (desc (match-string 2 string))
(when-let* ((desc (match-string 2 string)))
(replace-regexp-in-string
(rx (+ space)) " "
desc)))
Expand All @@ -92,7 +92,7 @@
(let (alist)
(cl-labels
((add-commands (subcommands &optional description)
(if-let (subalist (apply #'nix3-help-parse 'commands subcommands))
(if-let* ((subalist (apply #'nix3-help-parse 'commands subcommands)))
(dolist (x subalist)
(add-commands (append subcommands (list (car x)))
(cdr x)))
Expand Down
6 changes: 3 additions & 3 deletions nix3-registry.el
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ registry type and the \"to\" value of the entry."
(group (id transform)
(if transform
id
(if-let (cell (gethash id table))
(if-let* ((cell (gethash id table)))
(format "%s registry"
(capitalize (symbol-name (car cell))))
"")))
Expand All @@ -187,7 +187,7 @@ registry type and the \"to\" value of the entry."
(cons 'annotation-function #'annotator)))
(complete-with-action action items string pred))))
(let ((input (completing-read prompt #'completions)))
(if-let (entry (gethash input table))
(if-let* ((entry (gethash input table)))
(cons input (cdr entry))
(when (and add-to-registry
(nix3-registry--flake-url-p input)
Expand Down Expand Up @@ -243,7 +243,7 @@ registry type and the \"to\" value of the entry."
name flake))

(defun nix3-registry--maybe-origin-flake-url ()
(when-let (git-url (cdr (assoc "origin" (nix3-git-remotes))))
(when-let* ((git-url (cdr (assoc "origin" (nix3-git-remotes)))))
(nix3-flake-ref-alist-to-url
(nix3-git-url-to-flake-alist git-url))))

Expand Down
10 changes: 5 additions & 5 deletions nix3-transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ This is a function that takes a command line as an argument."
(required :initarg :required :initform t)))

(cl-defmethod transient-init-value ((obj nix3-transient-output-variable))
(if-let (value (eval (oref obj variable)))
(if-let* ((value (eval (oref obj variable))))
(oset obj value value)
(when (oref obj required)
(let ((value (transient-infix-read obj)))
Expand Down Expand Up @@ -442,7 +442,7 @@ will be refreshed."
(format "*nix eval<%s>*" path)))
(message "%s: %s" path string)))
(go (path)
(if-let (names (get-attr-names path))
(if-let* ((names (get-attr-names path)))
(let ((new-path (completing-read (format "Attribute (%s): " path)
;; Build candidates that are full
;; attribute paths. This will make
Expand Down Expand Up @@ -509,7 +509,7 @@ will be refreshed."
","))
(propertize ")" 'face 'transient-inactive-value))))
(interactive)
(if-let (licenses (nix3-transient--package-license))
(if-let* ((licenses (nix3-transient--package-license)))
(nix3-transient--browse-license-url
(if (assq 'fullName licenses)
licenses
Expand All @@ -521,7 +521,7 @@ will be refreshed."
(user-error "No license")))

(defun nix3-transient--browse-license-url (license)
(if-let (url (alist-get 'url license))
(if-let* ((url (alist-get 'url license)))
(browse-url url)
(user-error "License %s has no URL"
(or (alist-get 'spdxId license)
Expand All @@ -534,7 +534,7 @@ will be refreshed."
licenses)))
(cl-labels
((annotator (candidate)
(when-let (license (cdr (assoc candidate alist)))
(when-let* ((license (cdr (assoc candidate alist))))
(format " (%s)"
(mapconcat (lambda (x)
(symbol-name (car x)))
Expand Down