Commit 39fe824f authored by Jonas Bernoulli's avatar Jonas Bernoulli

magit-section-when: Stop using it as originally intended

Only three functions used `magit-section-when' as originally intended,
indicating that it probably isn't as useful as imagined.  Another
function uses it a strange way that isn't used anywhere else, even
though `magit-section-when's doc-string hints at such a use-case.

Stop using `magit-section-when' like that, so that it can be
deprecated and be replaced with a function that better suits the
majority of callers.  The remaining callers use `magit-section-when'
in a way that does not justify the "when" in its name.
parent 4daba697
......@@ -459,8 +459,9 @@ If no commit is in progress, then initiate it. Use the function
specified by variable `magit-commit-add-log-insert-function' to
actually insert the entry."
(let ((hunk (magit-section-when 'hunk it))
(log (magit-commit-message-buffer)) buf pos)
(let ((hunk (and (magit-section-match 'hunk)
(log (magit-commit-message-buffer)) buf pos)
(call-interactively #'magit-diff-visit-file)
(setq buf (current-buffer))
......@@ -1070,13 +1070,13 @@ to, or to some other symbolic-ref that points to the same ref."
(branch (magit-section-parent-value it))))
(defun magit-module-at-point (&optional predicate)
[file modules-unpulled-from-upstream]
[file modules-unpulled-from-pushremote]
[file modules-unpushed-to-upstream]
[file modules-unpushed-to-pushremote])
(let ((module (oref it value)))
(when (magit-section-match
[file modules-unpulled-from-upstream]
[file modules-unpulled-from-pushremote]
[file modules-unpushed-to-upstream]
[file modules-unpushed-to-pushremote]))
(let ((module (oref (magit-current-section) value)))
(and (or (not predicate)
(funcall predicate module))
......@@ -818,13 +818,14 @@ is displayed in the current frame."
"Move to the Nth parent of the current commit."
(interactive "p")
(when (derived-mode-p 'magit-log-mode)
(magit-section-when commit
(let ((parent-rev (format "%s^%s" (oref it value) (or n 1))))
(when (magit-section-match 'commit)
(let* ((section (magit-current-section))
(parent-rev (format "%s^%s" (oref section value) (or n 1))))
(if-let ((parent-hash (magit-rev-parse "--short" parent-rev)))
(if-let ((section (--first (equal (oref it value)
(magit-section-siblings it 'next))))
(magit-section-goto section)
(if-let ((parent (--first (equal (oref section value)
(magit-section-siblings section 'next))))
(magit-section-goto parent)
(concat "Parent " parent-hash " not found. Try typing "
......@@ -282,8 +282,8 @@ optional NODISPLAY is non-nil also display it."
(defun magit-process-kill ()
"Kill the process at point."
(magit-section-when process
(let ((process (oref it value)))
(when (magit-section-match 'process)
(let ((process (oref (magit-current-section) value)))
(unless (eq (process-status process) 'run)
(user-error "Process isn't running"))
(magit-confirm 'kill-process)
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