branch: elpa/git-commit commit c42b09f9879bc16fbba4e83bb2a4e985a797ee54 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-section-get-relative-position: Rename and move Its value is consumed by `magit-section-goto-successor', which is also defined in magit-mode.el. --- lisp/magit-mode.el | 26 +------------------------- lisp/magit-section.el | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el index f0344ada74..9634819362 100644 --- a/lisp/magit-mode.el +++ b/lisp/magit-mode.el @@ -37,8 +37,6 @@ ;; For `magit-refresh-buffer' (declare-function magit-process-unset-mode-line-error-status "magit-process" ()) -;; For `magit-refresh-get-relative-position' -(declare-function magit-hunk-section-p "magit-diff" (section) t) ;; For `magit-mode' (defvar bookmark-make-record-function) (declare-function magit--make-bookmark "magit-bookmark" ()) @@ -1086,7 +1084,7 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (and-let* ((section (magit-section-at))) `(( ,window ,section - ,@(magit-refresh-get-relative-position))))))) + ,@(magit-section-get-relative-position))))))) ;; If it qualifies, then the selected window ;; comes first, but we want to handle it last ;; so that its `magit-section-movement-hook' @@ -1118,28 +1116,6 @@ Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (float-time (time-subtract (current-time) magit-refresh-start-time))))))) -(defun magit-refresh-get-relative-position () - (and-let* ((section (magit-current-section)) - (start (oref section start)) - (point (magit-point))) - (list (- (line-number-at-pos point) - (line-number-at-pos start)) - (- point (line-beginning-position)) - (and (magit-hunk-section-p section) - (region-active-p) - (progn (goto-char (line-beginning-position)) - (when (looking-at "^[-+]") (forward-line)) - (while (looking-at "^[ @]") (forward-line)) - (let ((beg (point))) - (cond ((looking-at "^[-+]") - (forward-line) - (while (looking-at "^[-+]") (forward-line)) - (while (looking-at "^ ") (forward-line)) - (forward-line -1) - (regexp-quote (buffer-substring-no-properties - beg (line-end-position)))) - (t t)))))))) - ;;; Save File-Visiting Buffers (defvar magit--disable-save-buffers nil) diff --git a/lisp/magit-section.el b/lisp/magit-section.el index 318a774301..490e995e2c 100644 --- a/lisp/magit-section.el +++ b/lisp/magit-section.el @@ -50,6 +50,9 @@ (eval-when-compile (require 'benchmark)) +;; For `magit-section-get-relative-position' +(declare-function magit-hunk-section-p "magit-diff" (section) t) + ;;; Hooks (defvar magit-section-movement-hook nil @@ -1689,6 +1692,28 @@ invisible." (push ov magit-section-highlight-overlays) ov)) +(defun magit-section-get-relative-position () + (and-let* ((section (magit-current-section)) + (start (oref section start)) + (point (magit-point))) + (list (- (line-number-at-pos point) + (line-number-at-pos start)) + (- point (line-beginning-position)) + (and (magit-hunk-section-p section) + (region-active-p) + (progn (goto-char (line-beginning-position)) + (when (looking-at "^[-+]") (forward-line)) + (while (looking-at "^[ @]") (forward-line)) + (let ((beg (point))) + (cond ((looking-at "^[-+]") + (forward-line) + (while (looking-at "^[-+]") (forward-line)) + (while (looking-at "^ ") (forward-line)) + (forward-line -1) + (regexp-quote (buffer-substring-no-properties + beg (line-end-position)))) + (t t)))))))) + (defun magit-section-goto-successor (section line char arg) (let ((ident (magit-section-ident section))) (--if-let (magit-get-section ident)