Commit e6a03524 authored by Jonas Bernoulli's avatar Jonas Bernoulli

Use when-let instead of -when-let

parent b8133ab8
......@@ -49,7 +49,7 @@ This function will:
(apply fn args)
(signal 'bookmark-error-no-filename (list 'stringp default-directory)))
(when (derived-mode-p 'magit-mode)
(-when-let (hidden-sections (bookmark-prop-get bookmark
(when-let (hidden-sections (bookmark-prop-get bookmark
'magit-hidden-sections))
(--each (oref magit-root-section children)
(if (member (cons (oref it type)
......
......@@ -575,7 +575,7 @@ defaulting to the branch at point."
(list (magit-read-branch-prefer-other
(if force "Force delete branch" "Delete branch")))))
(unless force
(-when-let (unmerged (-remove #'magit-branch-merged-p branches))
(when-let (unmerged (-remove #'magit-branch-merged-p branches))
(if (magit-confirm 'delete-unmerged-branch
"Delete unmerged branch %s"
"Delete %i unmerged branches"
......@@ -649,7 +649,7 @@ defaulting to the branch at point."
(put 'magit-branch-delete 'interactive-only t)
(defun magit-branch-maybe-delete-pr-remote (branch)
(-when-let (remote (magit-get "branch" branch "pullRequestRemote"))
(when-let (remote (magit-get "branch" branch "pullRequestRemote"))
(let* ((variable (format "remote.%s.fetch" remote))
(refspecs (magit-get-all variable)))
(unless (member (format "+refs/heads/*:refs/remotes/%s/*" remote)
......
......@@ -126,7 +126,7 @@ an error while using those is harder to recover from."
(require 'epa)
(let ((keys (--map (concat (epg-sub-key-id (car (epg-key-sub-key-list it)))
" "
(-when-let (id-obj (car (epg-key-user-id-list it)))
(when-let (id-obj (car (epg-key-user-id-list it)))
(let ((id-str (epg-user-id-string id-obj)))
(if (stringp id-str)
id-str
......@@ -257,7 +257,7 @@ depending on the value of option `magit-commit-squash-confirm'."
(defun magit-commit-squash-internal
(option commit &optional args rebase edit confirmed)
(-when-let (args (magit-commit-assert args t))
(when-let (args (magit-commit-assert args t))
(when commit
(when (and rebase (not (magit-rev-ancestor-p commit "HEAD")))
(magit-read-char-case
......@@ -374,7 +374,7 @@ history element."
(defun magit-commit-diff ()
(when (and git-commit-mode magit-commit-show-diff)
(-when-let (diff-buffer (magit-mode-get-buffer 'magit-diff-mode))
(when-let (diff-buffer (magit-mode-get-buffer 'magit-diff-mode))
;; This window just started displaying the commit message
;; buffer. Without this that buffer would immediately be
;; replaced with the diff buffer. See #2632.
......
......@@ -1349,7 +1349,7 @@ or `HEAD'."
rev))))
(defun magit-diff-visit--hunk ()
(-when-let (scope (magit-diff-scope))
(when-let (scope (magit-diff-scope))
(let ((section (magit-current-section)))
(cl-case scope
((file files)
......@@ -2099,7 +2099,7 @@ or a ref which is not a branch, then it inserts nothing."
(insert "Parent: ")
(insert (propertize hash 'face 'magit-hash))
(insert " " msg "\n")))))
(-when-let (merged (magit-list-merged-branches rev))
(when-let (merged (magit-list-merged-branches rev))
(insert "Merged: ")
(let (branch)
(while (and (< (+ (- (point) (line-beginning-position))
......@@ -2112,7 +2112,7 @@ or a ref which is not a branch, then it inserts nothing."
(when merged
(insert (format " (%s more)" (length merged))))
(insert ?\n))
(-when-let (containing (magit-list-containing-branches rev))
(when-let (containing (magit-list-containing-branches rev))
(insert "Containing:")
(let (branch)
(while (and (< (+ (- (point) (line-beginning-position))
......@@ -2125,7 +2125,7 @@ or a ref which is not a branch, then it inserts nothing."
(when containing
(insert (format " (%s more)" (length containing))))
(insert ?\n))
(-when-let (follows (magit-get-current-tag rev t))
(when-let (follows (magit-get-current-tag rev t))
(let ((tag (car follows))
(cnt (cadr follows)))
(magit-insert-section (tag tag)
......@@ -2133,7 +2133,7 @@ or a ref which is not a branch, then it inserts nothing."
(propertize tag 'face 'magit-tag)
(propertize (number-to-string cnt)
'face 'magit-branch-local))))))
(-when-let (precedes (magit-get-next-tag rev t))
(when-let (precedes (magit-get-next-tag rev t))
(let ((tag (car precedes))
(cnt (cadr precedes)))
(magit-insert-section (tag tag)
......@@ -2170,7 +2170,7 @@ or a ref which is not a branch, then it inserts nothing."
(defun magit-insert-revision-gravatar-cb (image rev marker align-to column)
(unless (eq image 'error)
(-when-let (buffer (marker-buffer marker))
(when-let (buffer (marker-buffer marker))
(with-current-buffer buffer
(save-excursion
(goto-char marker)
......@@ -2379,7 +2379,7 @@ are highlighted."
(magit-diff-highlight-list section selection))
(magit-diff-highlight-list section))
t)
(-when-let (scope (magit-diff-scope section t))
(when-let (scope (magit-diff-scope section t))
(cond ((eq scope 'region)
(magit-diff-paint-hunk section selection t))
(selection
......
......@@ -277,7 +277,7 @@ With a prefix argument only ignore locally."
(delete-dups
(--mapcat
(cons (concat "/" it)
(-when-let (ext (file-name-extension it))
(when-let (ext (file-name-extension it))
(list (concat "/" (file-name-directory "foo") "*." ext)
(concat "*." ext))))
(magit-untracked-files)))))
......@@ -654,7 +654,7 @@ above."
(interactive)
(if (use-region-p)
(copy-region-as-kill nil nil 'region)
(-when-let (rev (cond ((memq major-mode '(magit-cherry-mode
(when-let (rev (cond ((memq major-mode '(magit-cherry-mode
magit-log-select-mode
magit-reflog-mode
magit-refs-mode
......
......@@ -436,7 +436,7 @@ call function WASHER with ARGS as its sole argument."
(defmacro magit--with-safe-default-directory (file &rest body)
(declare (indent 1) (debug (form body)))
`(-when-let (default-directory (magit--safe-default-directory ,file))
`(when-let (default-directory (magit--safe-default-directory ,file))
,@body))
(defun magit-git-dir (&optional path)
......@@ -447,7 +447,7 @@ it has to be a path relative to the control directory and its
absolute path is returned."
(magit--with-refresh-cache (list default-directory 'magit-git-dir path)
(magit--with-safe-default-directory nil
(-when-let (dir (magit-rev-parse-safe "--git-dir"))
(when-let (dir (magit-rev-parse-safe "--git-dir"))
(setq dir (file-name-as-directory (magit-expand-git-file-name dir)))
(unless (file-remote-p dir)
(setq dir (concat (file-remote-p default-directory) dir)))
......@@ -520,7 +520,7 @@ returning the truename."
updir
(concat (file-remote-p default-directory)
(file-name-as-directory topdir))))
(-when-let (gitdir (magit-rev-parse-safe "--git-dir"))
(when-let (gitdir (magit-rev-parse-safe "--git-dir"))
(setq gitdir (file-name-as-directory
(if (file-name-absolute-p gitdir)
;; We might have followed a symlink.
......@@ -1304,7 +1304,7 @@ SORTBY is a key or list of keys to pass to the `--sort' flag of
(magit-list-related-branches "--no-merged" commit arg))
(defun magit-list-unmerged-to-upstream-branches ()
(--filter (-when-let (upstream (magit-get-upstream-branch it))
(--filter (when-let (upstream (magit-get-upstream-branch it))
(member it (magit-list-unmerged-branches upstream)))
(magit-list-local-branch-names)))
......
......@@ -1280,7 +1280,7 @@ If there is no blob buffer in the same frame, then do nothing."
;;; Log Margin
(defun magit-log-format-margin (author date)
(-when-let (option (magit-margin-option))
(when-let (option (magit-margin-option))
(-let [(_ style width details details-width)
(or magit-buffer-margin
(symbol-value option))]
......
......@@ -119,7 +119,7 @@ does not carry to other options."
(`magit-status-mode 'magit-status-margin)))
(defun magit-set-buffer-margin (&optional reset refresh)
(-when-let (option (magit-margin-option))
(when-let (option (magit-margin-option))
(let* ((default (symbol-value option))
(default-width (nth 2 default)))
(when (or reset (not magit-buffer-margin))
......
......@@ -650,7 +650,7 @@ other buffers in the selected window."
'(display-buffer-same-window))))
(defun magit--display-buffer-fullframe (buffer alist)
(-when-let (window (or (display-buffer-reuse-window buffer alist)
(when-let (window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-pop-up-window buffer alist)
(display-buffer-use-some-window buffer alist)))
......@@ -667,7 +667,7 @@ Otherwise, behave like `magit-display-buffer-traditional'."
(defun magit--display-buffer-topleft (buffer alist)
(or (display-buffer-reuse-window buffer alist)
(-when-let (window2 (display-buffer-pop-up-window buffer alist))
(when-let (window2 (display-buffer-pop-up-window buffer alist))
(let ((window1 (get-buffer-window))
(buffer1 (current-buffer))
(buffer2 (window-buffer window2))
......@@ -709,7 +709,7 @@ split is made vertically or horizontally is determined by
'(display-buffer-same-window)))))
(defun magit--display-buffer-fullcolumn (buffer alist)
(-when-let (window (or (display-buffer-reuse-window buffer alist)
(when-let (window (or (display-buffer-reuse-window buffer alist)
(display-buffer-same-window buffer alist)
(display-buffer-below-selected buffer alist)))
(delete-other-windows-vertically window)
......@@ -1018,7 +1018,7 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'."
(windows
(--mapcat (with-selected-window it
(with-current-buffer buffer
(-when-let (section (magit-current-section))
(when-let (section (magit-current-section))
(list
(nconc (list it section)
(magit-refresh-get-relative-position))))))
......@@ -1047,7 +1047,7 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'."
magit-refresh-start-time)))))))
(defun magit-refresh-get-relative-position ()
(-when-let (section (magit-current-section))
(when-let (section (magit-current-section))
(let ((start (oref section start)))
(list (count-lines start (point))
(- (point) (line-beginning-position))
......@@ -1132,7 +1132,7 @@ is saved without asking, the user is asked about each modified
buffer which visits a file in the current repository. Optional
argument (the prefix) non-nil means save all with no questions."
(interactive "P")
(-when-let (topdir (magit-rev-parse-safe "--show-toplevel"))
(when-let (topdir (magit-rev-parse-safe "--show-toplevel"))
(let ((remote (file-remote-p topdir))
(save-some-buffers-action-alist
`((?Y (lambda (buffer)
......
......@@ -662,9 +662,9 @@ Magit status buffer."
"Special sentinel used by `magit-run-git-sequencer'."
(when (memq (process-status process) '(exit signal))
(magit-process-sentinel process event)
(-when-let (process-buf (process-buffer process))
(when-let (process-buf (process-buffer process))
(when (buffer-live-p process-buf)
(-when-let (status-buf (with-current-buffer process-buf
(when-let (status-buf (with-current-buffer process-buf
(magit-mode-get-buffer 'magit-status-mode)))
(with-current-buffer status-buf
(--when-let
......@@ -715,7 +715,7 @@ Magit status buffer."
(defun magit-process-yes-or-no-prompt (process string)
"Forward Yes-or-No prompts to the user."
(-when-let (beg (string-match magit-process-yes-or-no-prompt-regexp string))
(when-let (beg (string-match magit-process-yes-or-no-prompt-regexp string))
(let ((max-mini-window-height 30))
(process-send-string
process
......@@ -1040,7 +1040,7 @@ Limited by `magit-process-error-tooltip-max-lines'."
((not (eq msg 'suppressed))
(when (buffer-live-p process-buf)
(with-current-buffer process-buf
(-when-let (status-buf (magit-mode-get-buffer 'magit-status-mode))
(when-let (status-buf (magit-mode-get-buffer 'magit-status-mode))
(with-current-buffer status-buf
(setq magit-this-error msg)))))
(message "%s ... [%s buffer %s for details]" msg
......
......@@ -503,7 +503,7 @@ line is inserted at all."
(defun magit-insert-tags ()
"Insert sections showing all tags."
(-when-let (tags (magit-git-lines "tag" "--list" "-n"
(when-let (tags (magit-git-lines "tag" "--list" "-n"
(cadr magit-refresh-args)))
(let ((_head (magit-rev-parse "HEAD")))
(magit-insert-section (tags)
......
......@@ -380,7 +380,7 @@ With a prefix argument also expand it." heading)
"Show the body of the current section."
(interactive (list (magit-current-section)))
(oset section hidden nil)
(-when-let (washer (oref section washer))
(when-let (washer (oref section washer))
(oset section washer nil)
(let ((inhibit-read-only t)
(magit-insert-section--parent section)
......@@ -393,7 +393,7 @@ With a prefix argument also expand it." heading)
(funcall washer)
(oset section end (point-marker)))))
(magit-section-update-highlight))
(-when-let (beg (oref section content))
(when-let (beg (oref section content))
(remove-overlays beg (oref section end) 'invisible t))
(magit-section-maybe-cache-visibility section)
(dolist (child (oref section children))
......@@ -407,7 +407,7 @@ With a prefix argument also expand it." heading)
(if (eq section magit-root-section)
(user-error "Cannot hide root section")
(oset section hidden t)
(-when-let (beg (oref section content))
(when-let (beg (oref section content))
(let ((end (oref section end)))
(remove-overlays beg end 'invisible t)
(let ((o (make-overlay beg end)))
......@@ -503,7 +503,7 @@ hidden."
(defun magit-section-cycle-diffs ()
"Cycle visibility of diff-related sections in the current buffer."
(interactive)
(-when-let (sections
(when-let (sections
(cond ((derived-mode-p 'magit-status-mode)
(--mapcat
(when it
......@@ -1030,7 +1030,7 @@ invisible."
(unless (eq (magit-current-section) it)
(goto-char start))))
(or (and (magit-hunk-section-p section)
(-when-let (parent (magit-get-section
(when-let (parent (magit-get-section
(magit-section-ident
(oref section parent))))
(let* ((children (oref parent children))
......@@ -1117,7 +1117,7 @@ invisible."
(magit-section-selected-p it selection)))))
(defun magit-section-parent-value (section)
(-when-let (parent (oref section parent))
(when-let (parent (oref section parent))
(oref parent value)))
(defun magit-section-siblings (section &optional direction)
......@@ -1127,7 +1127,7 @@ If optional DIRECTION is `prev', then return siblings that come
before SECTION. If it is `next', then return siblings that come
after SECTION. For all other values, return all siblings
excluding SECTION itself."
(-when-let (parent (oref section parent))
(when-let (parent (oref section parent))
(let ((siblings (oref parent children)))
(pcase direction
(`prev (cdr (member section (reverse siblings))))
......
......@@ -714,7 +714,7 @@ If no such sequence is in progress, do nothing."
(when (or picking (magit-revert-in-progress-p))
(magit-insert-section (sequence)
(magit-insert-heading (if picking "Cherry Picking" "Reverting"))
(-when-let (lines (cdr (magit-file-lines (magit-git-dir "sequencer/todo"))))
(when-let (lines (cdr (magit-file-lines (magit-git-dir "sequencer/todo"))))
(dolist (line (nreverse lines))
(when (string-match "^\\(pick\\|revert\\) \\([^ ]+\\) \\(.*\\)$" line)
(magit-bind-match-strings (cmd hash msg) line
......
......@@ -227,7 +227,7 @@ When the region is active offer to drop all contained stashes."
(magit-rev-parse "--short" stash))
(magit-call-git "rev-parse" stash)
(magit-call-git "reflog" "delete" "--updateref" "--rewrite" stash))
(-when-let (ref (and (string-match "\\(.+\\)@{[0-9]+}$" stash)
(when-let (ref (and (string-match "\\(.+\\)@{[0-9]+}$" stash)
(match-string 1 stash)))
(unless (string-match "^refs/" ref)
(setq ref (concat "refs/" ref)))
......
......@@ -145,7 +145,7 @@ Non-interactively DIRECTORY is (re-)initialized unconditionally."
(let ((directory (file-name-as-directory
(expand-file-name
(read-directory-name "Create repository in: ")))))
(-when-let (toplevel (magit-toplevel directory))
(when-let (toplevel (magit-toplevel directory))
(setq toplevel (expand-file-name toplevel))
(unless (y-or-n-p (if (file-equal-p toplevel directory)
(format "Reinitialize existing repository %s? "
......@@ -209,7 +209,7 @@ also contains other useful hints.")
(defvar magit--remotes-using-recent-git nil)
(defun magit--tramp-asserts (directory)
(-when-let (remote (file-remote-p 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)))
......@@ -338,7 +338,7 @@ the status buffer causes this section to disappear again."
(insert (propertize (format "%-10s" "GitError! ")
'face 'magit-section-heading))
(insert (propertize magit-this-error 'face 'font-lock-warning-face))
(-when-let (key (car (where-is-internal 'magit-process-buffer)))
(when-let (key (car (where-is-internal 'magit-process-buffer)))
(insert (format " [Type `%s' for details]" (key-description key))))
(insert ?\n))
(setq magit-this-error nil)))
......@@ -504,13 +504,12 @@ value of that variable can be set using \"D = f DIRECTORY RET g\"."
(base (and base (file-directory-p base) base)))
(unless (equal show "no")
(if (equal show "all")
(-when-let (files (magit-untracked-files nil base))
(when-let (files (magit-untracked-files nil base))
(magit-insert-section (untracked)
(magit-insert-heading "Untracked files:")
(magit-insert-files files base)
(insert ?\n)))
(-when-let
(files (--mapcat (and (eq (aref it 0) ??)
(when-let (files (--mapcat (and (eq (aref it 0) ??)
(list (substring it 3)))
(magit-git-items "status" "-z" "--porcelain"
"--" base)))
......@@ -529,7 +528,7 @@ value of that variable can be set using \"D = f DIRECTORY RET g\"."
If the first element of `magit-diff-section-arguments' is a
directory, then limit the list to files below that. The value
value of that variable can be set using \"D = f DIRECTORY RET g\"."
(-when-let (files (magit-list-files))
(when-let (files (magit-list-files))
(let* ((base (car magit-diff-section-file-args))
(base (and base (file-directory-p base) base)))
(magit-insert-section (tracked nil t)
......@@ -543,7 +542,7 @@ value of that variable can be set using \"D = f DIRECTORY RET g\"."
If the first element of `magit-diff-section-arguments' is a
directory, then limit the list to files below that. The value
of that variable can be set using \"D = f DIRECTORY RET g\"."
(-when-let (files (magit-ignored-files))
(when-let (files (magit-ignored-files))
(let* ((base (car magit-diff-section-file-args))
(base (and base (file-directory-p base) base)))
(magit-insert-section (tracked nil t)
......
......@@ -278,7 +278,7 @@ single module from the user."
Hook `magit-module-sections-hook' controls which module sections
are inserted, and option `magit-module-sections-nested' controls
whether they are wrapped in an additional section."
(-when-let (modules (magit-list-module-paths))
(when-let (modules (magit-list-module-paths))
(if magit-module-sections-nested
(magit-insert-section section (submodules nil t)
(magit-insert-heading
......@@ -298,7 +298,7 @@ whether they are wrapped in an additional section."
"Insert sections for all modules.
For each section insert the path and the output of `git describe --tags',
or, failing that, the abbreviated HEAD commit hash."
(-when-let (modules (magit-list-module-paths))
(when-let (modules (magit-list-module-paths))
(magit-insert-section section (submodules nil t)
(magit-insert-heading
(format "%s (%s)"
......@@ -415,7 +415,7 @@ These sections can be expanded to show the respective commits."
(defun magit--insert-modules-logs (heading type range)
"For internal use, don't add to a hook."
(-when-let (modules (magit-list-module-paths))
(when-let (modules (magit-list-module-paths))
(magit-insert-section section ((eval type) nil t)
(string-match "\\`\\(.+\\) \\([^ ]+\\)\\'" heading)
(magit-insert-heading
......
......@@ -40,6 +40,7 @@
(require 'cl-lib)
(require 'dash)
(require 'subr-x)
(require 'crm)
......
......@@ -270,7 +270,7 @@ many \"branches\" of each wip ref are shown."
args files))
(defun magit-wip-log-get-tips (wipref count)
(-when-let (reflog (magit-git-lines "reflog" wipref))
(when-let (reflog (magit-git-lines "reflog" wipref))
(let (tips)
(while (and reflog (> count 1))
(setq reflog (cl-member "^[^ ]+ [^:]+: restart autosaving"
......
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