[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit e733c8d1aa 05/12: magit-section-get-relative-po
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit e733c8d1aa 05/12: magit-section-get-relative-position: Define as generic function |
Date: |
Fri, 13 May 2022 10:58:11 -0400 (EDT) |
branch: elpa/git-commit
commit e733c8d1aa022458a67af5db70796c3d81ae6fb2
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
magit-section-get-relative-position: Define as generic function
---
lisp/magit-diff.el | 22 +++++++++++++++++++++-
lisp/magit-mode.el | 3 ++-
lisp/magit-section.el | 29 ++++++++---------------------
3 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index d59f9d6eb4..ffcece0b89 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -2849,7 +2849,7 @@ or a ref which is not a branch, then it inserts nothing."
(cl-defmethod magit-buffer-value (&context (major-mode
magit-merge-preview-mode))
magit-buffer-revision)
-;;; Diff Sections
+;;; Hunk Section
(defun magit-hunk-set-window-start (section)
"When SECTION is a `hunk', ensure that its beginning is visible.
@@ -2859,6 +2859,24 @@ It the SECTION has a different type, then do nothing."
(add-hook 'magit-section-movement-hook #'magit-hunk-set-window-start)
+(cl-defmethod magit-section-get-relative-position ((_section
magit-hunk-section))
+ (nconc (cl-call-next-method)
+ (and (region-active-p)
+ (progn
+ (goto-char (line-beginning-position))
+ (when (looking-at "^[-+]") (forward-line))
+ (while (looking-at "^[ @]") (forward-line))
+ (let ((beg (magit-point)))
+ (list (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-hunk-goto-successor (section arg)
(and (magit-hunk-section-p section)
(and-let* ((parent (magit-get-section
@@ -2884,6 +2902,8 @@ It the SECTION has a different type, then do nothing."
(add-hook 'magit-section-goto-successor-hook #'magit-hunk-goto-successor)
+;;; Diff Sections
+
(defvar magit-unstaged-section-map
(let ((map (make-sparse-keymap)))
(magit-menu-set map [magit-visit-thing] #'magit-diff-unstaged "Visit
diff")
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 9634819362..8eb4bc83a8 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1084,7 +1084,8 @@ Run hooks `magit-pre-refresh-hook' and
`magit-post-refresh-hook'."
(and-let* ((section (magit-section-at)))
`(( ,window
,section
-
,@(magit-section-get-relative-position)))))))
+ ,@(magit-section-get-relative-position
+ section)))))))
;; If it qualifies, then the selected window
;; comes first, but we want to handle it last
;; so that its `magit-section-movement-hook'
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 490e995e2c..f1ace71f31 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -1692,29 +1692,16 @@ 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)))
+(cl-defgeneric magit-section-get-relative-position (section))
+
+(cl-defmethod magit-section-get-relative-position ((section magit-section))
+ (let ((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)
+ (- point (line-beginning-position)))))
+
+(defun magit-section-goto-successor (section line char &optional arg)
(let ((ident (magit-section-ident section)))
(--if-let (magit-get-section ident)
(let ((start (oref it start)))
- [nongnu] elpa/git-commit 466bf542b0 02/12: Remove unnecessary declare-function, (continued)
- [nongnu] elpa/git-commit 466bf542b0 02/12: Remove unnecessary declare-function, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 91e6698435 10/12: Avoid loading bookmark upfront, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit ccb0de02ad 01/12: magit--disable-save-buffers: Renamed variable, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit c42b09f987 04/12: magit-section-get-relative-position: Rename and move, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 69327510e2 07/12: magit-section-goto-successor: Cosmetics, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 7c45ae83ac 08/12: Add magit-process-unset-mode-line-error-status to hook, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 67352a64b5 11/12: magit--toplevel-safe: New function, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 8269af107f 12/12: magit-generate-new-buffer: Determine appropriate default-directory, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 208dbd5689 06/12: magit-section-goto-successor: Define as generic function, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit 8ea1df1cd0 03/12: Wrap git-commit-mode with bound-and-true-p, ELPA Syncer, 2022/05/13
- [nongnu] elpa/git-commit e733c8d1aa 05/12: magit-section-get-relative-position: Define as generic function,
ELPA Syncer <=
- [nongnu] elpa/git-commit 2276f6bcce 09/12: Move core bookmark support to magit-mode.el, ELPA Syncer, 2022/05/13