branch: elpa/magit
commit fc69a08eb04af57b55d4f02b1dfe218daaa9b36a
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    Use shared bindings with cond-let and cond-let*
---
 lisp/magit-diff.el    | 34 +++++++++----------
 lisp/magit-push.el    | 12 +++----
 lisp/magit-refs.el    | 75 ++++++++++++++++++++---------------------
 lisp/magit-section.el | 92 +++++++++++++++++++++++++--------------------------
 4 files changed, 107 insertions(+), 106 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 41ec3e33b01..45addb385ed 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1195,16 +1195,16 @@ If no DWIM context is found, nil is returned."
        (unmerged 'unmerged)
        (unpushed (magit-diff--range-to-endpoints (oref it value)))
        (unpulled (magit-diff--range-to-endpoints (oref it value)))
-       (branch (let ((current (magit-get-current-branch))
-                     (atpoint (oref it value)))
-                 (cond-let
-                   ((not (equal atpoint current))
-                    (format "%s...%s" (or current "HEAD") atpoint))
-                   ([upstream (magit-get-upstream-branch)]
-                    (format "%s...%s" upstream current))
-                   ((magit-anything-modified-p)
-                    current)
-                   ((cons 'commit current)))))
+       (branch (cond-let
+                 [[current (magit-get-current-branch)]
+                  [atpoint (oref it value)]]
+                 ((not (equal atpoint current))
+                  (format "%s...%s" (or current "HEAD") atpoint))
+                 ([upstream (magit-get-upstream-branch)]
+                  (format "%s...%s" upstream current))
+                 ((magit-anything-modified-p)
+                  current)
+                 ((cons 'commit current))))
        (commit (cons 'commit (oref it value)))
        ([file commit] (cons 'commit (oref (oref it parent) value)))
        ([hunk file commit]
@@ -2298,13 +2298,13 @@ keymap is the parent of their keymaps."
         (let (files)
           (while (looking-at "^[-0-9]+\t[-0-9]+\t\\(.+\\)$")
             (push (magit-decode-git-path
-                   (let ((f (match-str 1)))
-                     (cond
-                      ((string-match "{.* => \\(.*\\)}" f)
-                       (replace-match (match-str 1 f) nil t f))
-                      ((string-match " => " f)
-                       (substring f (match-end 0)))
-                      (t f))))
+                   (cond-let
+                     [[file (match-str 1)]]
+                     ((string-match "{.* => \\(.*\\)}" file)
+                      (replace-match (match-str 1 file) nil t file))
+                     ((string-match " => " file)
+                      (substring file (match-end 0)))
+                     (file)))
                   files)
             (magit-delete-line))
           (setq files (nreverse files))
diff --git a/lisp/magit-push.el b/lisp/magit-push.el
index a1691c8d1ad..c64acb511eb 100644
--- a/lisp/magit-push.el
+++ b/lisp/magit-push.el
@@ -302,12 +302,12 @@ what this command will do.  To add it use something like:
                      ;; Note: Avoid `magit-get-remote' because it
                      ;; filters out the local repo case (".").
                      (magit-get "branch" branch "remote")
-                     (let ((remotes (magit-list-remotes)))
-                       (cond
-                        ((and (magit-git-version>= "2.27")
-                              (length= remotes 1))
-                         (car remotes))
-                        ((member "origin" remotes) "origin"))))))
+                       (cond-let
+                         [[remotes (magit-list-remotes)]]
+                         ((and (magit-git-version>= "2.27")
+                               (length= remotes 1))
+                          (car remotes))
+                         ((car (member "origin" remotes)))))))
     (if (null remote)
         "nothing (no remote)"
       (let ((refspec (magit-get "remote" remote "push")))
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index 0792da6d785..c72e282831c 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -435,47 +435,48 @@ different, but only if you have customized the option
 `magit-visit-ref-behavior' (which see).  When invoked from a
 menu this command always behaves like `magit-show-commit'."
   (interactive)
-  (if (and (derived-mode-p 'magit-refs-mode)
-           (magit-section-match '(branch tag))
-           (not (magit-menu-position)))
-      (let ((ref (oref (magit-current-section) value)))
-        (cond (current-prefix-arg
-               (cond ((memq 'focus-on-ref magit-visit-ref-behavior)
-                      (magit-refs-setup-buffer ref 
(magit-show-refs-arguments)))
-                     (magit-visit-ref-behavior
-                      ;; Don't prompt for commit to visit.
-                      (let ((current-prefix-arg nil))
-                        (call-interactively #'magit-show-commit)))))
-              ((and (memq 'create-branch magit-visit-ref-behavior)
-                    (magit-section-match [branch remote]))
-               (let ((branch (cdr (magit-split-branch-name ref))))
-                 (if (magit-branch-p branch)
-                     (if (magit-rev-eq branch ref)
-                         (magit-call-git "checkout" branch)
-                       (setq branch (propertize branch 'face 
'magit-branch-local))
-                       (setq ref (propertize ref 'face 'magit-branch-remote))
-                       (pcase (prog1 (read-char-choice (format (propertize "\
+  (cond-let
+    ((not (and (derived-mode-p 'magit-refs-mode)
+               (magit-section-match '(branch tag))
+               (not (magit-menu-position))))
+     (call-interactively #'magit-show-commit))
+    [[ref (oref (magit-current-section) value)]]
+    ((and current-prefix-arg
+          (memq 'focus-on-ref magit-visit-ref-behavior))
+     (magit-refs-setup-buffer ref (magit-show-refs-arguments)))
+    ((and current-prefix-arg
+          magit-visit-ref-behavior
+          ;; Don't prompt for commit to visit.
+          (let ((current-prefix-arg nil))
+            (call-interactively #'magit-show-commit))))
+    ((and (memq 'create-branch magit-visit-ref-behavior)
+          (magit-section-match [branch remote]))
+     (let ((branch (cdr (magit-split-branch-name ref))))
+       (if (magit-branch-p branch)
+           (if (magit-rev-eq branch ref)
+               (magit-call-git "checkout" branch)
+             (setq branch (propertize branch 'face 'magit-branch-local))
+             (setq ref (propertize ref 'face 'magit-branch-remote))
+             (pcase (prog1 (read-char-choice (format (propertize "\
 Branch %s already exists.
   [c]heckout %s as-is
   [r]reset %s to %s and checkout %s
   [a]bort " 'face 'minibuffer-prompt) branch branch branch ref branch)
-                                                       '(?c ?r ?a))
-                                (message "")) ; otherwise prompt sticks
-                         (?c (magit-call-git "checkout" branch))
-                         (?r (magit-call-git "checkout" "-B" branch ref))
-                         (?a (user-error "Abort"))))
-                   (magit-call-git "checkout" "-b" branch ref))
-                 (setq magit-buffer-upstream branch)
-                 (magit-refresh)))
-              ((or (memq 'checkout-any magit-visit-ref-behavior)
-                   (and (memq 'checkout-branch magit-visit-ref-behavior)
-                        (magit-section-match [branch local])))
-               (magit-call-git "checkout" ref)
-               (setq magit-buffer-upstream ref)
-               (magit-refresh))
-              (t
-               (call-interactively #'magit-show-commit))))
-    (call-interactively #'magit-show-commit)))
+                                             '(?c ?r ?a))
+                      (message "")) ; otherwise prompt sticks
+               (?c (magit-call-git "checkout" branch))
+               (?r (magit-call-git "checkout" "-B" branch ref))
+               (?a (user-error "Abort"))))
+         (magit-call-git "checkout" "-b" branch ref))
+       (setq magit-buffer-upstream branch)
+       (magit-refresh)))
+    ((or (memq 'checkout-any magit-visit-ref-behavior)
+         (and (memq 'checkout-branch magit-visit-ref-behavior)
+              (magit-section-match [branch local])))
+     (magit-call-git "checkout" ref)
+     (setq magit-buffer-upstream ref)
+     (magit-refresh))
+    ((call-interactively #'magit-show-commit))))
 
 ;;; Sections
 
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index d030c3c35a8..97e097dc471 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -809,25 +809,25 @@ the beginning of the current section."
   "Move to the beginning of the next sibling section.
 If there is no next sibling section, then move to the parent."
   (interactive)
-  (let ((current (magit-current-section)))
-    (cond-let
-      ((not (oref current parent))
-       (magit-section-goto 1))
-      ([next (car (magit-section-siblings current 'next))]
-       (magit-section-goto next))
-      ((magit-section-forward)))))
+  (cond-let
+    [[current (magit-current-section)]]
+    ((not (oref current parent))
+     (magit-section-goto 1))
+    ([next (car (magit-section-siblings current 'next))]
+     (magit-section-goto next))
+    ((magit-section-forward))))
 
 (defun magit-section-backward-sibling ()
   "Move to the beginning of the previous sibling section.
 If there is no previous sibling section, then move to the parent."
   (interactive)
-  (let ((current (magit-current-section)))
-    (cond-let
-      ((not (oref current parent))
-       (magit-section-goto -1))
-      ([previous (car (magit-section-siblings current 'prev))]
-       (magit-section-goto previous))
-      ((magit-section-backward)))))
+  (cond-let
+    [[current (magit-current-section)]]
+    ((not (oref current parent))
+     (magit-section-goto -1))
+    ([previous (car (magit-section-siblings current 'prev))]
+     (magit-section-goto previous))
+    ((magit-section-backward))))
 
 (defun magit-mouse-set-point (event &optional promote-to-region)
   "Like `mouse-set-point' but also call `magit-section-movement-hook'."
@@ -984,35 +984,35 @@ from using this key and instead bind another key to 
`tab-next'.  Because
 `tab-bar-mode' does not use a mode map but instead manipulates the
 global map, this involves advising `tab-bar--define-keys'."
   (interactive (list (magit-current-section)))
-  (cond
-   ((and (equal (this-command-keys) [C-tab])
-         (eq (global-key-binding [C-tab]) 'tab-next)
-         (fboundp 'tab-bar-switch-to-next-tab))
-    (tab-bar-switch-to-next-tab current-prefix-arg))
-   ((eq section magit-root-section)
-    (magit-section-cycle-global))
-   ((oref section hidden)
-    (magit-section-show section)
-    (magit-section-hide-children section))
-   ((let ((children (oref section children)))
-      (cond ((and (seq-some (##oref % hidden)   children)
-                  (seq-some (##oref % children) children))
-             (magit-section-show-headings section))
-            ((seq-some #'magit-section-hidden-body children)
-             (magit-section-show-children section))
-            ((magit-section-hide section)))))))
+  (cond-let
+    ((and (equal (this-command-keys) [C-tab])
+          (eq (global-key-binding [C-tab]) 'tab-next)
+          (fboundp 'tab-bar-switch-to-next-tab))
+     (tab-bar-switch-to-next-tab current-prefix-arg))
+    ((eq section magit-root-section)
+     (magit-section-cycle-global))
+    ((oref section hidden)
+     (magit-section-show section)
+     (magit-section-hide-children section))
+    [[children (oref section children)]]
+    ((and (seq-some (##oref % hidden)   children)
+          (seq-some (##oref % children) children))
+     (magit-section-show-headings section))
+    ((seq-some #'magit-section-hidden-body children)
+     (magit-section-show-children section))
+    ((magit-section-hide section))))
 
 (defun magit-section-cycle-global ()
   "Cycle visibility of all sections in the current buffer."
   (interactive)
-  (let ((children (oref magit-root-section children)))
-    (cond ((and (seq-some (##oref % hidden)   children)
-                (seq-some (##oref % children) children))
-           (magit-section-show-headings magit-root-section))
-          ((seq-some #'magit-section-hidden-body children)
-           (magit-section-show-children magit-root-section))
-          (t
-           (mapc #'magit-section-hide children)))))
+  (cond-let
+    [[children (oref magit-root-section children)]]
+    ((and (seq-some (##oref % hidden)   children)
+          (seq-some (##oref % children) children))
+     (magit-section-show-headings magit-root-section))
+    ((seq-some #'magit-section-hidden-body children)
+     (magit-section-show-children magit-root-section))
+    ((mapc #'magit-section-hide children))))
 
 (defun magit-section-hidden (section)
   "Return t if SECTION and/or an ancestor is hidden."
@@ -1250,13 +1250,13 @@ of course you want to be that precise."
       (or (magit-section-match-2 (cdr condition) section)
           (and-let ((parent (oref section parent)))
             (magit-section-match-2 condition parent)))
-    (and (let ((c (car condition)))
-           (cond-let
-             ((class-p c)
-              (cl-typep section c))
-             ([class (cdr (assq c magit--section-type-alist))]
-              (cl-typep section class))
-             ((eq (oref section type) c))))
+    (and (cond-let
+           [[c (car condition)]]
+           ((class-p c)
+            (cl-typep section c))
+           ([class (cdr (assq c magit--section-type-alist))]
+            (cl-typep section class))
+           ((eq (oref section type) c)))
          (or (not (setq condition (cdr condition)))
              (and-let ((parent (oref section parent)))
                (magit-section-match-2 condition parent))))))

Reply via email to