Skip to content

Commit 75c95d4

Browse files
authored
Merge pull request #3 from emacs-twist/if-let
Replace deprecated if-let and when-let
2 parents 6935775 + 6e60bcb commit 75c95d4

File tree

7 files changed

+40
-40
lines changed

7 files changed

+40
-40
lines changed

nix3-core.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ This command discard the exit code or output of the command."
160160

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

nix3-flake-input.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129

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

@@ -178,15 +178,15 @@
178178
(defun nix3-flake-input-update-to-rev (rev)
179179
(interactive "sRevision: ")
180180
(let ((alist (alist-get 'original (cdr nix3-flake-input))))
181-
(if-let (cell (assq 'rev alist))
181+
(if-let* ((cell (assq 'rev alist)))
182182
(setcdr cell rev)
183183
(setq alist (cons (cons 'rev rev) alist)))
184184
(nix3-flake-input-update alist)))
185185

186186
(defun nix3-flake-input-update-to-ref (ref)
187187
(interactive "sRef: ")
188188
(let ((alist (alist-get 'original (cdr nix3-flake-input))))
189-
(if-let (cell (assq 'ref alist))
189+
(if-let* ((cell (assq 'ref alist)))
190190
(setcdr cell ref)
191191
(setq alist (cons (cons 'ref ref) alist)))
192192
(nix3-flake-input-update alist)))

nix3-flake-lock.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146

147147
;;;###autoload
148148
(defun nix3-flake-lock-diff-section ()
149-
(when-let (files (nix3-flake-lock-magit-sections))
149+
(when-let* ((files (nix3-flake-lock-magit-sections)))
150150
(cl-flet*
151151
((format-mtime (locked)
152152
(format-time-string "%Y-%m-%d" (alist-get 'lastModified locked)))
@@ -194,7 +194,7 @@
194194
(defun nix3-flake-lock-source-at-point ()
195195
"Display the source at point."
196196
(interactive)
197-
(when-let (section (magit-current-section))
197+
(when-let* ((section (magit-current-section)))
198198
(pcase (oref section value)
199199
(`(,_id ,old ,new)
200200
(cond

nix3-flake.el

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ If DIR is non-nil, the function returns a flake at or above the
281281
directory. It implies LOCAL."
282282
(or (unless (or local dir)
283283
nix3-flake-url)
284-
(if-let (root (locate-dominating-file (or dir default-directory) "flake.nix"))
284+
(if-let* ((root (locate-dominating-file (or dir default-directory) "flake.nix")))
285285
(nix3-normalize-path root)
286286
(unless allow-missing
287287
(error "No flake.nix is found")))))
@@ -324,12 +324,12 @@ directory. It implies LOCAL."
324324
(pcase \.type
325325
("indirect"
326326
(require 'nix3-registry)
327-
(if-let (entry (thread-last
327+
(if-let* ((entry (thread-last
328328
(nix3-registry--collect-entries)
329329
(cl-remove-if (lambda (x)
330330
(equal (cdr (assq 'type (cddr x)))
331331
"path")))
332-
(assoc \.id)))
332+
(assoc \.id))))
333333
(to-url (cddr entry))
334334
(error "Failed to find a registry entry for %s" \.id)))
335335
("github"
@@ -445,7 +445,7 @@ directory. It implies LOCAL."
445445
type)
446446
result))
447447
("unknown"
448-
(when-let (match (seq-find (apply-partially #'prefixp path) extra-derivations))
448+
(when-let* ((match (seq-find (apply-partially #'prefixp path) extra-derivations)))
449449
(let ((rest (seq-drop match (length path))))
450450
(go2 path rest))))))
451451
(go2 (path rest)
@@ -510,7 +510,7 @@ directory. It implies LOCAL."
510510

511511
(defun nix3-flake-insert-metadata ()
512512
(magit-insert-section (flake-metadata nil)
513-
(when-let (metadata (nix3-flake--get-metadata-result))
513+
(when-let* ((metadata (nix3-flake--get-metadata-result)))
514514
(let-alist metadata
515515
(nix3-section-dlist 0
516516
nil
@@ -539,14 +539,14 @@ directory. It implies LOCAL."
539539

540540
(defun nix3-flake-output-return ()
541541
(interactive)
542-
(when-let (output (nix3-flake-output-path-at-point))
542+
(when-let* ((output (nix3-flake-output-path-at-point)))
543543
(setq nix3-transient-flake (nix3-flake--buffer-url))
544544
(setq nix3-transient-flake-output output)
545545
(setq nix3-transient-flake-output-type (nix3-flake-output-type))
546546
(nix3-transient-on-output)))
547547

548548
(defun nix3-flake-output-path-at-point ()
549-
(when-let (section (magit-current-section))
549+
(when-let* ((section (magit-current-section)))
550550
(when (eq (oref section type) 'flake-output)
551551
(oref section value))))
552552

@@ -558,7 +558,7 @@ directory. It implies LOCAL."
558558
(while (setq section (magit-current-section))
559559
(when (eq (oref section type) 'flake-output-type)
560560
(throw 'output-type (oref section value)))
561-
(if-let (parent (oref section parent))
561+
(if-let* ((parent (oref section parent)))
562562
(let ((pos (point)))
563563
(magit-section-goto parent)
564564
;; If there is no heading for the parent branch, the position
@@ -618,7 +618,7 @@ directory. It implies LOCAL."
618618

619619
(defun nix3-flake-insert-header (url)
620620
(insert (propertize "Flake: " 'face 'magit-section-heading))
621-
(if-let (metadata (nix3-flake-metadata--get url))
621+
(if-let* ((metadata (nix3-flake-metadata--get url)))
622622
(if (member (nix3-lookup-tree '(original type) metadata)
623623
'("indirect" "path" "git"))
624624
(insert (cdr (assq 'originalUrl metadata)))
@@ -632,7 +632,7 @@ directory. It implies LOCAL."
632632
(let (result)
633633
(cl-labels
634634
((go (rev-path node)
635-
(if-let (type (cdr (assq 'type node)))
635+
(if-let* ((type (cdr (assq 'type node))))
636636
(push (cons type rev-path) result)
637637
(pcase-dolist (`(,name . ,child) node)
638638
(go (cons name rev-path) child)))))
@@ -645,7 +645,7 @@ directory. It implies LOCAL."
645645
(seq-sort-by #'car #'string<))))
646646

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

657657
(defun nix3-flake-insert-inputs ()
658658
(require 'nix3-flake-input)
659-
(when-let (result (nix3-flake--get-metadata-result))
659+
(when-let* ((result (nix3-flake--get-metadata-result)))
660660
(nix3-section-with-keymap nix3-flake-input-map
661661
(magit-insert-section (flake-inputs nil (nix3-flake--fold-toplevel-p))
662662
(magit-insert-heading "Flake inputs")
@@ -783,7 +783,7 @@ directory. It implies LOCAL."
783783
(read-only-mode 1))
784784

785785
(defun nix3-flake-show-eldoc (callback)
786-
(when-let (help (get-char-property (point) 'help-echo))
786+
(when-let* ((help (get-char-property (point) 'help-echo)))
787787
(when (stringp help)
788788
(funcall callback help))))
789789

@@ -921,7 +921,7 @@ directory. It implies LOCAL."
921921
"Go to the flake buffer."
922922
(interactive)
923923
(when (eq major-mode 'nix3-flake-show-mode)
924-
(when-let (buffer (pop nix3-flake-show-history))
924+
(when-let* ((buffer (pop nix3-flake-show-history)))
925925
(switch-to-buffer buffer))))
926926

927927
;;;; Bookmark integration
@@ -937,9 +937,9 @@ directory. It implies LOCAL."
937937

938938
;;;###autoload
939939
(defun nix3-flake-show-bookmark-handler (bookmark)
940-
(if-let (url (bookmark-prop-get bookmark 'url))
940+
(if-let* ((url (bookmark-prop-get bookmark 'url)))
941941
(nix3-flake-show-url url)
942-
(if-let (dir (bookmark-prop-get bookmark 'default-directory))
942+
(if-let* ((dir (bookmark-prop-get bookmark 'default-directory)))
943943
(if (file-directory-p dir)
944944
(nix3-flake-show dir)
945945
(user-error "Trying to open a bookmark on a non-existent directory: %s" bookmark))
@@ -1005,11 +1005,11 @@ If NO-CONFIRM is non-nil, "
10051005
(then `(lambda (_)
10061006
(let (message-log-max)
10071007
(message nil))
1008-
(if-let (templates (thread-last
1009-
(nix3-flake-show--get ,url)
1010-
;; Since Nix 2.7, the default template is templates.default, so we
1011-
;; won't consider defaultTemplate.
1012-
(alist-get 'templates)))
1008+
(if-let* ((templates (thread-last
1009+
(nix3-flake-show--get ,url)
1010+
;; Since Nix 2.7, the default template is templates.default, so we
1011+
;; won't consider defaultTemplate.
1012+
(alist-get 'templates))))
10131013
(concat ,name-or-url
10141014
"#" (nix3-flake--complete-template ,prompt templates))
10151015
(error "No template"))))
@@ -1065,7 +1065,7 @@ If NO-CONFIRM is non-nil, "
10651065
templates)))
10661066
(cl-labels
10671067
((annotator (candidate)
1068-
(if-let (description (cdr (assoc candidate template-alist)))
1068+
(if-let* ((description (cdr (assoc candidate template-alist))))
10691069
(concat " " description)
10701070
""))
10711071
(group (candidate transform)
@@ -1098,7 +1098,7 @@ then runs `nix3-flake-init'."
10981098
(interactive)
10991099
(when nix3-flake-url
11001100
(user-error "You must run this command inside a local flake"))
1101-
(if-let (dir (locate-dominating-file default-directory "flake.nix"))
1101+
(if-let* ((dir (locate-dominating-file default-directory "flake.nix")))
11021102
(funcall nix3-flake-edit-find-file-fn (expand-file-name "flake.nix" dir))
11031103
(let ((default-directory (or (vc-git-root default-directory)
11041104
(progn
@@ -1122,7 +1122,7 @@ then runs `nix3-flake-init'."
11221122

11231123
(defun nix3-flake-remember-this-project ()
11241124
"Remember the current project."
1125-
(when-let (pr (project-current))
1125+
(when-let* ((pr (project-current)))
11261126
(project-remember-project pr)))
11271127

11281128
;;;; Manage relationships between remote repositories and local copies

nix3-help.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
last-end start))))
8181
(when (string-match capture string)
8282
(push (cons (match-string 1 string)
83-
(when-let (desc (match-string 2 string))
83+
(when-let* ((desc (match-string 2 string)))
8484
(replace-regexp-in-string
8585
(rx (+ space)) " "
8686
desc)))
@@ -92,7 +92,7 @@
9292
(let (alist)
9393
(cl-labels
9494
((add-commands (subcommands &optional description)
95-
(if-let (subalist (apply #'nix3-help-parse 'commands subcommands))
95+
(if-let* ((subalist (apply #'nix3-help-parse 'commands subcommands)))
9696
(dolist (x subalist)
9797
(add-commands (append subcommands (list (car x)))
9898
(cdr x)))

nix3-registry.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ registry type and the \"to\" value of the entry."
175175
(group (id transform)
176176
(if transform
177177
id
178-
(if-let (cell (gethash id table))
178+
(if-let* ((cell (gethash id table)))
179179
(format "%s registry"
180180
(capitalize (symbol-name (car cell))))
181181
"")))
@@ -187,7 +187,7 @@ registry type and the \"to\" value of the entry."
187187
(cons 'annotation-function #'annotator)))
188188
(complete-with-action action items string pred))))
189189
(let ((input (completing-read prompt #'completions)))
190-
(if-let (entry (gethash input table))
190+
(if-let* ((entry (gethash input table)))
191191
(cons input (cdr entry))
192192
(when (and add-to-registry
193193
(nix3-registry--flake-url-p input)
@@ -243,7 +243,7 @@ registry type and the \"to\" value of the entry."
243243
name flake))
244244

245245
(defun nix3-registry--maybe-origin-flake-url ()
246-
(when-let (git-url (cdr (assoc "origin" (nix3-git-remotes))))
246+
(when-let* ((git-url (cdr (assoc "origin" (nix3-git-remotes)))))
247247
(nix3-flake-ref-alist-to-url
248248
(nix3-git-url-to-flake-alist git-url))))
249249

nix3-transient.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ This is a function that takes a command line as an argument."
138138
(required :initarg :required :initform t)))
139139

140140
(cl-defmethod transient-init-value ((obj nix3-transient-output-variable))
141-
(if-let (value (eval (oref obj variable)))
141+
(if-let* ((value (eval (oref obj variable))))
142142
(oset obj value value)
143143
(when (oref obj required)
144144
(let ((value (transient-infix-read obj)))
@@ -442,7 +442,7 @@ will be refreshed."
442442
(format "*nix eval<%s>*" path)))
443443
(message "%s: %s" path string)))
444444
(go (path)
445-
(if-let (names (get-attr-names path))
445+
(if-let* ((names (get-attr-names path)))
446446
(let ((new-path (completing-read (format "Attribute (%s): " path)
447447
;; Build candidates that are full
448448
;; attribute paths. This will make
@@ -509,7 +509,7 @@ will be refreshed."
509509
","))
510510
(propertize ")" 'face 'transient-inactive-value))))
511511
(interactive)
512-
(if-let (licenses (nix3-transient--package-license))
512+
(if-let* ((licenses (nix3-transient--package-license)))
513513
(nix3-transient--browse-license-url
514514
(if (assq 'fullName licenses)
515515
licenses
@@ -521,7 +521,7 @@ will be refreshed."
521521
(user-error "No license")))
522522

523523
(defun nix3-transient--browse-license-url (license)
524-
(if-let (url (alist-get 'url license))
524+
(if-let* ((url (alist-get 'url license)))
525525
(browse-url url)
526526
(user-error "License %s has no URL"
527527
(or (alist-get 'spdxId license)
@@ -534,7 +534,7 @@ will be refreshed."
534534
licenses)))
535535
(cl-labels
536536
((annotator (candidate)
537-
(when-let (license (cdr (assoc candidate alist)))
537+
(when-let* ((license (cdr (assoc candidate alist))))
538538
(format " (%s)"
539539
(mapconcat (lambda (x)
540540
(symbol-name (car x)))

0 commit comments

Comments
 (0)