branch: elpa/magit
commit 415bd700992a70e50fd6fdf8e37519bf22fa2aa7
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-make-margin-overlay: At bol set margin of previous line
That is actually what all but one caller need.
For `magit-log-wash-rev', which unlike the other callers does not
insert texts but instead moves other existing lines, it does not
matter. Here we can just move the call to `magit-make-margin-overlay'
from before the call to `forward-line' to after that.
Do not just unconditionally default to set the margin of the previous
line, in case that doesn't work for third-party callers. Only do so
if point is at the beginning of a line. Also for compatibility, keep
the optional PREVIOUS-LINE argument, but ignore it if not provided.
I.e., unspecified means "dwim", not "nil, therefore for current line".
Suggested-by: Martin Joerg <[email protected]>
---
lisp/magit-log.el | 19 +++++++------------
lisp/magit-margin.el | 19 ++++++++++---------
lisp/magit-refs.el | 18 ++++++++----------
lisp/magit-stash.el | 8 ++------
4 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index c623d347bf0..5166617bf9a 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -1448,15 +1448,11 @@ Do not add this to a hook variable."
(setq date (+ (string-to-number (match-string 1 date))
(* (string-to-number (match-string 2 date)) 60 60)
(* (string-to-number (match-string 3 date)) 60))))
- (save-excursion
- (backward-char)
- (magit-log-format-margin hash author date)))
+ (magit-log-format-margin hash author date))
(when (and (eq style 'cherry)
(magit-buffer-margin-p))
- (save-excursion
- (backward-char)
- (apply #'magit-log-format-margin hash
- (split-string (magit-rev-format "%aN%x00%ct" hash) "\0"))))
+ (apply #'magit-log-format-margin hash
+ (split-string (magit-rev-format "%aN%x00%ct" hash) "\0")))
(when (and graph
(not (eobp))
(not (looking-at non-graph-re)))
@@ -1487,8 +1483,8 @@ Do not add this to a hook variable."
(while (and (not (eobp)) (not (looking-at non-graph-re)))
(when align
(save-excursion (insert align)))
- (magit-make-margin-overlay)
- (forward-line))
+ (forward-line)
+ (magit-make-margin-overlay))
;; When `--format' is used and its value isn't one of the
;; predefined formats, then `git-log' does not insert a
;; separator line.
@@ -1616,7 +1612,7 @@ The shortstat style is experimental and rather slow."
(magit-log-format-shortstat-margin rev)
(magit-log-format-author-margin author date))))
-(defun magit-log-format-author-margin (author date &optional previous-line)
+(defun magit-log-format-author-margin (author date)
(pcase-let ((`(,_ ,style ,width ,details ,details-width)
(or magit-buffer-margin
(symbol-value (magit-margin-option))
@@ -1641,8 +1637,7 @@ The shortstat style is experimental and rather slow."
(format (format (if abbr "%%2d%%-%dc" "%%2d %%-%ds")
(- width (if details (1+ details-width) 0)))
cnt unit)))
- 'magit-log-date))
- previous-line)))
+ 'magit-log-date)))))
(defun magit-log-format-shortstat-margin (rev)
(magit-make-margin-overlay
diff --git a/lisp/magit-margin.el b/lisp/magit-margin.el
index 064f8c72a6f..b710fbddd39 100644
--- a/lisp/magit-margin.el
+++ b/lisp/magit-margin.el
@@ -159,15 +159,16 @@ does not carry to other options."
(and (magit-buffer-margin-p)
(nth 2 magit-buffer-margin))))))
-(defun magit-make-margin-overlay (&optional string previous-line)
- (if previous-line
- (save-excursion
- (forward-line -1)
- (magit-make-margin-overlay string))
+(cl-defun magit-make-margin-overlay (&optional string (previous-line nil
sline))
+ "Display STRING in the margin of the previous (or current) line.
+If point is at the beginning of a line, set the margin string for
+the previous line, otherwise for the current line. Semi-obsolete
+optional PREVIOUS-LINE can be used to explicitly specify which
+line is affected."
+ (save-excursion
+ (forward-line (if (if sline previous-line (bolp)) -1 0))
;; Don't put the overlay on the complete line to work around #1880.
- (let ((o (make-overlay (1+ (line-beginning-position))
- (line-end-position)
- nil t)))
+ (let ((o (make-overlay (1+ (point)) (line-end-position) nil t)))
(overlay-put o 'evaporate t)
(overlay-put o 'before-string
(propertize "o" 'display
@@ -184,7 +185,7 @@ does not carry to other options."
(defun magit-maybe-make-margin-overlay ()
(when (magit-section-match magit-margin-overlay-conditions
magit-insert-section--current)
- (magit-make-margin-overlay nil t)))
+ (magit-make-margin-overlay)))
;;; Custom Support
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index e5132d726c4..2bcee3e7e24 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -565,7 +565,7 @@ line is inserted at all."
(magit-refs--format-margin tag))
(magit-refs--insert-cherry-commits tag)))))
(insert ?\n)
- (magit-make-margin-overlay nil t)))))
+ (magit-make-margin-overlay)))))
(defun magit-insert-remote-branches ()
"Insert sections showing all remote-tracking branches."
@@ -620,7 +620,7 @@ line is inserted at all."
(magit-refs--format-margin branch))
(magit-refs--insert-cherry-commits branch))))))))
(insert ?\n)
- (magit-make-margin-overlay nil t))))
+ (magit-make-margin-overlay))))
(defun magit-insert-local-branches ()
"Insert sections showing all local branches."
@@ -637,7 +637,7 @@ line is inserted at all."
(magit-refs--format-margin branch))
(magit-refs--insert-cherry-commits branch))))
(insert ?\n)
- (magit-make-margin-overlay nil t)))
+ (magit-make-margin-overlay)))
(defun magit-insert-shelved-branches ()
"Insert sections showing all shelved branches."
@@ -652,7 +652,7 @@ line is inserted at all."
(magit-refs--format-margin ref))
(magit-refs--insert-cherry-commits ref)))
(insert ?\n)
- (magit-make-margin-overlay nil t))))
+ (magit-make-margin-overlay))))
(defun magit-refs--format-local-branches ()
(let ((lines (seq-keep #'magit-refs--format-local-branch
@@ -802,14 +802,12 @@ line is inserted at all."
"cherry" "-v" (magit-abbrev-arg) magit-buffer-upstream ref)
(if (= (point) start)
(message "No cherries for %s" ref)
- (magit-make-margin-overlay nil t)))))
+ (magit-make-margin-overlay)))))
(defun magit-refs--format-margin (commit)
- (save-excursion
- (goto-char (line-beginning-position 0))
- (if-let ((line (magit-rev-format "%cN%x00%ct" commit)))
- (apply #'magit-log-format-margin commit (split-string line "\0"))
- (magit-make-margin-overlay))))
+ (if-let ((line (magit-rev-format "%cN%x00%ct" commit)))
+ (apply #'magit-log-format-margin commit (split-string line "\0"))
+ (magit-make-margin-overlay)))
;;; _
(provide 'magit-refs)
diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el
index ebbcd7d267b..df93ae031eb 100644
--- a/lisp/magit-stash.el
+++ b/lisp/magit-stash.el
@@ -527,16 +527,12 @@ instead of \"Stashes:\"."
(magit-insert-section (stash autostash)
(insert (propertize "AUTOSTASH" 'font-lock-face 'magit-hash))
(insert " " msg "\n")
- (save-excursion
- (backward-char)
- (magit-log-format-margin autostash author date)))))
+ (magit-log-format-margin autostash author date))))
(if verified
(magit-git-wash (apply-partially #'magit-log-wash-log 'stash)
"reflog" "--format=%gd%x00%aN%x00%at%x00%gs" ref)
(insert ?\n)
- (save-excursion
- (backward-char)
- (magit-make-margin-overlay)))))))
+ (magit-make-margin-overlay))))))
;;; List Stashes