aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2025-08-22 20:55:35 +0200
committerJonas Bernoulli <jonas@bernoul.li>2025-08-22 20:55:35 +0200
commit28f30e14036f567640f1cbfca94a67e5e2013303 (patch)
tree26b01bb3ca13133cb06d26cfd61643340b8dd255
parent594723c6391fb1320a1a80d688edda7c96803f16 (diff)
Use cond-let and cond-let*
I've only recently implemented these forms, but before that I have been hoping they would be added to Emacs for a decade or so. Even so, I do not yet have any practice using them, and so my sense of when to use them, and when not, has yet to evolve.
-rw-r--r--lisp/git-commit.el20
-rw-r--r--lisp/git-rebase.el26
-rw-r--r--lisp/magit-base.el26
-rw-r--r--lisp/magit-blame.el16
-rw-r--r--lisp/magit-branch.el100
-rw-r--r--lisp/magit-diff.el228
-rw-r--r--lisp/magit-extras.el104
-rw-r--r--lisp/magit-git.el225
-rw-r--r--lisp/magit-log.el36
-rw-r--r--lisp/magit-merge.el30
-rw-r--r--lisp/magit-mode.el100
-rw-r--r--lisp/magit-refs.el26
-rw-r--r--lisp/magit-section.el67
-rw-r--r--lisp/magit-submodule.el15
-rw-r--r--lisp/magit-transient.el54
-rw-r--r--lisp/magit-wip.el85
16 files changed, 573 insertions, 585 deletions
diff --git a/lisp/git-commit.el b/lisp/git-commit.el
index b077058..0bcad3d 100644
--- a/lisp/git-commit.el
+++ b/lisp/git-commit.el
@@ -796,16 +796,16 @@ Save current message first."
(defun git-commit-save-message ()
"Save current message to `log-edit-comment-ring'."
(interactive)
- (if-let ((message (git-commit-buffer-message)))
- (progn
- (when-let ((index (ring-member log-edit-comment-ring message)))
- (ring-remove log-edit-comment-ring index))
- (ring-insert log-edit-comment-ring message)
- (when git-commit-use-local-message-ring
- (magit-repository-local-set 'log-edit-comment-ring
- log-edit-comment-ring))
- (message "Message saved"))
- (message "Only whitespace and/or comments; message not saved")))
+ (cond-let
+ ([message (git-commit-buffer-message)]
+ (when-let ((index (ring-member log-edit-comment-ring message)))
+ (ring-remove log-edit-comment-ring index))
+ (ring-insert log-edit-comment-ring message)
+ (when git-commit-use-local-message-ring
+ (magit-repository-local-set 'log-edit-comment-ring
+ log-edit-comment-ring))
+ (message "Message saved"))
+ ((message "Only whitespace and/or comments; message not saved"))))
(defun git-commit-prepare-message-ring ()
(make-local-variable 'log-edit-comment-ring-index)
diff --git a/lisp/git-rebase.el b/lisp/git-rebase.el
index dc7c6d0..a2c89be 100644
--- a/lisp/git-rebase.el
+++ b/lisp/git-rebase.el
@@ -362,15 +362,15 @@ BATCH is non-nil, in which case nil is returned. Non-nil
BATCH also ignores commented lines."
(save-excursion
(goto-char (line-beginning-position))
- (if-let* ((re-start (if batch
- "^"
- (format "^\\(?99:%s\\)? *"
- (regexp-quote comment-start))))
- (type (seq-some (pcase-lambda (`(,type . ,re))
- (let ((case-fold-search nil))
- (and (looking-at (concat re-start re)) type)))
- git-rebase-line-regexps)))
- (git-rebase-action
+ (cond-let*
+ ([re-start (if batch
+ "^"
+ (format "^\\(?99:%s\\)? *" (regexp-quote comment-start)))]
+ [type (seq-some (pcase-lambda (`(,type . ,re))
+ (let ((case-fold-search nil))
+ (and (looking-at (concat re-start re)) type)))
+ git-rebase-line-regexps)]
+ (git-rebase-action
:action-type type
:action (and-let ((action (match-str 1)))
(or (cdr (assoc action git-rebase-short-options))
@@ -378,10 +378,10 @@ BATCH also ignores commented lines."
:action-options (match-str 2)
:target (match-str 3)
:trailer (match-str 5)
- :comment-p (and (match-str 99) t))
- (and (not batch)
- ;; Use empty object rather than nil to ease handling.
- (git-rebase-action)))))
+ :comment-p (and (match-str 99) t)))
+ ((not batch)
+ ;; Use empty object rather than nil to ease handling.
+ (git-rebase-action)))))
(defun git-rebase-set-action (action)
"Set action of commit line to ACTION.
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index 7e5a69b..85907f7 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -1159,19 +1159,19 @@ Like `message', except that `message-log-max' is bound to nil."
(defun magit--ellipsis (&optional where)
"Build an ellipsis always as string, depending on WHERE."
- (if (stringp magit-ellipsis)
- magit-ellipsis
- (if-let ((pair (car (or
- (alist-get (or where t) magit-ellipsis)
- (alist-get t magit-ellipsis)))))
- (pcase-let* ((`(,fancy . ,universal) pair)
- (ellipsis (if (and fancy (char-displayable-p fancy))
- fancy
- universal)))
- (if (characterp ellipsis)
- (char-to-string ellipsis)
- ellipsis))
- (user-error "Variable magit-ellipsis is invalid"))))
+ (cond-let
+ ((stringp magit-ellipsis)
+ magit-ellipsis)
+ ([pair (car (or (alist-get (or where t) magit-ellipsis)
+ (alist-get t magit-ellipsis)))]
+ (pcase-let* ((`(,fancy . ,universal) pair)
+ (ellipsis (if (and fancy (char-displayable-p fancy))
+ fancy
+ universal)))
+ (if (characterp ellipsis)
+ (char-to-string ellipsis)
+ ellipsis)))
+ ((user-error "Variable magit-ellipsis is invalid"))))
(defun magit--ext-regexp-quote (string)
"Like `reqexp-quote', but for Extended Regular Expressions."
diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index 1e5f340..084bae1 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -747,14 +747,14 @@ modes is toggled, then this mode also gets toggled automatically.
(delete-overlay ov)))))
(defun magit-blame-maybe-show-message ()
- (when (magit-blame--style-get 'show-message)
- (if-let ((msg (cdr (assoc "summary"
- (gethash (oref (magit-current-blame-chunk)
- orig-rev)
- magit-blame-cache)))))
- (progn (set-text-properties 0 (length msg) nil msg)
- (magit-msg "%S" msg))
- (magit-msg "Commit data not available yet. Still blaming."))))
+ (cond-let
+ ((not (magit-blame--style-get 'show-message)))
+ ([msg (cdr (assoc "summary"
+ (gethash (oref (magit-current-blame-chunk) orig-rev)
+ magit-blame-cache)))]
+ (set-text-properties 0 (length msg) nil msg)
+ (magit-msg "%S" msg))
+ ((magit-msg "Commit data not available yet. Still blaming."))))
;;; Commands
diff --git a/lisp/magit-branch.el b/lisp/magit-branch.el
index 6415455..3b2b40f 100644
--- a/lisp/magit-branch.el
+++ b/lisp/magit-branch.el
@@ -496,37 +496,38 @@ from the source branch's upstream, then an error is raised."
(magit-anything-modified-p))
(message "Staying on HEAD due to uncommitted changes")
(setq checkout t))
- (if-let ((current (magit-get-current-branch)))
- (let ((tracked (magit-get-upstream-branch current))
- base)
- (when from
- (unless (magit-rev-ancestor-p from current)
- (user-error "Cannot spin off %s. %s is not reachable from %s"
- branch from current))
- (when (and tracked
- (magit-rev-ancestor-p from tracked))
- (user-error "Cannot spin off %s. %s is ancestor of upstream %s"
- branch from tracked)))
- (let ((magit-process-raise-error t))
- (if checkout
- (magit-call-git "checkout" "-b" branch current)
- (magit-call-git "branch" branch current)))
- (when-let ((upstream (magit-get-indirect-upstream-branch current)))
- (magit-call-git "branch" "--set-upstream-to" upstream branch))
- (when (and tracked
- (setq base
- (if from
- (concat from "^")
- (magit-git-string "merge-base" current tracked)))
- (not (magit-rev-eq base current)))
- (if checkout
- (magit-call-git "update-ref" "-m"
- (format "reset: moving to %s" base)
- (concat "refs/heads/" current) base)
- (magit-call-git "reset" "--hard" base))))
- (if checkout
- (magit-call-git "checkout" "-b" branch)
- (magit-call-git "branch" branch)))
+ (cond-let
+ ([current (magit-get-current-branch)]
+ (let ((tracked (magit-get-upstream-branch current))
+ base)
+ (when from
+ (unless (magit-rev-ancestor-p from current)
+ (user-error "Cannot spin off %s. %s is not reachable from %s"
+ branch from current))
+ (when (and tracked
+ (magit-rev-ancestor-p from tracked))
+ (user-error "Cannot spin off %s. %s is ancestor of upstream %s"
+ branch from tracked)))
+ (let ((magit-process-raise-error t))
+ (if checkout
+ (magit-call-git "checkout" "-b" branch current)
+ (magit-call-git "branch" branch current)))
+ (when-let ((upstream (magit-get-indirect-upstream-branch current)))
+ (magit-call-git "branch" "--set-upstream-to" upstream branch))
+ (when (and tracked
+ (setq base
+ (if from
+ (concat from "^")
+ (magit-git-string "merge-base" current tracked)))
+ (not (magit-rev-eq base current)))
+ (if checkout
+ (magit-call-git "update-ref" "-m"
+ (format "reset: moving to %s" base)
+ (concat "refs/heads/" current) base)
+ (magit-call-git "reset" "--hard" base)))))
+ (checkout
+ (magit-call-git "checkout" "-b" branch))
+ ((magit-call-git "branch" branch)))
(magit-refresh))
;;;###autoload
@@ -728,25 +729,24 @@ prompt is confusing."
(magit-set nil "branch" branch "pushRemote"))
(defun magit-delete-remote-branch-sentinel (remote refs process event)
- (when (memq (process-status process) '(exit signal))
- (if (= (process-exit-status process) 1)
- (if-let* ((on-remote (mapcar (##concat "refs/remotes/" remote "/" %)
- (magit-remote-list-branches remote)))
- (rest (seq-filter (##and (not (member % on-remote))
- (magit-ref-exists-p %))
- refs)))
- (progn
- (process-put process 'inhibit-refresh t)
- (magit-process-sentinel process event)
- (setq magit-this-error nil)
- (message "Some remote branches no longer exist. %s"
- "Deleting just the local tracking refs instead...")
- (dolist (ref rest)
- (magit-call-git "update-ref" "-d" ref))
- (magit-refresh)
- (message "Deleting local remote-tracking refs...done"))
- (magit-process-sentinel process event))
- (magit-process-sentinel process event))))
+ (cond-let*
+ ((not (memq (process-status process) '(exit signal))))
+ ([_(= (process-exit-status process) 1)]
+ [on-remote (mapcar (##concat "refs/remotes/" remote "/" %)
+ (magit-remote-list-branches remote))]
+ [rest (seq-filter (##and (not (member % on-remote))
+ (magit-ref-exists-p %))
+ refs)]
+ (process-put process 'inhibit-refresh t)
+ (magit-process-sentinel process event)
+ (setq magit-this-error nil)
+ (message "Some remote branches no longer exist. %s"
+ "Deleting just the local tracking refs instead...")
+ (dolist (ref rest)
+ (magit-call-git "update-ref" "-d" ref))
+ (magit-refresh)
+ (message "Deleting local remote-tracking refs...done"))
+ ((magit-process-sentinel process event))))
;;;###autoload
(defun magit-branch-rename (old new &optional force)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index bf676a8..41ec3e3 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -851,28 +851,20 @@ and `:slant'."
('nil magit-direct-use-buffer-arguments)
((or 'always 'selected 'current 'never)
use-buffer-args)))
- (let (args files)
- (cond
- ((and (memq use-buffer-args '(always selected current))
- (eq major-mode mode))
- (setq args magit-buffer-diff-args)
- (setq files magit-buffer-diff-files))
- ((when-let ((_(memq use-buffer-args '(always selected)))
- (buffer (magit-get-mode-buffer
- mode nil
- (eq use-buffer-args 'selected))))
- (setq args (buffer-local-value 'magit-buffer-diff-args buffer))
- (setq files (buffer-local-value 'magit-buffer-diff-files buffer))
- t))
- ((plist-member (symbol-plist mode) 'magit-diff-current-arguments)
- (setq args (get mode 'magit-diff-current-arguments)))
- ((when-let ((elt (assq (intern (format "magit-diff:%s" mode))
- transient-values)))
- (setq args (cdr elt))
- t))
- (t
- (setq args (get mode 'magit-diff-default-arguments))))
- (list args files)))
+ (cond-let
+ ((and (memq use-buffer-args '(always selected current))
+ (eq major-mode mode))
+ (list magit-buffer-diff-args
+ magit-buffer-diff-files))
+ ([_(memq use-buffer-args '(always selected))]
+ [buffer (magit-get-mode-buffer mode nil (eq use-buffer-args 'selected))]
+ (list (buffer-local-value 'magit-buffer-diff-args buffer)
+ (buffer-local-value 'magit-buffer-diff-files buffer)))
+ ((plist-member (symbol-plist mode) 'magit-diff-current-arguments)
+ (list (get mode 'magit-diff-current-arguments) nil))
+ ([elt (assq (intern (format "magit-diff:%s" mode)) transient-values)]
+ (list (cdr elt) nil))
+ ((list (get mode 'magit-diff-default-arguments) nil))))
(defun magit-diff--set-value (obj &optional save)
(pcase-let* ((obj (oref obj prototype))
@@ -1174,53 +1166,51 @@ The information can be in three forms:
A string indicating a diff range.
If no DWIM context is found, nil is returned."
- (cond
- ((and-let ((commits (magit-region-values '(commit branch) t)))
- (prog1 (concat (car (last commits)) ".." (car commits))
- (deactivate-mark))))
- (magit-buffer-refname
- (cons 'commit magit-buffer-refname))
- ((derived-mode-p 'magit-stash-mode)
- (cons 'commit
- (magit-section-case
- (commit (oref it value))
- (file (thread-first it
- (oref parent)
- (oref value)))
- (hunk (thread-first it
- (oref parent)
- (oref parent)
- (oref value))))))
- ((derived-mode-p 'magit-revision-mode)
- (cons 'commit magit-buffer-revision))
- ((derived-mode-p 'magit-diff-mode)
- (pcase-exhaustive magit-buffer-diff-type
- ('committed magit-buffer-range)
- ((or 'unstaged 'staged 'undefined) magit-buffer-diff-type)))
- (t
- (magit-section-case
- ([* unstaged] 'unstaged)
- ([* staged] 'staged)
- (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)))
- (if (equal atpoint current)
- (if-let ((upstream (magit-get-upstream-branch)))
- (format "%s...%s" upstream current)
- (if (magit-anything-modified-p)
- current
- (cons 'commit current)))
- (format "%s...%s"
- (or current "HEAD")
- atpoint))))
- (commit (cons 'commit (oref it value)))
- ([file commit] (cons 'commit (oref (oref it parent) value)))
- ([hunk file commit]
- (cons 'commit (oref (oref (oref it parent) parent) value)))
- (stash (cons 'stash (oref it value)))
- (pullreq (forge--pullreq-range (oref it value) t))))))
+ (cond-let
+ ([commits (magit-region-values '(commit branch) t)]
+ (deactivate-mark)
+ (concat (car (last commits)) ".." (car commits)))
+ (magit-buffer-refname
+ (cons 'commit magit-buffer-refname))
+ ((derived-mode-p 'magit-stash-mode)
+ (cons 'commit
+ (magit-section-case
+ (commit (oref it value))
+ (file (thread-first it
+ (oref parent)
+ (oref value)))
+ (hunk (thread-first it
+ (oref parent)
+ (oref parent)
+ (oref value))))))
+ ((derived-mode-p 'magit-revision-mode)
+ (cons 'commit magit-buffer-revision))
+ ((derived-mode-p 'magit-diff-mode)
+ (pcase-exhaustive magit-buffer-diff-type
+ ('committed magit-buffer-range)
+ ((or 'unstaged 'staged 'undefined) magit-buffer-diff-type)))
+ ((magit-section-case
+ ([* unstaged] 'unstaged)
+ ([* staged] 'staged)
+ (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)))))
+ (commit (cons 'commit (oref it value)))
+ ([file commit] (cons 'commit (oref (oref it parent) value)))
+ ([hunk file commit]
+ (cons 'commit (oref (oref (oref it parent) parent) value)))
+ (stash (cons 'stash (oref it value)))
+ (pullreq (forge--pullreq-range (oref it value) t))))))
(defun magit-diff--range-to-endpoints (range)
(cond ((string-match "\\.\\.\\." range) (replace-match ".." nil nil range))
@@ -1998,13 +1988,14 @@ like 'magit-jump-to-diffstat-or-diff'."
:inapt-if-not (##cl-find-if (##eq (oref % type) 'file)
(oref magit-root-section children))
(interactive "P")
- (if-let ((section (cl-find-if (##eq (oref % type) 'file)
- (oref magit-root-section children))))
- (progn (goto-char (oref section start))
- (when expand
- (with-local-quit (magit-section-show section))
- (recenter 0)))
- (message (format "No diff sections found"))))
+ (cond-let
+ ([section (cl-find-if (##eq (oref % type) 'file)
+ (oref magit-root-section children))]
+ (goto-char (oref section start))
+ (when expand
+ (with-local-quit (magit-section-show section))
+ (recenter 0)))
+ ((message (format "No diff sections found")))))
;;; Diff Mode
@@ -2778,21 +2769,21 @@ or a ref which is not a branch, then it inserts nothing."
(magit-insert-section
( commit-message nil nil
:heading-highlight-face 'magit-diff-revision-summary-highlight)
- (if-let* ((rev magit-buffer-revision)
- (msg (with-temp-buffer
- (save-excursion (magit-rev-insert-format "%B" rev))
- (magit-revision--wash-message))))
- (progn
- (save-excursion (insert msg))
- (magit-revision--wash-message-hashes)
- (save-excursion
- (magit--add-face-text-property (point)
- (progn (forward-line) (point))
- 'magit-diff-revision-summary
- t nil t)
- (magit-insert-heading))
- (goto-char (point-max)))
- (insert "(no message)\n"))))
+ (cond-let*
+ ([rev magit-buffer-revision]
+ [msg (with-temp-buffer
+ (save-excursion (magit-rev-insert-format "%B" rev))
+ (magit-revision--wash-message))]
+ (save-excursion (insert msg))
+ (magit-revision--wash-message-hashes)
+ (save-excursion
+ (magit--add-face-text-property (point)
+ (progn (forward-line) (point))
+ 'magit-diff-revision-summary
+ t nil t)
+ (magit-insert-heading))
+ (goto-char (point-max)))
+ ((insert "(no message)\n")))))
(defun magit-insert-revision-notes ()
"Insert commit notes into a revision buffer."
@@ -2999,33 +2990,34 @@ Refer to user option `magit-revision-insert-related-refs-display-alist'."
align-to column)))))))
(defun magit-insert-revision-gravatar-cb (image size rev marker align-to column)
- (unless (eq image 'error)
- (when-let ((buffer (marker-buffer marker)))
- (with-current-buffer buffer
- (save-excursion
- (goto-char marker)
- ;; The buffer might display another revision by now or
- ;; it might have been refreshed, in which case another
- ;; process might already have inserted the image.
- (when (and (equal rev magit-buffer-revision)
- (not (eq (car-safe
- (car-safe
- (get-text-property (point) 'display)))
- 'image)))
- (setf (image-property image :ascent) 'center)
- (setf (image-property image :relief) 1)
- (setf (image-property image :scale) 1)
- (setf (image-property image :height) size)
- (let ((top (list image '(slice 0.0 0.0 1.0 0.5)))
- (bot (list image '(slice 0.0 0.5 1.0 1.0)))
- (align `((space :align-to ,align-to))))
- (let ((inhibit-read-only t))
- (insert (propertize " " 'display top))
- (insert (propertize " " 'display align))
- (forward-line)
- (forward-char column)
- (insert (propertize " " 'display bot))
- (insert (propertize " " 'display align))))))))))
+ (cond-let
+ ((eq image 'error))
+ ([buffer (marker-buffer marker)]
+ (with-current-buffer buffer
+ (save-excursion
+ (goto-char marker)
+ ;; The buffer might display another revision by now or
+ ;; it might have been refreshed, in which case another
+ ;; process might already have inserted the image.
+ (when (and (equal rev magit-buffer-revision)
+ (not (eq (car-safe
+ (car-safe
+ (get-text-property (point) 'display)))
+ 'image)))
+ (setf (image-property image :ascent) 'center)
+ (setf (image-property image :relief) 1)
+ (setf (image-property image :scale) 1)
+ (setf (image-property image :height) size)
+ (let ((top (list image '(slice 0.0 0.0 1.0 0.5)))
+ (bot (list image '(slice 0.0 0.5 1.0 1.0)))
+ (align `((space :align-to ,align-to))))
+ (let ((inhibit-read-only t))
+ (insert (propertize " " 'display top))
+ (insert (propertize " " 'display align))
+ (forward-line)
+ (forward-char column)
+ (insert (propertize " " 'display bot))
+ (insert (propertize " " 'display align))))))))))
;;; Merge-Preview Mode
diff --git a/lisp/magit-extras.el b/lisp/magit-extras.el
index 8325c1c..c34c0cf 100644
--- a/lisp/magit-extras.el
+++ b/lisp/magit-extras.el
@@ -672,42 +672,41 @@ a hunk, then strip the diff marker column and keep only either
the added or removed lines, depending on the sign of the prefix
argument."
(interactive "P")
- (cond
- ((and arg
- (magit-section-internal-region-p)
- (magit-section-match 'hunk))
- (kill-new
- (thread-last (buffer-substring-no-properties
- (region-beginning)
- (region-end))
- (replace-regexp-in-string
- (format "^\\%c.*\n?" (if (< (prefix-numeric-value arg) 0) ?+ ?-))
- "")
- (replace-regexp-in-string "^[ +-]" "")))
- (deactivate-mark))
- ((use-region-p)
- (call-interactively #'copy-region-as-kill))
- (t
- (when-let* ((section (magit-current-section))
- (value (oref section value)))
- (magit-section-case
- ((branch commit module-commit tag)
- (let ((default-directory default-directory) ref)
- (magit-section-case
- ((branch tag)
- (setq ref value))
- (module-commit
- (setq default-directory
- (file-name-as-directory
- (expand-file-name (magit-section-parent-value section)
- (magit-toplevel))))))
- (setq value (magit-rev-parse
- (and magit-copy-revision-abbreviated "--short")
- value))
- (push (list value default-directory) magit-revision-stack)
- (kill-new (message "%s" (or (and current-prefix-arg ref)
- value)))))
- (t (kill-new (message "%s" value))))))))
+ (cond-let*
+ ((and arg
+ (magit-section-internal-region-p)
+ (magit-section-match 'hunk))
+ (kill-new
+ (thread-last (buffer-substring-no-properties
+ (region-beginning)
+ (region-end))
+ (replace-regexp-in-string
+ (format "^\\%c.*\n?" (if (< (prefix-numeric-value arg) 0) ?+ ?-))
+ "")
+ (replace-regexp-in-string "^[ +-]" "")))
+ (deactivate-mark))
+ ((use-region-p)
+ (call-interactively #'copy-region-as-kill))
+ ([section (magit-current-section)]
+ [value (oref section value)]
+ (magit-section-case
+ ((branch commit module-commit tag)
+ (let ((default-directory default-directory) ref)
+ (magit-section-case
+ ((branch tag)
+ (setq ref value))
+ (module-commit
+ (setq default-directory
+ (file-name-as-directory
+ (expand-file-name (magit-section-parent-value section)
+ (magit-toplevel))))))
+ (setq value (magit-rev-parse
+ (and magit-copy-revision-abbreviated "--short")
+ value))
+ (push (list value default-directory) magit-revision-stack)
+ (kill-new (message "%s" (or (and current-prefix-arg ref)
+ value)))))
+ (t (kill-new (message "%s" value)))))))
;;;###autoload
(defun magit-copy-buffer-revision ()
@@ -736,22 +735,23 @@ When `magit-copy-revision-abbreviated' is non-nil, save the
abbreviated revision to the `kill-ring' and the
`magit-revision-stack'."
(interactive)
- (if (use-region-p)
- (call-interactively #'copy-region-as-kill)
- (when-let ((rev (or magit-buffer-revision
- (cl-case major-mode
- (magit-diff-mode
- (if (string-match "\\.\\.\\.?\\(.+\\)"
- magit-buffer-range)
- (match-str 1 magit-buffer-range)
- magit-buffer-range))
- (magit-status-mode "HEAD")))))
- (when (magit-commit-p rev)
- (setq rev (magit-rev-parse
- (and magit-copy-revision-abbreviated "--short")
- rev))
- (push (list rev default-directory) magit-revision-stack)
- (kill-new (message "%s" rev))))))
+ (cond-let*
+ ((use-region-p)
+ (call-interactively #'copy-region-as-kill))
+ ([rev (or magit-buffer-revision
+ (cl-case major-mode
+ (magit-diff-mode
+ (if (string-match "\\.\\.\\.?\\(.+\\)"
+ magit-buffer-range)
+ (match-str 1 magit-buffer-range)
+ magit-buffer-range))
+ (magit-status-mode "HEAD")))]
+ [_(magit-commit-p rev)]
+ (setq rev (magit-rev-parse
+ (and magit-copy-revision-abbreviated "--short")
+ rev))
+ (push (list rev default-directory) magit-revision-stack)
+ (kill-new (message "%s" rev)))))
;;; Buffer Switching
diff --git a/lisp/magit-git.el b/lisp/magit-git.el
index b886481..a286805 100644
--- a/lisp/magit-git.el
+++ b/lisp/magit-git.el
@@ -883,66 +883,60 @@ returning the truename."
(magit--with-refresh-cache
(cons (or directory default-directory) 'magit-toplevel)
(magit--with-safe-default-directory directory
- (if-let ((topdir (magit-rev-parse-safe "--show-toplevel")))
- (let (updir)
- (setq topdir (magit-expand-git-file-name topdir))
- (cond
- ((and
- ;; Always honor these settings.
- (not find-file-visit-truename)
- (not (getenv "GIT_WORK_TREE"))
- ;; `--show-cdup' is the relative path to the toplevel
- ;; from `(file-truename default-directory)'. Here we
- ;; pretend it is relative to `default-directory', and
- ;; go to that directory. Then we check whether
- ;; `--show-toplevel' still returns the same value and
- ;; whether `--show-cdup' now is the empty string. If
- ;; both is the case, then we are at the toplevel of
- ;; the same working tree, but also avoided needlessly
- ;; following any symlinks.
- (progn
- (setq updir (file-name-as-directory
- (magit-rev-parse-safe "--show-cdup")))
- (setq updir (if (file-name-absolute-p updir)
- (concat (file-remote-p default-directory)
- updir)
- (expand-file-name updir)))
- (and-let*
- ((default-directory updir)
- (top (and (string-equal
- (magit-rev-parse-safe "--show-cdup") "")
- (magit-rev-parse-safe "--show-toplevel"))))
- (string-equal (magit-expand-git-file-name top) topdir))))
- updir)
- ((concat (file-remote-p default-directory)
- (file-name-as-directory topdir)))))
- (and-let* ((gitdir (magit-rev-parse-safe "--git-dir"))
- (gitdir (file-name-as-directory
- (if (file-name-absolute-p gitdir)
- ;; We might have followed a symlink.
- (concat (file-remote-p default-directory)
- (magit-expand-git-file-name gitdir))
- (expand-file-name gitdir)))))
- (if (magit-bare-repo-p)
- gitdir
- (let* ((link (expand-file-name "gitdir" gitdir))
- (wtree (and (file-exists-p link)
- (magit-file-line link))))
- (cond
- ((and wtree
- ;; Ignore .git/gitdir files that result from a
- ;; Git bug. See #2364.
- (not (equal wtree ".git")))
- ;; Return the linked working tree.
- (concat (file-remote-p default-directory)
- (file-name-directory wtree)))
- ;; The working directory may not be the parent
- ;; directory of .git if it was set up with
- ;; "git init --separate-git-dir". See #2955.
- ((car (rassoc gitdir magit--separated-gitdirs)))
- (;; Step outside the control directory to enter the
- ;; working tree.
- (file-name-directory (directory-file-name gitdir)))))))))))
+ (cond-let*
+ ([topdir (magit-rev-parse-safe "--show-toplevel")]
+ [topdir (magit-expand-git-file-name topdir)]
+ (cond-let*
+ (;; Always honor these settings.
+ [_(not find-file-visit-truename)]
+ [_(not (getenv "GIT_WORK_TREE"))]
+ ;; `--show-cdup' is the relative path to the toplevel
+ ;; from `(file-truename default-directory)'. Here we
+ ;; pretend it is relative to `default-directory', and
+ ;; go to that directory. Then we check whether
+ ;; `--show-toplevel' still returns the same value and
+ ;; whether `--show-cdup' now is the empty string. If
+ ;; both is the case, then we are at the toplevel of
+ ;; the same working tree, but also avoided needlessly
+ ;; following any symlinks.
+ [updir (file-name-as-directory
+ (magit-rev-parse-safe "--show-cdup"))]
+ [updir (if (file-name-absolute-p updir)
+ (concat (file-remote-p default-directory) updir)
+ (expand-file-name updir))]
+ [updir->topdir
+ (let ((default-directory updir))
+ (and (string-equal (magit-rev-parse-safe "--show-cdup") "")
+ (magit-rev-parse-safe "--show-toplevel")))]
+ [_(string-equal (magit-expand-git-file-name updir->topdir) topdir)]
+ updir)
+ ((concat (file-remote-p default-directory)
+ (file-name-as-directory topdir)))))
+ ([gitdir (magit-rev-parse-safe "--git-dir")]
+ [gitdir (file-name-as-directory
+ (if (file-name-absolute-p gitdir)
+ ;; We might have followed a symlink.
+ (concat (file-remote-p default-directory)
+ (magit-expand-git-file-name gitdir))
+ (expand-file-name gitdir)))]
+ (cond-let*
+ ((magit-bare-repo-p) gitdir)
+ ;; Return the linked working tree, if any.
+ ([link (expand-file-name "gitdir" gitdir)]
+ [wtree (and (file-exists-p link)
+ (magit-file-line link))]
+ ;; Ignore ".git/gitdir" files that result from a Git bug.
+ ;; This has long been fixed, but old repository may still
+ ;; exist that contain such a file. See #2364.
+ [_(not (equal wtree ".git"))]
+ (concat (file-remote-p default-directory)
+ (file-name-directory wtree)))
+ ;; The working directory may not be the parent
+ ;; directory of .git if it was set up with
+ ;; "git init --separate-git-dir". See #2955.
+ ((car (rassoc gitdir magit--separated-gitdirs)))
+ ;; Step outside the control directory to enter the working tree.
+ ((file-name-directory (directory-file-name gitdir)))))))))
(defun magit--toplevel-safe ()
(or (magit-toplevel)
@@ -1251,15 +1245,16 @@ Sorted from longest to shortest CYGWIN name."
Git does not understand.
2. If it is a remote filename, then remove the remote part.
3. Deal with an `windows-nt' Emacs vs. Cygwin Git incompatibility."
- (if (file-name-absolute-p filename)
- (if-let ((cyg:win (cl-rassoc filename magit-cygwin-mount-points
- :test (##string-prefix-p %2 %1))))
- (concat (car cyg:win)
- (substring filename (length (cdr cyg:win))))
- (let ((expanded (expand-file-name filename)))
- (or (file-remote-p expanded 'localname)
- expanded)))
- filename))
+ (cond-let
+ ((not (file-name-absolute-p filename))
+ filename)
+ ([cyg:win (cl-rassoc filename magit-cygwin-mount-points
+ :test (##string-prefix-p %2 %1))]
+ (concat (car cyg:win)
+ (substring filename (length (cdr cyg:win)))))
+ ([expanded (expand-file-name filename)]
+ (or (file-remote-p expanded 'localname)
+ expanded))))
(defun magit-decode-git-path (path)
(if (eq (aref path 0) ?\")
@@ -1270,14 +1265,15 @@ Sorted from longest to shortest CYGWIN name."
path))
(defun magit-file-at-point (&optional expand assert)
- (if-let ((file (magit-section-case
- (file (oref it value))
- (hunk (magit-section-parent-value it)))))
- (if expand
- (expand-file-name file (magit-toplevel))
- file)
- (when assert
- (user-error "No file at point"))))
+ (cond-let
+ ([file (magit-section-case
+ (file (oref it value))
+ (hunk (magit-section-parent-value it)))]
+ (if expand
+ (expand-file-name file (magit-toplevel))
+ file))
+ (assert
+ (user-error "No file at point"))))
(defun magit-current-file ()
(or (magit-file-relative-name)
@@ -1891,11 +1887,12 @@ as into its upstream."
(magit-get-upstream-branch branch))))
(magit-rev-ancestor-p branch upstream)
t)
- (if (eq target t)
- (delete (magit-name-local-branch branch)
- (magit-list-containing-branches branch))
- (and-let ((target (or target (magit-get-current-branch))))
- (magit-rev-ancestor-p branch target)))))
+ (cond-let
+ ((eq target t)
+ (delete (magit-name-local-branch branch)
+ (magit-list-containing-branches branch)))
+ ([target (or target (magit-get-current-branch))]
+ (magit-rev-ancestor-p branch target)))))
(defun magit-get-tracked (refname)
"Return the remote branch tracked by the remote-tracking branch REFNAME.
@@ -2265,26 +2262,26 @@ If `first-parent' is set, traverse only first parents."
"\t")))
(defun magit-abbrev-length ()
- (let ((abbrev (magit-get "core.abbrev")))
- (if (and abbrev (not (equal abbrev "auto")))
- (string-to-number abbrev)
- ;; Guess the length git will be using based on an example
- ;; abbreviation. Actually HEAD's abbreviation might be an
- ;; outlier, so use the shorter of the abbreviations for two
- ;; commits. See #3034.
- (if-let* ((head (magit-rev-parse "--short" "HEAD"))
- (head-len (length head)))
- (min head-len
- (if-let ((rev (magit-rev-parse "--short" "HEAD~")))
- (length rev)
- head-len))
- ;; We're on an unborn branch, but perhaps the repository has
- ;; other commits. See #4123.
- (if-let ((commits (magit-git-lines "rev-list" "-n2" "--all"
- "--abbrev-commit")))
- (apply #'min (mapcar #'length commits))
- ;; A commit does not exist. Fall back to the default of 7.
- 7)))))
+ (cond-let*
+ ([abbrev (magit-get "core.abbrev")]
+ [_(not (equal abbrev "auto"))]
+ (string-to-number abbrev))
+ ;; Guess the length git will be using based on an example
+ ;; abbreviation. Actually HEAD's abbreviation might be an
+ ;; outlier, so use the shorter of the abbreviations for two
+ ;; commits. See #3034.
+ ([head (magit-rev-parse "--short" "HEAD")]
+ [head-len (length head)]
+ (min head-len
+ (if-let ((rev (magit-rev-parse "--short" "HEAD~")))
+ (length rev)
+ head-len)))
+ ;; We're on an unborn branch, but perhaps the repository has
+ ;; other commits. See #4123.
+ ([commits (magit-git-lines "rev-list" "-n2" "--all" "--abbrev-commit")]
+ (apply #'min (mapcar #'length commits)))
+ ;; A commit does not exist. Fall back to the default of 7.
+ (7)))
(defun magit-abbrev-arg (&optional arg)
(format "--%s=%d" (or arg "abbrev") (magit-abbrev-length)))
@@ -2432,18 +2429,18 @@ and this option only controls what face is used.")
magit-branch-local)))))
(t
(push (concat push name) combined)))))
- (when (and target (not upstream))
- (if (member target remotes)
- (progn
- (magit--add-face-text-property
- 0 (length target) 'magit-branch-upstream nil target)
- (setq upstream target)
- (setq remotes (delete target remotes)))
- (when-let ((target (car (member target combined))))
- (magit--add-face-text-property
- 0 (length target) 'magit-branch-upstream nil target)
- (setq upstream target)
- (setq combined (delete target combined))))))
+ (cond-let
+ ((or upstream (not target)))
+ ((member target remotes)
+ (magit--add-face-text-property
+ 0 (length target) 'magit-branch-upstream nil target)
+ (setq upstream target)
+ (setq remotes (delete target remotes)))
+ ([target (car (member target combined))]
+ (magit--add-face-text-property
+ 0 (length target) 'magit-branch-upstream nil target)
+ (setq upstream target)
+ (setq combined (delete target combined)))))
(string-join (flatten-tree `(,state
,head
,upstream
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index a342d7d..bf9c1b2 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -413,28 +413,20 @@ commits before and half after."
('nil magit-direct-use-buffer-arguments)
((or 'always 'selected 'current 'never)
use-buffer-args)))
- (let (args files)
- (cond
- ((and (memq use-buffer-args '(always selected current))
- (eq major-mode mode))
- (setq args magit-buffer-log-args)
- (setq files magit-buffer-log-files))
- ((when-let ((_(memq use-buffer-args '(always selected)))
- (buffer (magit-get-mode-buffer
- mode nil
- (eq use-buffer-args 'selected))))
- (setq args (buffer-local-value 'magit-buffer-log-args buffer))
- (setq files (buffer-local-value 'magit-buffer-log-files buffer))
- t))
- ((plist-member (symbol-plist mode) 'magit-log-current-arguments)
- (setq args (get mode 'magit-log-current-arguments)))
- ((when-let ((elt (assq (intern (format "magit-log:%s" mode))
- transient-values)))
- (setq args (cdr elt))
- t))
- (t
- (setq args (get mode 'magit-log-default-arguments))))
- (list args files)))
+ (cond-let
+ ((and (memq use-buffer-args '(always selected current))
+ (eq major-mode mode))
+ (list magit-buffer-log-args
+ magit-buffer-log-files))
+ ([_(memq use-buffer-args '(always selected))]
+ [buffer (magit-get-mode-buffer mode nil (eq use-buffer-args 'selected))]
+ (list (buffer-local-value 'magit-buffer-log-args buffer)
+ (buffer-local-value 'magit-buffer-log-files buffer)))
+ ((plist-member (symbol-plist mode) 'magit-log-current-arguments)
+ (list (get mode 'magit-log-current-arguments) nil))
+ ([elt (assq (intern (format "magit-log:%s" mode)) transient-values)]
+ (list (cdr elt) nil))
+ ((list (get mode 'magit-log-default-arguments) nil))))
(defun magit-log--set-value (obj &optional save)
(pcase-let* ((obj (oref obj prototype))
diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el
index 91cc55f..1c85784 100644
--- a/lisp/magit-merge.el
+++ b/lisp/magit-merge.el
@@ -172,21 +172,21 @@ then also remove the respective remote branch."
(format "Do you really want to merge `%s' into another branch? "
branch))
(user-error "Abort")))
- (if-let ((target (magit-get-push-branch branch t)))
- (progn
- (magit-git-push branch target (list "--force-with-lease"))
- (set-process-sentinel
- magit-this-process
- (lambda (process event)
- (when (memq (process-status process) '(exit signal))
- (if (not (zerop (process-exit-status process)))
- (magit-process-sentinel process event)
- (process-put process 'inhibit-refresh t)
- (magit-process-sentinel process event)
- (magit--merge-absorb-1 branch args))
- (when message
- (message message))))))
- (magit--merge-absorb-1 branch args)))
+ (cond-let
+ ([target (magit-get-push-branch branch t)]
+ (magit-git-push branch target (list "--force-with-lease"))
+ (set-process-sentinel
+ magit-this-process
+ (lambda (process event)
+ (when (memq (process-status process) '(exit signal))
+ (if (not (zerop (process-exit-status process)))
+ (magit-process-sentinel process event)
+ (process-put process 'inhibit-refresh t)
+ (magit-process-sentinel process event)
+ (magit--merge-absorb-1 branch args))
+ (when message
+ (message message))))))
+ ((magit--merge-absorb-1 branch args))))
(defun magit--merge-absorb-1 (branch args)
(if-let ((pr (magit-get "branch" branch "pullRequest")))
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 7d91192..412855f 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -445,11 +445,12 @@ Where applicable, other keymaps remap this command to another,
which actually visits the thing at point."
(declare (completion ignore))
(interactive)
- (if (eq transient-current-command 'magit-dispatch)
- (call-interactively (key-binding (this-command-keys)))
- (if-let ((url (thing-at-point 'url t)))
- (browse-url url)
- (user-error "There is no thing at point that could be visited"))))
+ (cond-let
+ ((eq transient-current-command 'magit-dispatch)
+ (call-interactively (key-binding (this-command-keys))))
+ ([url (thing-at-point 'url t)]
+ (browse-url url))
+ ((user-error "There is no thing at point that could be visited"))))
(defun magit-edit-thing ()
"This is a placeholder command, which may signal an error if called.
@@ -956,32 +957,33 @@ and another unlocked buffer already exists for that mode and
repository, then the former buffer is instead deleted and the
latter is displayed in its place."
(interactive)
- (if magit-buffer-locked-p
- (if-let ((unlocked (magit-get-mode-buffer major-mode)))
- (let ((locked (current-buffer)))
- (switch-to-buffer unlocked nil t)
- (kill-buffer locked))
- (setq magit-buffer-locked-p nil)
- (let ((name (funcall magit-generate-buffer-name-function major-mode))
- (buffer (current-buffer))
- (mode major-mode))
- (rename-buffer (generate-new-buffer-name name))
- (with-temp-buffer
- (magit--maybe-uniquify-buffer-names buffer name mode))))
- (if-let ((value (magit-buffer-value)))
- (if-let ((locked (magit-get-mode-buffer major-mode value)))
- (let ((unlocked (current-buffer)))
- (switch-to-buffer locked nil t)
- (kill-buffer unlocked))
- (setq magit-buffer-locked-p t)
- (let ((name (funcall magit-generate-buffer-name-function
- major-mode value))
- (buffer (current-buffer))
- (mode major-mode))
- (rename-buffer (generate-new-buffer-name name))
- (with-temp-buffer
- (magit--maybe-uniquify-buffer-names buffer name mode))))
- (user-error "Buffer has no value it could be locked to"))))
+ (cond-let
+ (magit-buffer-locked-p
+ (if-let ((unlocked (magit-get-mode-buffer major-mode)))
+ (let ((locked (current-buffer)))
+ (switch-to-buffer unlocked nil t)
+ (kill-buffer locked))
+ (setq magit-buffer-locked-p nil)
+ (let ((name (funcall magit-generate-buffer-name-function major-mode))
+ (buffer (current-buffer))
+ (mode major-mode))
+ (rename-buffer (generate-new-buffer-name name))
+ (with-temp-buffer
+ (magit--maybe-uniquify-buffer-names buffer name mode)))))
+ ([value (magit-buffer-value)]
+ (if-let ((locked (magit-get-mode-buffer major-mode value)))
+ (let ((unlocked (current-buffer)))
+ (switch-to-buffer locked nil t)
+ (kill-buffer unlocked))
+ (setq magit-buffer-locked-p t)
+ (let ((name (funcall magit-generate-buffer-name-function
+ major-mode value))
+ (buffer (current-buffer))
+ (mode major-mode))
+ (rename-buffer (generate-new-buffer-name name))
+ (with-temp-buffer
+ (magit--maybe-uniquify-buffer-names buffer name mode)))))
+ ((user-error "Buffer has no value it could be locked to"))))
;;; Bury Buffer
@@ -1152,17 +1154,17 @@ The arguments are for internal use."
(if window
(with-selected-window window
(magit-section-goto-successor section line char)
- (cond
- ((derived-mode-p 'magit-log-mode))
- ((or (not window-start)
- (> window-start (point))))
- ((magit-section-equal ws-section (magit-section-at window-start))
- (set-window-start window window-start t))
- ((when-let ((pos (save-excursion
- (and (magit-section-goto-successor--same
- ws-section ws-line 0)
- (point)))))
- (set-window-start window pos t)))))
+ (cond-let
+ ((derived-mode-p 'magit-log-mode))
+ ((or (not window-start)
+ (> window-start (point))))
+ ((magit-section-equal ws-section (magit-section-at window-start))
+ (set-window-start window window-start t))
+ ([pos (save-excursion
+ (and (magit-section-goto-successor--same
+ ws-section ws-line 0)
+ (point)))]
+ (set-window-start window pos t))))
;; We must make sure this does not call `set-window-start',
;; which the HUNK METHOD does by calling `magit-section-goto'
;; because that runs the `magit-section-goto-successor-hook'
@@ -1490,13 +1492,13 @@ Unless specified, REPOSITORY is the current buffer's repository."
Unless specified, REPOSITORY is the current buffer's repository.
If REPOSITORY is `all', then delete the value for KEY for all
repositories."
- (if (eq repository 'all)
- (dolist (cache magit-repository-local-cache)
- (setf cache (compat-call assoc-delete-all key cache)))
- (when-let ((cache (assoc (or repository
- (magit-repository-local-repository))
- magit-repository-local-cache)))
- (setf cache (compat-call assoc-delete-all key cache)))))
+ (cond-let
+ ((eq repository 'all)
+ (dolist (cache magit-repository-local-cache)
+ (setf cache (compat-call assoc-delete-all key cache))))
+ ([cache (assoc (or repository (magit-repository-local-repository))
+ magit-repository-local-cache)]
+ (setf cache (compat-call assoc-delete-all key cache)))))
(defmacro magit--with-repository-local-cache (key &rest body)
(declare (indent 1) (debug (form body)))
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index fe690f5..0792da6 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -356,22 +356,16 @@ Type \\[magit-reset] to reset `HEAD' to the commit at point.
(defun magit-show-refs-arguments (&optional use-buffer-args)
(unless use-buffer-args
(setq use-buffer-args magit-direct-use-buffer-arguments))
- (let (args)
- (cond
- ((eq transient-current-command 'magit-show-refs)
- (setq args (transient-args 'magit-show-refs)))
- ((eq major-mode 'magit-refs-mode)
- (setq args magit-buffer-arguments))
- ((and (memq use-buffer-args '(always selected))
- (and-let ((buffer (magit-get-mode-buffer
- 'magit-refs-mode nil
- (eq use-buffer-args 'selected))))
- (progn
- (setq args (buffer-local-value 'magit-buffer-arguments buffer))
- t))))
- (t
- (setq args (alist-get 'magit-show-refs transient-values))))
- args))
+ (cond-let*
+ ((eq transient-current-command 'magit-show-refs)
+ (transient-args 'magit-show-refs))
+ ((eq major-mode 'magit-refs-mode)
+ magit-buffer-arguments)
+ ([_(memq use-buffer-args '(always selected))]
+ [buffer (magit-get-mode-buffer 'magit-refs-mode nil
+ (eq use-buffer-args 'selected))]
+ (buffer-local-value 'magit-buffer-arguments buffer))
+ ((alist-get 'magit-show-refs transient-values))))
(transient-define-argument magit-for-each-ref:--contains ()
:description "Contains"
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 84a8a5b..d030c3c 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -678,14 +678,15 @@ then return nil."
(defun magit-menu-highlight-point-section ()
(setq magit-section-highlight-force-update t)
- (if (eq (current-buffer) magit--context-menu-buffer)
- (setq magit--context-menu-section nil)
- (if-let ((window (get-buffer-window magit--context-menu-buffer)))
- (with-selected-window window
- (setq magit--context-menu-section nil)
- (magit-section-update-highlight))
- (with-current-buffer magit--context-menu-buffer
- (setq magit--context-menu-section nil))))
+ (cond-let
+ ((eq (current-buffer) magit--context-menu-buffer)
+ (setq magit--context-menu-section nil))
+ ([window (get-buffer-window magit--context-menu-buffer)]
+ (with-selected-window window
+ (setq magit--context-menu-section nil)
+ (magit-section-update-highlight)))
+ ((with-current-buffer magit--context-menu-buffer
+ (setq magit--context-menu-section nil))))
(setq magit--context-menu-buffer nil))
(defvar magit--plural-append-es '(branch))
@@ -809,22 +810,24 @@ the beginning of the current section."
If there is no next sibling section, then move to the parent."
(interactive)
(let ((current (magit-current-section)))
- (if (oref current parent)
- (if-let ((next (car (magit-section-siblings current 'next))))
- (magit-section-goto next)
- (magit-section-forward))
- (magit-section-goto 1))))
+ (cond-let
+ ((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)))
- (if (oref current parent)
- (if-let ((previous (car (magit-section-siblings current 'prev))))
- (magit-section-goto previous)
- (magit-section-backward))
- (magit-section-goto -1))))
+ (cond-let
+ ((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'."
@@ -868,14 +871,15 @@ With a prefix argument also expand it." heading)
(cons (cons ',type ,value)
(magit-section-ident magit-root-section)))
(interactive "P")
- (if-let ((section (magit-get-section
- (cons (cons ',type ,value)
- (magit-section-ident magit-root-section)))))
- (progn (goto-char (oref section start))
- (when expand
- (with-local-quit (magit-section-show section))
- (recenter 0)))
- (message ,(format "Section \"%s\" wasn't found" heading)))))
+ (cond-let
+ ([section (magit-get-section
+ (cons (cons ',type ,value)
+ (magit-section-ident magit-root-section)))]
+ (goto-char (oref section start))
+ (when expand
+ (with-local-quit (magit-section-show section))
+ (recenter 0)))
+ ((message ,(format "Section \"%s\" wasn't found" heading))))))
;;;; Visibility
@@ -1247,11 +1251,12 @@ of course you want to be that precise."
(and-let ((parent (oref section parent)))
(magit-section-match-2 condition parent)))
(and (let ((c (car condition)))
- (if (class-p c)
- (cl-typep section c)
- (if-let ((class (cdr (assq c magit--section-type-alist))))
- (cl-typep section class)
- (eq (oref section type) c))))
+ (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))))
(or (not (setq condition (cdr condition)))
(and-let ((parent (oref section parent)))
(magit-section-match-2 condition parent))))))
diff --git a/lisp/magit-submodule.el b/lisp/magit-submodule.el
index 589e81b..0c0a4d6 100644
--- a/lisp/magit-submodule.el
+++ b/lisp/magit-submodule.el
@@ -498,13 +498,14 @@ or, failing that, the abbreviated HEAD commit hash."
(if-let ((branch (magit-get-current-branch)))
(propertize branch 'font-lock-face 'magit-branch-local)
(propertize "(detached)" 'font-lock-face 'warning))))
- (if-let ((desc (magit-git-string "describe" "--tags")))
- (progn (when (and magit-modules-overview-align-numbers
- (string-match-p "\\`[0-9]" desc))
- (insert ?\s))
- (insert (propertize desc 'font-lock-face 'magit-tag)))
- (when-let ((abbrev (magit-rev-format "%h")))
- (insert (propertize abbrev 'font-lock-face 'magit-hash)))))
+ (cond-let
+ ([desc (magit-git-string "describe" "--tags")]
+ (when (and magit-modules-overview-align-numbers
+ (string-match-p "\\`[0-9]" desc))
+ (insert ?\s))
+ (insert (propertize desc 'font-lock-face 'magit-tag)))
+ ([abbrev (magit-rev-format "%h")]
+ (insert (propertize abbrev 'font-lock-face 'magit-hash)))))
(insert ?\n))))))
(insert ?\n))
diff --git a/lisp/magit-transient.el b/lisp/magit-transient.el
index 8d5ecd6..8fa9d5c 100644
--- a/lisp/magit-transient.el
+++ b/lisp/magit-transient.el
@@ -93,18 +93,19 @@
(let ((choices (oref obj choices)))
(when (functionp choices)
(setq choices (funcall choices)))
- (if current-prefix-arg
- (pcase-let*
- ((`(,fallback . ,choices)
- (magit--git-variable-list-choices obj))
- (choice (magit-completing-read
- (format "Set `%s' to" (oref obj variable))
- (if fallback (nconc choices (list fallback)) choices)
- nil t)))
- (if (equal choice fallback) nil choice))
- (if-let ((value (oref obj value)))
- (cadr (member value choices))
- (car choices)))))
+ (cond-let
+ (current-prefix-arg
+ (pcase-let*
+ ((`(,fallback . ,choices)
+ (magit--git-variable-list-choices obj))
+ (choice (magit-completing-read
+ (format "Set `%s' to" (oref obj variable))
+ (if fallback (nconc choices (list fallback)) choices)
+ nil t)))
+ (if (equal choice fallback) nil choice)))
+ ([value (oref obj value)]
+ (cadr (member value choices)))
+ ((car choices)))))
;;;; Readers
@@ -155,20 +156,21 @@
(oref obj variable)))
(cl-defmethod transient-format-value ((obj magit--git-variable))
- (if-let ((value (oref obj value)))
- (if (oref obj multi-value)
- (if (cdr value)
- (mapconcat (##concat "\n "
- (propertize % 'face 'transient-value))
- value "")
- (propertize (car value) 'face 'transient-value))
- (propertize (car (split-string value "\n"))
- 'face 'transient-value))
- (if-let* ((default (oref obj default))
- (default (if (functionp default) (funcall default) default)))
- (concat (propertize "default:" 'face 'transient-inactive-value)
- (propertize default 'face 'transient-value))
- (propertize "unset" 'face 'transient-inactive-value))))
+ (cond-let*
+ ([value (oref obj value)]
+ (if (oref obj multi-value)
+ (if (cdr value)
+ (mapconcat (##concat "\n "
+ (propertize % 'face 'transient-value))
+ value "")
+ (propertize (car value) 'face 'transient-value))
+ (propertize (car (split-string value "\n"))
+ 'face 'transient-value)))
+ ([default (oref obj default)]
+ [default (if (functionp default) (funcall default) default)]
+ (concat (propertize "default:" 'face 'transient-inactive-value)
+ (propertize default 'face 'transient-value)))
+ ((propertize "unset" 'face 'transient-inactive-value))))
(cl-defmethod transient-format-value ((obj magit--git-variable:choices))
(pcase-let ((`(,fallback . ,choices) (magit--git-variable-list-choices obj)))
diff --git a/lisp/magit-wip.el b/lisp/magit-wip.el
index 8cccc51..eb9e0fc 100644
--- a/lisp/magit-wip.el
+++ b/lisp/magit-wip.el
@@ -117,30 +117,33 @@ variant `magit-wip-after-save-mode'."
(remove-hook 'after-save-hook #'magit-wip-commit-buffer-file t)))
(defun magit-wip-after-save-local-mode-turn-on ()
- (when (and buffer-file-name
- (if magit--wip-activation-cache
- (if-let ((elt (assoc default-directory
- magit--wip-activation-cache)))
- (and-let ((top (cadr elt)))
- (member (file-relative-name buffer-file-name top)
- (cddr elt)))
- (if-let ((top (magit-toplevel)))
- (let (files)
- (if-let ((elt (assoc top magit--wip-activation-cache)))
- (setq files (cddr elt))
- (setq files (let ((default-directory top))
- (magit-tracked-files)))
- (push `(,top ,top ,@files)
- magit--wip-activation-cache)
- (unless (eq default-directory top)
- (push `(,default-directory ,top ,@files)
- magit--wip-activation-cache)))
- (member (file-relative-name buffer-file-name) files))
- (push (list default-directory nil)
- magit--wip-activation-cache)
- nil))
- (and (magit-inside-worktree-p t)
- (magit-file-tracked-p buffer-file-name))))
+ (when (cond-let
+ ((not buffer-file-name)
+ nil)
+ ((not magit--wip-activation-cache)
+ (and (magit-inside-worktree-p t)
+ (magit-file-tracked-p buffer-file-name)))
+ ([elt (assoc default-directory
+ magit--wip-activation-cache)]
+ (and-let ((top (cadr elt)))
+ (member (file-relative-name buffer-file-name top)
+ (cddr elt))))
+ ([top (magit-toplevel)]
+ (let (files)
+ (if-let ((elt (assoc top magit--wip-activation-cache)))
+ (setq files (cddr elt))
+ (setq files (let ((default-directory top))
+ (magit-tracked-files)))
+ (push `(,top ,top ,@files)
+ magit--wip-activation-cache)
+ (unless (eq default-directory top)
+ (push `(,default-directory ,top ,@files)
+ magit--wip-activation-cache)))
+ (member (file-relative-name buffer-file-name) files)))
+ (t
+ (push (list default-directory nil)
+ magit--wip-activation-cache)
+ nil))
(magit-wip-after-save-local-mode)))
;;;###autoload
@@ -438,23 +441,23 @@ many \"branches\" of each wip ref are shown."
(defun magit-wip-purge ()
"Ask to delete all wip-refs that no longer have a corresponding ref."
(interactive)
- (if-let ((wiprefs (thread-last
- (cl-set-difference (magit-list-refs "refs/wip/")
- (magit-list-refs)
- :test (##equal (substring %1 15) %2))
- (delete "refs/wip/index/HEAD")
- (delete "refs/wip/wtree/HEAD"))))
- (progn
- (magit-confirm 'purge-dangling-wiprefs
- "Delete wip-ref %s without corresponding ref"
- "Delete %d wip-refs without corresponding ref"
- nil wiprefs)
- (message "Deleting wip-refs...")
- (dolist (wipref wiprefs)
- (magit-call-git "update-ref" "-d" wipref))
- (message "Deleting wip-refs...done")
- (magit-refresh))
- (message "All wip-refs have a corresponding ref")))
+ (cond-let
+ ([wiprefs (thread-last
+ (cl-set-difference (magit-list-refs "refs/wip/")
+ (magit-list-refs)
+ :test (##equal (substring %1 15) %2))
+ (delete "refs/wip/index/HEAD")
+ (delete "refs/wip/wtree/HEAD"))]
+ (magit-confirm 'purge-dangling-wiprefs
+ "Delete wip-ref %s without corresponding ref"
+ "Delete %d wip-refs without corresponding ref"
+ nil wiprefs)
+ (message "Deleting wip-refs...")
+ (dolist (wipref wiprefs)
+ (magit-call-git "update-ref" "-d" wipref))
+ (message "Deleting wip-refs...done")
+ (magit-refresh))
+ ((message "All wip-refs have a corresponding ref"))))
;;; _
(provide 'magit-wip)