Commit b9e484b3 authored by Jonas Bernoulli's avatar Jonas Bernoulli

Use if-let instead of -if-let

parent 18d2d81e
......@@ -659,8 +659,8 @@ modes is toggled, then this mode also gets toggled automatically.
(?A . ,(p2 "author-time" "author-tz" 'magit-blame-date))
(?C . ,(p2 "committer-time" "committer-tz" 'magit-blame-date))
(?f . "")))))))
(-if-let (width (and (string-suffix-p "%f" format)
(magit-blame--style-get 'margin-width)))
(if-let (width (and (string-suffix-p "%f" format)
(magit-blame--style-get 'margin-width)))
(concat str
(propertize (make-string (max 0 (- width (length str))) ?\s)
'face face))
......@@ -694,10 +694,10 @@ modes is toggled, then this mode also gets toggled automatically.
(defun magit-blame-maybe-show-message ()
(when (magit-blame--style-get 'show-message)
(let ((message-log-max 0))
(-if-let (msg (cdr (assq 'heading
(gethash (oref (magit-current-blame-chunk)
orig-rev)
magit-blame-cache))))
(if-let (msg (cdr (assq 'heading
(gethash (oref (magit-current-blame-chunk)
orig-rev)
magit-blame-cache))))
(progn (setq msg (substring msg 0 -1))
(set-text-properties 0 (length msg) nil msg)
(message msg))
......@@ -757,7 +757,7 @@ not turn on `read-only-mode'."
(magit--not-inside-repository-error))
(if (and magit-blame-mode
(eq type magit-blame-type))
(-if-let (chunk (magit-current-blame-chunk))
(if-let (chunk (magit-current-blame-chunk))
(unless (oref chunk prev-rev)
(user-error "Chunk has no further history"))
(user-error "Commit data not available yet. Still blaming."))
......@@ -827,7 +827,7 @@ then also kill the buffer."
(defun magit-blame-next-chunk-same-commit (&optional previous)
"Move to the next chunk from the same commit.\n\n(fn)"
(interactive)
(-if-let (rev (oref (magit-current-blame-chunk) orig-rev))
(if-let (rev (oref (magit-current-blame-chunk) orig-rev))
(let ((pos (point)) ov)
(save-excursion
(while (and (not ov)
......
......@@ -494,7 +494,7 @@ from the source branch's upstream, then an error is raised."
(magit-branch-arguments)))
(when (magit-branch-p branch)
(user-error "Cannot spin off %s. It already exists" branch))
(-if-let (current (magit-get-current-branch))
(if-let (current (magit-get-current-branch))
(let ((tracked (magit-get-upstream-branch current))
base)
(when from
......@@ -680,7 +680,7 @@ defaulting to the branch at point."
(when (memq (process-status process) '(exit signal))
(if (= (process-exit-status process) 0)
(magit-process-sentinel process event)
(-if-let (rest (-filter #'magit-ref-exists-p refs))
(if-let (rest (-filter #'magit-ref-exists-p refs))
(progn
(process-put process 'inhibit-refresh t)
(magit-process-sentinel process event)
......@@ -882,7 +882,7 @@ variable `branch.<name>.description'."
(width (+ (length branch) 19))
(var (format "branch.%s.description" branch)))
(concat var " " (make-string (- width (length var)) ?\s)
(-if-let (value (magit-get var))
(if-let (value (magit-get var))
(propertize (car (split-string value "\n"))
'face 'magit-popup-option-value)
(propertize "unset" 'face 'magit-popup-disabled-argument)))))
......@@ -926,11 +926,11 @@ already set. When nil, then always unset."
'magit-branch-local
'magit-branch-remote)))
(concat varM (make-string (- width (length varM)) ?\s)
(-if-let (value (magit-get varM))
(if-let (value (magit-get varM))
(propertize value 'face face)
(propertize "unset" 'face 'magit-popup-disabled-argument))
"\n " varR (make-string (- width (length varR)) ?\s)
(-if-let (value (magit-get varR))
(if-let (value (magit-get varR))
(propertize value 'face face)
(propertize "unset" 'face 'magit-popup-disabled-argument)))))
......
......@@ -385,15 +385,15 @@ history element."
(magit-display-buffer-noselect t)
(inhibit-quit nil))
(message "Diffing changes to be committed (C-g to abort diffing)")
(-if-let (fn (cl-case last-command
(magit-commit
(apply-partially 'magit-diff-staged nil))
(magit-commit-all
(apply-partially 'magit-diff-working-tree nil))
((magit-commit-amend
magit-commit-reword
magit-rebase-reword-commit)
'magit-diff-while-amending)))
(if-let (fn (cl-case last-command
(magit-commit
(apply-partially 'magit-diff-staged nil))
(magit-commit-all
(apply-partially 'magit-diff-working-tree nil))
((magit-commit-amend
magit-commit-reword
magit-rebase-reword-commit)
'magit-diff-while-amending)))
(funcall fn args)
(if (magit-anything-staged-p)
(magit-diff-staged nil args)
......
......@@ -719,10 +719,10 @@ This is a variant of `magit-diff-popup' which shows the same popup
but which limits the diff to the file being visited in the current
buffer."
(interactive)
(-if-let (file (magit-file-relative-name))
(if-let (file (magit-file-relative-name))
(let ((magit-diff-arguments
(magit-popup-import-file-args
(-if-let (buffer (magit-mode-get-buffer 'magit-diff-mode))
(if-let (buffer (magit-mode-get-buffer 'magit-diff-mode))
(with-current-buffer buffer
(nth 3 magit-refresh-args))
(default-value 'magit-diff-arguments))
......@@ -965,7 +965,7 @@ be committed."
"Show diff for the blob or file visited in the current buffer."
(interactive)
(require 'magit)
(-if-let (file (magit-file-relative-name))
(if-let (file (magit-file-relative-name))
(magit-mode-setup-internal #'magit-diff-mode
(list (or magit-buffer-refname
(magit-get-current-branch)
......
......@@ -126,7 +126,7 @@ like pretty much every other keymap:
With a prefix argument, visit in another window. If there
is no file at point, then instead visit `default-directory'."
(interactive "P")
(dired-jump other-window (-if-let (file (magit-file-at-point))
(dired-jump other-window (if-let (file (magit-file-at-point))
(progn (setq file (expand-file-name file))
(if (file-directory-p file)
(concat file "/.")
......@@ -137,7 +137,7 @@ is no file at point, then instead visit `default-directory'."
(defun magit-dired-log (&optional follow)
"Show log for all marked files, or the current file."
(interactive "P")
(-if-let (topdir (magit-toplevel default-directory))
(if-let (topdir (magit-toplevel default-directory))
(let ((args (car (magit-log-arguments)))
(files (dired-get-marked-files nil nil #'magit-file-tracked-p)))
(unless files
......
......@@ -326,8 +326,8 @@ Currently this only adds the following key bindings.
(defun magit-blob-previous ()
"Visit the previous blob which modified the current file."
(interactive)
(-if-let (file (or magit-buffer-file-name
(buffer-file-name (buffer-base-buffer))))
(if-let (file (or magit-buffer-file-name
(buffer-file-name (buffer-base-buffer))))
(--if-let (magit-blob-ancestor magit-buffer-revision file)
(magit-blob-visit it (line-number-at-pos))
(user-error "You have reached the beginning of time"))
......
......@@ -490,7 +490,7 @@ 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"))
(if-let (topdir (magit-rev-parse-safe "--show-toplevel"))
(let (updir)
(setq topdir (magit-expand-git-file-name topdir))
(if (and
......@@ -2026,14 +2026,14 @@ the reference is used. The first regexp submatch becomes the
(defun magit--format-popup-variable:value (variable width &optional global)
(concat variable
(make-string (max 1 (- width 3 (length variable))) ?\s)
(-if-let (value (magit-get (and global "--global") variable))
(if-let (value (magit-get (and global "--global") variable))
(propertize value 'face 'magit-popup-option-value)
(propertize "unset" 'face 'magit-popup-disabled-argument))))
(defun magit--format-popup-variable:values (variable width &optional global)
(concat variable
(make-string (max 1 (- width 3 (length variable))) ?\s)
(-if-let (values (magit-get-all (and global "--global") variable))
(if-let (values (magit-get-all (and global "--global") variable))
(concat
(propertize (car values) 'face 'magit-popup-option-value)
(mapconcat
......
......@@ -502,10 +502,10 @@ This is a variant of `magit-log-popup' which shows the same popup
but which limits the log to the file being visited in the current
buffer."
(interactive)
(-if-let (file (magit-file-relative-name))
(if-let (file (magit-file-relative-name))
(let ((magit-log-arguments
(magit-popup-import-file-args
(-if-let (buffer (magit-mode-get-buffer 'magit-log-mode))
(if-let (buffer (magit-mode-get-buffer 'magit-log-mode))
(with-current-buffer buffer
(nth 2 magit-refresh-args))
(default-value 'magit-log-arguments))
......@@ -686,7 +686,7 @@ active, restrict the log to the lines that the region touches."
;; of a trailing newline.
(1- end)))))))))
(require 'magit)
(-if-let (file (magit-file-relative-name))
(if-let (file (magit-file-relative-name))
(magit-mode-setup-internal
#'magit-log-mode
(list (list (or magit-buffer-refname
......@@ -821,10 +821,10 @@ is displayed in the current frame."
(when (derived-mode-p 'magit-log-mode)
(magit-section-when commit
(let ((parent-rev (format "%s^%s" (oref it value) (or n 1))))
(-if-let (parent-hash (magit-rev-parse "--short" parent-rev))
(-if-let (section (--first (equal (oref it value)
parent-hash)
(magit-section-siblings it 'next)))
(if-let (parent-hash (magit-rev-parse "--short" parent-rev))
(if-let (section (--first (equal (oref it value)
parent-hash)
(magit-section-siblings it 'next)))
(magit-section-goto section)
(user-error
(substitute-command-keys
......
......@@ -129,7 +129,7 @@ branch, then also remove the respective remote branch."
(unless (yes-or-no-p
"Do you really wanto to merge `master' into another branch? ")
(user-error "Abort")))
(-if-let (target (magit-get-push-branch branch t))
(if-let (target (magit-get-push-branch branch t))
(progn
(magit-git-push branch target (list "--force-with-lease"))
(set-process-sentinel
......
......@@ -768,7 +768,7 @@ thinking a buffer belongs to a repo that it doesn't.")
(put 'magit-buffer-locked-p 'permanent-local t)
(defun magit-mode-get-buffer (mode &optional create frame value)
(-if-let (topdir (magit-toplevel))
(if-let (topdir (magit-toplevel))
(or (--first (with-current-buffer it
(and (eq major-mode mode)
(equal magit--default-directory topdir)
......@@ -844,15 +844,15 @@ 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-mode-get-buffer major-mode))
(if-let (unlocked (magit-mode-get-buffer major-mode))
(let ((locked (current-buffer)))
(switch-to-buffer unlocked nil t)
(kill-buffer locked))
(setq magit-buffer-locked-p nil)
(rename-buffer (funcall magit-generate-buffer-name-function
major-mode)))
(-if-let (value (magit-buffer-lock-value))
(-if-let (locked (magit-mode-get-buffer major-mode nil nil value))
(if-let (value (magit-buffer-lock-value))
(if-let (locked (magit-mode-get-buffer major-mode nil nil value))
(let ((unlocked (current-buffer)))
(switch-to-buffer locked nil t)
(kill-buffer unlocked))
......
......@@ -1044,10 +1044,10 @@ Limited by `magit-process-error-tooltip-max-lines'."
(with-current-buffer status-buf
(setq magit-this-error msg)))))
(message "%s ... [%s buffer %s for details]" msg
(-if-let (key (and (buffer-live-p command-buf)
(with-current-buffer command-buf
(car (where-is-internal
'magit-process-buffer)))))
(if-let (key (and (buffer-live-p command-buf)
(with-current-buffer command-buf
(car (where-is-internal
'magit-process-buffer)))))
(format "Hit %s to see" (key-description key))
"See")
(buffer-name process-buf))))))
......
......@@ -759,7 +759,7 @@ the push-remote can be changed before pushed to it."
"remote.pushDefault"
(format "branch.%s.pushRemote" it)))
push-remote))
(-if-let (remote (magit-get-push-remote it))
(if-let (remote (magit-get-push-remote it))
(if (member remote (magit-list-remotes))
(magit-git-push it (concat remote "/" it) args)
(user-error "Remote `%s' doesn't exist" remote))
......@@ -799,7 +799,7 @@ upstream can be changed before pushed to it."
(progn
(when upstream
(magit-set-branch*merge/remote it upstream))
(-if-let (target (magit-get-upstream-branch it))
(if-let (target (magit-get-upstream-branch it))
(magit-git-push it target args)
(user-error "No upstream is configured for %s" it)))
(user-error "No branch is checked out")))
......@@ -1010,7 +1010,7 @@ changes introduced by that commit (unlike 'git format-patch'
which creates patches for all commits that are reachable from
`HEAD' but not from the specified commit)."
(interactive
(list (-if-let (revs (magit-region-values 'commit t))
(list (if-let (revs (magit-region-values 'commit t))
(concat (car (last revs)) "^.." (car revs))
(let ((range (magit-read-range-or-commit "Format range or commit")))
(if (string-match-p "\\.\\." range)
......
......@@ -782,16 +782,16 @@ anything this time around.
:start (point-marker)
:parent magit-insert-section--parent)))
(oset ,s hidden
(-if-let (value (run-hook-with-args-until-success
'magit-section-set-visibility-hook ,s))
(if-let (value (run-hook-with-args-until-success
'magit-section-set-visibility-hook ,s))
(eq value 'hide)
(-if-let (incarnation (and magit-insert-section--oldroot
(magit-get-section
(magit-section-ident ,s)
magit-insert-section--oldroot)))
(if-let (incarnation (and magit-insert-section--oldroot
(magit-get-section
(magit-section-ident ,s)
magit-insert-section--oldroot)))
(oref incarnation hidden)
(-if-let (value (magit-section-match-assoc
,s magit-section-initial-visibility-alist))
(if-let (value (magit-section-match-assoc
,s magit-section-initial-visibility-alist))
(progn
(when (functionp value)
(setq value (funcall value ,s)))
......
......@@ -495,7 +495,7 @@ This discards all changes made since the sequence started."
If that variable is unset, then rebase onto `remote.pushDefault'."
(interactive (list (magit-rebase-arguments)))
(--if-let (magit-get-current-branch)
(-if-let (remote (magit-get-push-remote it))
(if-let (remote (magit-get-push-remote it))
(if (member remote (magit-list-remotes))
(magit-git-rebase (concat remote "/" it) args)
(user-error "Remote `%s' doesn't exist" remote))
......@@ -507,7 +507,7 @@ If that variable is unset, then rebase onto `remote.pushDefault'."
"Rebase the current branch onto its upstream branch."
(interactive (list (magit-rebase-arguments)))
(--if-let (magit-get-current-branch)
(-if-let (target (magit-get-upstream-branch it))
(if-let (target (magit-get-upstream-branch it))
(magit-git-rebase target args)
(user-error "No upstream is configured for %s" it))
(user-error "No branch is checked out")))
......
......@@ -211,8 +211,8 @@ also contains other useful hints.")
(defun magit--tramp-asserts (directory)
(when-let (remote (file-remote-p directory))
(unless (member remote magit--remotes-using-recent-git)
(-if-let (version (let ((default-directory directory))
(magit-git-version)))
(if-let (version (let ((default-directory directory))
(magit-git-version)))
(if (version<= magit--minimal-git version)
(push version magit--remotes-using-recent-git)
(display-warning 'magit (format "\
......
......@@ -397,12 +397,12 @@ acts similarly to `completing-read', except for the following:
`magit-completing-read-function' is set to its default value of
`magit-builtin-completing-read'."
(setq magit-completing-read--silent-default nil)
(-if-let (dwim (and def
(nth 2 (-first (pcase-lambda (`(,cmd ,re ,_))
(and (eq this-command cmd)
(or (not re)
(string-match-p re prompt))))
magit-dwim-selection))))
(if-let (dwim (and def
(nth 2 (-first (pcase-lambda (`(,cmd ,re ,_))
(and (eq this-command cmd)
(or (not re)
(string-match-p re prompt))))
magit-dwim-selection))))
(if (eq dwim 'ask)
(if (y-or-n-p (format "%s %s? " prompt def))
def
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment