branch: elpa/magit
commit 3ec4a182a602ac890844588ab39829912f0e168d
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit--{bolp,eolp,bol-position,eol-position}: New utility functions
It would have been better to define them in "magit-base.el",
but then we couldn't use them in "magit-section.el".
---
lisp/git-rebase.el | 6 ++----
lisp/magit-blame.el | 4 +---
lisp/magit-diff.el | 6 ++----
lisp/magit-section.el | 32 +++++++++++++++++++++++---------
4 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/lisp/git-rebase.el b/lisp/git-rebase.el
index f552e4ae0d6..e408408edf5 100644
--- a/lisp/git-rebase.el
+++ b/lisp/git-rebase.el
@@ -375,10 +375,8 @@ non-nil, return the beginning and end of the current
rebase line,
if any."
(cond
((use-region-p)
- (let ((beg (save-excursion (goto-char (region-beginning))
- (line-beginning-position)))
- (end (save-excursion (goto-char (region-end))
- (line-end-position))))
+ (let ((beg (magit--bol-position (region-beginning)))
+ (end (magit--eol-position (region-end))))
(and (git-rebase-line-p beg)
(git-rebase-line-p end)
(list beg (1+ end)))))
diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index fb27be3ef67..1e8f0ba52ba 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -599,9 +599,7 @@ modes is toggled, then this mode also gets toggled
automatically.
(magit-blame--update-heading-overlay ov)))
(defun magit-blame--make-highlight-overlay (chunk beg)
- (let ((ov (make-overlay beg (save-excursion
- (goto-char beg)
- (1+ (line-end-position))))))
+ (let ((ov (make-overlay beg (1+ (magit--eol-position beg)))))
(overlay-put ov 'magit-blame-chunk chunk)
(overlay-put ov 'magit-blame-highlight t)
(magit-blame--update-highlight-overlay ov)))
diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 644d3ea5b74..6eabd5345a3 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -3464,12 +3464,10 @@ are highlighted."
;;; Hunk Region
(defun magit-diff-hunk-region-beginning ()
- (save-excursion (goto-char (region-beginning))
- (line-beginning-position)))
+ (magit--bol-position (region-beginning)))
(defun magit-diff-hunk-region-end ()
- (save-excursion (goto-char (region-end))
- (line-end-position)))
+ (magit--eol-position (region-end)))
(defun magit-diff-update-hunk-region (section)
"Highlight the hunk-internal region if any."
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 89d3c598712..49d4a4603b3 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -1620,9 +1620,7 @@ is explicitly expanded."
(setq map (symbol-value map)))
(put-text-property
start
- (save-excursion
- (goto-char start)
- (line-end-position))
+ (magit--eol-position start)
'keymap (if map
(make-composed-keymap
(list map magit-section-heading-map))
@@ -1913,9 +1911,7 @@ When `magit-section-preserve-visibility' is nil, do
nothing."
(when (and magit-section-visibility-indicator
(magit-section-content-p section))
(let* ((beg (oref section start))
- (eoh (save-excursion
- (goto-char beg)
- (line-end-position))))
+ (eoh (magit--eol-position beg)))
(cond
((symbolp (car-safe magit-section-visibility-indicator))
(let ((ov (magit--overlay-at beg 'magit-vis-indicator 'fringe)))
@@ -1983,9 +1979,7 @@ When `magit-section-preserve-visibility' is nil, do
nothing."
(= (oref section content)
(oref section end)))
(dolist (o (overlays-in (oref section start)
- (save-excursion
- (goto-char (oref section start))
- (1+ (line-end-position)))))
+ (1+ (magit--eol-position (oref section start)))))
(when (overlay-get o 'magit-vis-indicator)
(delete-overlay o)))))
@@ -2287,6 +2281,26 @@ Configuration'."
(put-text-property beg end 'face face string)
(put-text-property beg end 'font-lock-face face string))
+(defun magit--bolp (pos)
+ "Return t if POS is at the beginning of a line.
+This is like moving to POS and then calling `bolp'."
+ (save-excursion (goto-char pos) (bolp)))
+
+(defun magit--eolp (pos)
+ "Return t if POS is at the end of a line.
+This is like moving to POS and then calling `eolp'."
+ (save-excursion (goto-char pos) (bolp)))
+
+(defun magit--bol-position (pos)
+ "Return the position at the beginning of the line containing POS.
+This is like moving to POS and then calling `pos-bol'."
+ (save-excursion (goto-char pos) (pos-bol)))
+
+(defun magit--eol-position (pos)
+ "Return the position at the end of the line containing POS.
+This is like moving to POS and then calling `pos-eol'."
+ (save-excursion (goto-char pos) (pos-eol)))
+
;;; Imenu Support
(defvar-local magit--imenu-group-types nil)