branch: elpa/magit commit 67a662022eb5e00ad0c281255c308ab5fce28985 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Avoid t condition in final match-all cond clause If there is a single BODY form in the final clause, we can just use that as the CONDITION instead (because the value of that is returned if the BODY is empty). I've been gravitating towards that style for a long time, but because I realize that this is not without issue and that there are certainly those that would find this practice questionable, I refrained from updating existing code until now. The main problem with dropping the `t' is that it is not always immediately obvious if one is looking at (cond ... ((foo bar))) or (cond ... ((foo) (bar))) That's why I still use `t' when the single BODY form is too long and/or complex, despite fitting on one line. In this case from `magit-log-move-to-revision', for example, I was on the fence: (cond ... ((apply #'magit-log-all-branches (magit-log-arguments)))) (It's worth noting that the same issue also occurs when reading non-final-catch-all clauses.) On the other hand, the single BODY form can also be complex *enough* to allow using it as the CONDITION, without that being hard to parse. E.g., when it spans multiple lines, and indentation keeps increasing, and/or when BODY is a `let' from or similar. Used like this, `cond' becomes more similar to `or' in certain situations, but even then they still behave differently, consider: (or (and CONDITION maybe-nil) ...) vs (cond (CONDITION maybe-nil) ...) --- lisp/magit-apply.el | 3 +-- lisp/magit-base.el | 5 ++--- lisp/magit-branch.el | 6 ++---- lisp/magit-diff.el | 24 ++++++++++-------------- lisp/magit-ediff.el | 3 +-- lisp/magit-fetch.el | 3 +-- lisp/magit-files.el | 3 +-- lisp/magit-git.el | 5 ++--- lisp/magit-log.el | 3 +-- lisp/magit-margin.el | 2 +- lisp/magit-merge.el | 3 +-- lisp/magit-mode.el | 6 ++---- lisp/magit-process.el | 6 ++---- lisp/magit-pull.el | 17 +++++++---------- lisp/magit-push.el | 6 ++---- lisp/magit-refs.el | 4 ++-- lisp/magit-repos.el | 4 ++-- lisp/magit-section.el | 7 +++---- lisp/magit-sequence.el | 19 +++++++------------ lisp/magit-stash.el | 2 +- lisp/magit-status.el | 3 +-- lisp/magit-transient.el | 6 ++---- 22 files changed, 54 insertions(+), 86 deletions(-) diff --git a/lisp/magit-apply.el b/lisp/magit-apply.el index fff23de8ef4..8f7623c8127 100644 --- a/lisp/magit-apply.el +++ b/lisp/magit-apply.el @@ -733,8 +733,7 @@ so causes the change to be applied to the index as well." magit-buffer-range) ((derived-mode-p 'magit-diff-mode) magit-buffer-range) - (t - "--cached"))))) + ("--cached"))))) (magit--separate (##member (oref % value) bs) sections)))) (magit-confirm-files 'reverse (mapcar (##oref % value) sections)) diff --git a/lisp/magit-base.el b/lisp/magit-base.el index 85907f76808..c82dd09b823 100644 --- a/lisp/magit-base.el +++ b/lisp/magit-base.el @@ -766,7 +766,7 @@ This is similar to `read-string', but (user-error "Need non-empty input")) ((and no-whitespace (string-match-p "[\s\t\n]" val)) (user-error "Input contains whitespace")) - (t val)))) + (val)))) (defun magit-read-string-ns ( prompt &optional initial-input history default-value inherit-input-method) @@ -985,8 +985,7 @@ Pad the left side of STRING so that it aligns with the text area." ;; Delete the percent sign. (delete-region (1- (match-beginning 0)) (match-beginning 0))))) ;; Signal an error on bogus format strings. - (t - (error "Invalid format string")))) + ((error "Invalid format string")))) (buffer-string))) ;;; Missing from Emacs diff --git a/lisp/magit-branch.el b/lisp/magit-branch.el index 064e93839e5..9455cebd7f4 100644 --- a/lisp/magit-branch.el +++ b/lisp/magit-branch.el @@ -374,8 +374,7 @@ when using `magit-branch-and-checkout'." choice)) ((member choice local) (list choice)) - (t - (list choice (magit-read-starting-point "Create" choice)))))) + ((list choice (magit-read-starting-point "Create" choice)))))) (cond ((not start-point) (magit--checkout branch (magit-branch-arguments)) @@ -619,8 +618,7 @@ prompt is confusing." (format "%s is" (seq-find #'magit-ref-ambiguous-p branches))) ((= len (length refs)) (format "These %s names are" len)) - (t - (format "%s of these names are" len)))))) + ((format "%s of these names are" len)))))) (cond ((string-match "^refs/remotes/\\([^/]+\\)" (car refs)) (let* ((remote (match-str 1 (car refs))) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index 699d23f7a2c..11b770676fe 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -1215,7 +1215,7 @@ If no DWIM context is found, nil is returned." (defun magit-diff--range-to-endpoints (range) (cond ((string-match "\\.\\.\\." range) (replace-match ".." nil nil range)) ((string-match "\\.\\." range) (replace-match "..." nil nil range)) - (t range))) + (range))) (defun magit-diff--region-range (&optional interactive mbase) (and-let* ((commits (magit-region-values '(commit branch) t)) @@ -1504,8 +1504,7 @@ instead." (message "No revision buffer"))) ((local-variable-p 'magit-buffer-diff-files) (toggle)) - (t - (user-error "Cannot toggle file filter in this buffer"))))) + ((user-error "Cannot toggle file filter in this buffer"))))) (defun magit-diff-less-context (&optional count) "Decrease the context for diff hunks by COUNT lines." @@ -1881,8 +1880,7 @@ commit or stash at point, then prompt for a commit." (setq rev target) (setq cmd #'magit-show-commit) (setq buf (magit-get-mode-buffer 'magit-revision-mode))))) - (t - (magit-section-case + ((magit-section-case (branch (setq rev (magit-ref-maybe-qualify (oref it value))) (setq cmd #'magit-show-commit) @@ -1947,8 +1945,7 @@ commit or stash at point, then prompt for a commit." (mapc #'magit-section-show-headings sections)) ((seq-some #'magit-section-hidden-body children) (mapc #'magit-section-show-children sections)) - (t - (mapc #'magit-section-hide sections))))))) + ((mapc #'magit-section-hide sections))))))) ;;;; Jump Commands @@ -2071,7 +2068,7 @@ Staging and applying changes is documented in info node ((and (magit-repository-local-get 'this-commit-command) (not (magit-anything-staged-p))) "Uncommitting changes") - (t "Unstaged changes"))) + ("Unstaged changes"))) (pcase (length magit-buffer-diff-files) (0) (1 (concat " in file " (car magit-buffer-diff-files))) @@ -2087,8 +2084,7 @@ Staging and applying changes is documented in info node (delq nil (list magit-buffer-range magit-buffer-typearg))) ((equal magit-buffer-typearg "--cached") (list 'staged)) - (t - (list 'unstaged magit-buffer-typearg))) + ((list 'unstaged magit-buffer-typearg))) (and magit-buffer-diff-files (cons "--" magit-buffer-diff-files)))) (cl-defmethod magit-menu-common-value ((_section magit-diff-section)) @@ -2562,7 +2558,7 @@ function errors." " (" (cond (rewind "rewind") ((string-search "..." range) "non-ff") - (t "new commits")) + ("new commits")) (and (or modified untracked) (concat ", " (and modified "modified") @@ -3074,7 +3070,7 @@ It the SECTION has a different type, then do nothing." (forward-line -1) (regexp-quote (buffer-substring-no-properties beg (line-end-position)))) - (t t)))))))) + (t)))))))) (cl-defmethod magit-section-goto-successor ((section magit-hunk-section) line char &optional arg) @@ -3189,7 +3185,7 @@ Do not confuse this with `magit-diff-scope' (which see)." (if (magit-rev-head-p range) 'staged 'undefined)) ; i.e., committed and staged - (t 'committed)))) + ('committed)))) ((derived-mode-p 'magit-status-mode) (let ((stype (oref section type))) (if (memq stype '(staged unstaged tracked untracked)) @@ -3211,7 +3207,7 @@ Do not confuse this with `magit-diff-scope' (which see)." (magit-section-match [* file commit] section)) 'committed 'undefined)) - (t 'undefined)))) + ('undefined)))) (cl-defun magit-diff-scope (&optional (section nil ssection) strict) "Return the diff scope of SECTION or the selected section(s). diff --git a/lisp/magit-ediff.el b/lisp/magit-ediff.el index cddcc7f041d..54acf4561de 100644 --- a/lisp/magit-ediff.el +++ b/lisp/magit-ediff.el @@ -488,8 +488,7 @@ mind at all, then it asks the user for a command to run." (magit-ediff-show-stash revB)) (file (funcall command file)) - (t - (call-interactively command))))))) + ((call-interactively command))))))) ;;;###autoload (defun magit-ediff-show-staged (file) diff --git a/lisp/magit-fetch.el b/lisp/magit-fetch.el index 530b662fe53..4a38da728ba 100644 --- a/lisp/magit-fetch.el +++ b/lisp/magit-fetch.el @@ -84,8 +84,7 @@ push-remote." ((member remote (magit-list-remotes)) remote) (remote (format "%s, replacing invalid" v)) - (t - (format "%s, setting that" v))))) + ((format "%s, setting that" v))))) ;;;###autoload (autoload 'magit-fetch-from-upstream "magit-fetch" nil t) (transient-define-suffix magit-fetch-from-upstream (remote args) diff --git a/lisp/magit-files.el b/lisp/magit-files.el index 258c28fd6d5..67b88005779 100644 --- a/lisp/magit-files.el +++ b/lisp/magit-files.el @@ -94,8 +94,7 @@ the line and column corresponding to that location." (magit-buffer-revision (setq line (magit-diff-visit--offset file (concat magit-buffer-revision ".." rev) line))) - (t - (setq line (magit-diff-visit--offset file (list "-R" rev) line))))) + ((setq line (magit-diff-visit--offset file (list "-R" rev) line))))) (funcall fn buf) (when line (with-current-buffer buf diff --git a/lisp/magit-git.el b/lisp/magit-git.el index b35431b6717..10296b52ed4 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -697,7 +697,7 @@ values of `magit-remote-git-executable' and `exec-path'.\n")) ((save-match-data (and (string-match magit--git-version-regexp output) (match-str 1 output)))) - (t output))))) + (output))))) (defun magit-debug-git-executable () "Display a buffer with information about `magit-git-executable'. @@ -2424,8 +2424,7 @@ and this option only controls what face is used.") (magit--propertize-face name '(magit-branch-upstream magit-branch-local))))) - (t - (push (concat push name) combined))))) + ((push (concat push name) combined))))) (cond-let ((or upstream (not target))) ((member target remotes) diff --git a/lisp/magit-log.el b/lisp/magit-log.el index 96f34be4f0d..20a162ad7e9 100644 --- a/lisp/magit-log.el +++ b/lisp/magit-log.el @@ -962,8 +962,7 @@ of the current repository first; creating it if necessary." (current-buffer)) ((and$ (magit-get-mode-buffer 'magit-log-mode) (pop-to-buffer-same-window $))) - (t - (apply #'magit-log-all-branches (magit-log-arguments)))) + ((apply #'magit-log-all-branches (magit-log-arguments)))) (unless (magit-log-goto-commit-section (magit-rev-abbrev commit)) (user-error "%s isn't visible in the current log buffer" commit)))) diff --git a/lisp/magit-margin.el b/lisp/magit-margin.el index 1426aee685c..5917d92c7c0 100644 --- a/lisp/magit-margin.el +++ b/lisp/magit-margin.el @@ -240,7 +240,7 @@ English.") (>= (/ age weight) 1)) (list cnt (cond (abbreviate char) ((= cnt 1) unit) - (t units))) + (units))) (fn age (cdr spec))))))) (fn (abs (- (float-time) (if (stringp date) diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el index 1c85784b96f..ae5a82038f5 100644 --- a/lisp/magit-merge.el +++ b/lisp/magit-merge.el @@ -248,8 +248,7 @@ then also remove the respective remote branch." (list file (magit-checkout-read-stage file))) ((yes-or-no-p (format "Restore conflicts in %s? " file)) (list file "--merge")) - (t - (user-error "Quit"))))) + ((user-error "Quit"))))) (pcase (cons arg (cddr (car (magit-file-status file)))) ((or `("--ours" ?D ,_) '("--ours" ?U ?A) diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el index 92b469cb828..f52fb17454c 100644 --- a/lisp/magit-mode.el +++ b/lisp/magit-mode.el @@ -790,8 +790,7 @@ split is made vertically or horizontally is determined by ((with-current-buffer buffer (derived-mode-p 'magit-diff-mode 'magit-process-mode)) '(magit--display-buffer-topleft)) - (t - '(display-buffer-same-window))))) + ('(display-buffer-same-window))))) (defun magit--display-buffer-fullcolumn (buffer alist) (when-let ((window (or (display-buffer-reuse-window buffer alist) @@ -822,8 +821,7 @@ the mode of the current buffer derives from `magit-log-mode' or ((with-current-buffer buffer (derived-mode-p 'magit-process-mode)) nil) - (t - '(magit--display-buffer-fullcolumn))))) + ('(magit--display-buffer-fullcolumn))))) (defun magit-maybe-set-dedicated () "Mark the selected window as dedicated if appropriate. diff --git a/lisp/magit-process.el b/lisp/magit-process.el index 6f3d2bc06e8..a126233f68a 100644 --- a/lisp/magit-process.el +++ b/lisp/magit-process.el @@ -810,8 +810,7 @@ Magit status buffer." ((and args (equal program shell-file-name)) (propertize (cadr args) 'font-lock-face 'magit-section-heading)) - (t - (concat (propertize (file-name-nondirectory program) + ((concat (propertize (file-name-nondirectory program) 'font-lock-face 'magit-section-heading) " " (propertize (mapconcat #'shell-quote-argument args " ") @@ -832,8 +831,7 @@ Magit status buffer." (delete-region (oref section start) (1+ (oref section end))) (cl-decf count)) - (t - (push section head)))) + ((push section head)))) (pop tail)) (oset magit-root-section children (nconc (reverse head) tail))))) diff --git a/lisp/magit-pull.el b/lisp/magit-pull.el index 3cd4dc5effe..17401cd7321 100644 --- a/lisp/magit-pull.el +++ b/lisp/magit-pull.el @@ -99,14 +99,12 @@ push-remote." (target (magit-get-push-branch branch t)) (remote (magit-get-push-remote branch)) (v (magit--push-remote-variable branch t))) - (cond - (target) - ((member remote (magit-list-remotes)) - (format "%s, replacing non-existent" v)) - (remote - (format "%s, replacing invalid" v)) - (t - (format "%s, setting that" v))))) + (cond (target) + ((member remote (magit-list-remotes)) + (format "%s, replacing non-existent" v)) + (remote + (format "%s, replacing invalid" v)) + ((format "%s, setting that" v))))) ;;;###autoload (autoload 'magit-pull-from-upstream "magit-pull" nil t) (transient-define-suffix magit-pull-from-upstream (args) @@ -148,8 +146,7 @@ the upstream." (concat u ", replacing non-existent")) ((or remote merge) (concat u ", replacing invalid")) - (t - (concat u ", setting that"))))))) + ((concat u ", setting that"))))))) ;;;###autoload (defun magit-pull-branch (source args) diff --git a/lisp/magit-push.el b/lisp/magit-push.el index c64acb511eb..f603250b052 100644 --- a/lisp/magit-push.el +++ b/lisp/magit-push.el @@ -107,8 +107,7 @@ argument the push-remote can be changed before pushed to it." 'magit-branch-remote))) (remote (format "%s, replacing invalid" v)) - (t - (format "%s, setting that" v))))) + ((format "%s, setting that" v))))) ;;;###autoload (autoload 'magit-push-current-to-upstream "magit-push" nil t) (transient-define-suffix magit-push-current-to-upstream (args) @@ -171,8 +170,7 @@ the upstream." (magit--propertize-face merge 'magit-branch-remote))) ((or remote merge) (concat u ", creating it and replacing invalid")) - (t - (concat u ", creating it"))))))) + ((concat u ", creating it"))))))) ;;;###autoload (defun magit-push-current (target args) diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el index c72e282831c..43a437b4f11 100644 --- a/lisp/magit-refs.el +++ b/lisp/magit-refs.el @@ -769,9 +769,9 @@ line is inserted at all." (magit--propertize-face (cond ((> ahead 0) (concat "<" (number-to-string ahead))) ((> behind 0) (concat (number-to-string behind) ">")) - (t "=")) + ("=")) 'magit-dimmed))) - (t ""))))) + (""))))) (defun magit-refs--propertize-branch (branch ref &optional head-face) (let ((face (cdr (cl-find-if (pcase-lambda (`(,re . ,_)) diff --git a/lisp/magit-repos.el b/lisp/magit-repos.el index e6147a13de1..874e6db4bc3 100644 --- a/lisp/magit-repos.el +++ b/lisp/magit-repos.el @@ -310,7 +310,7 @@ If it contains \"%s\" then the directory is substituted for that." sort-fn #'identity idx)) (sort-fn sort-fn) (sort-set nil) - (t t))) + (t))) (flatten-tree props)))) magit-repolist-columns)))) @@ -403,7 +403,7 @@ Usually this is just its basename." (setq b (and (string-match re b) (match-str 0 b))) (cond ((and a b) (version< a b)) (b nil) - (t t))))) + (t))))) (defun magit-repolist-column-branch (_) "Insert the current branch." diff --git a/lisp/magit-section.el b/lisp/magit-section.el index dd753dcedf7..f9867d27981 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -1138,8 +1138,7 @@ or when INTERACTIVE is non-nil, show the section in the echo area." ((and (eieio-object-p val) (fboundp 'cl-prin1-to-string)) (cl-prin1-to-string val)) - (t - val))) + (val))) (if ident (magit-section-ident section) (apply #'vector (magit-section-lineage section))) @@ -2316,7 +2315,7 @@ Configuration'." (message " %-50s %f %s" entry time (cond ((> time 0.03) "!!") ((> time 0.01) "!") - (t "")))) + ("")))) (apply entry args))))))) (cl-defun magit--overlay-at (pos prop &optional (val nil sval) testfn) @@ -2453,7 +2452,7 @@ This is like moving to POS and then calling `pos-eol'." (oref section value))) ((string-match " ([0-9]+)\\'" heading) (substring heading 0 (match-beginning 0))) - (t heading))))) + (heading))))) (defun magit--imenu-goto-function (_name position &rest _rest) "Go to the section at POSITION. diff --git a/lisp/magit-sequence.el b/lisp/magit-sequence.el index 119593558a7..ecdaa06967b 100644 --- a/lisp/magit-sequence.el +++ b/lisp/magit-sequence.el @@ -349,8 +349,7 @@ the process manually." command)) ((seq-find (##string-prefix-p "--mainline=" %) args) args) - (t - (cons (format "--mainline=%s" + ((cons (format "--mainline=%s" (read-number "Replay merges relative to parent: ")) args)))) commits))) @@ -632,8 +631,7 @@ the upstream." (concat u ", replacing non-existent")) ((or remote merge) (concat u ", replacing invalid")) - (t - (concat u ", setting that"))))))) + ((concat u ", setting that"))))))) ;;;###autoload (defun magit-rebase-branch (target args) @@ -940,8 +938,7 @@ If no such sequence is in progress, do nothing." (commit (magit-sequence-insert-commit "pick" commit 'magit-sequence-pick)) - (t - (magit-sequence-insert-am-patch + ((magit-sequence-insert-am-patch "pick" patch 'magit-sequence-pick))) (cl-decf i))) (magit-sequence-insert-sequence nil "ORIG_HEAD") @@ -1087,15 +1084,14 @@ status buffer (i.e., the reverse of how they will be applied)." (equal (magit-patch-id unstaged) id)) "same") ;; ...and some changes are gone and/or others were added. - (t "work"))) + ("work"))) stop 'magit-sequence-part)) ;; The commit is definitely gone... ((assoc (##magit-rev-equal % stop) done) ;; ...but all of its changes are still in effect. (magit-sequence-insert-commit "poof" stop 'magit-sequence-drop)) - (t - ;; ...and some changes are gone and/or other changes were added. - (magit-sequence-insert-commit "gone" stop 'magit-sequence-drop))) + ;; ...and some changes are gone and/or other changes were added. + ((magit-sequence-insert-commit "gone" stop 'magit-sequence-drop))) (setq stop nil)))) (pcase-dolist (`(,rev ,abbrev ,msg) done) (apply #'magit-sequence-insert-commit @@ -1113,8 +1109,7 @@ status buffer (i.e., the reverse of how they will be applied)." abbrev msg)) ((equal rev head) (list "done" rev 'magit-sequence-head abbrev msg)) - (t - (list "done" rev 'magit-sequence-done abbrev msg))))) + ((list "done" rev 'magit-sequence-done abbrev msg))))) (magit-sequence-insert-commit "onto" onto (if (equal onto head) 'magit-sequence-head diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el index 1449a128db4..456cb624713 100644 --- a/lisp/magit-stash.el +++ b/lisp/magit-stash.el @@ -448,7 +448,7 @@ Then apply STASH, dropping it if it applies cleanly." (unless noerror (user-error "No %s changes to save" (cond ((not index) "unstaged") ((not worktree) "staged") - (t "local")))))) + ("local")))))) (defun magit-stash-store (message ref rev) (magit-update-ref ref message rev)) diff --git a/lisp/magit-status.el b/lisp/magit-status.el index d499b0da798..feb2fac0983 100644 --- a/lisp/magit-status.el +++ b/lisp/magit-status.el @@ -645,8 +645,7 @@ arguments are for internal use only." (propertize "does not exist on" 'font-lock-face 'magit-branch-warning) (propertize remote 'font-lock-face 'magit-branch-remote)))) - (t - (propertize "invalid upstream configuration" + ((propertize "invalid upstream configuration" 'font-lock-face 'magit-branch-warning))))) (insert ?\n)))))) diff --git a/lisp/magit-transient.el b/lisp/magit-transient.el index 7a111d6be7b..7cafc54b365 100644 --- a/lisp/magit-transient.el +++ b/lisp/magit-transient.el @@ -68,8 +68,7 @@ (oset obj value (cond ((oref obj multi-value) (magit-get-all arg variable)) - (t - (magit-get arg variable)))))) + ((magit-get arg variable)))))) (cl-defmethod transient-init-value ((obj magit--git-variable:boolean)) (let ((variable (format (oref obj variable) @@ -206,8 +205,7 @@ 'transient-inactive-value) ((member global choices) 'transient-value) - (t - 'font-lock-warning-face)))) + ('font-lock-warning-face)))) (fallback (propertize fallback 'face (if value