Hello,
In http://thread.gmane.org/gmane.comp.version-control.git.magit/140, I
raised the issue of random cursor movement. I have found (at least
partially) the reasons. I put them here for when Marius Vollmer come
back.
1. magit-goto-next-section
the `offset' in this function is always negative and so recenter is
always called.
Log:
Try to fix recenter in magit-goto-next-section
--- a/magit.el
+++ b/magit.el
@@ -707,11 +707,12 @@ Many Magit faces inherit from this one by default."
(magit-show-commit next))
(if (not (magit-section-hidden next))
(let ((offset (- (line-number-at-pos
- (magit-section-beginning next))
- (line-number-at-pos
- (magit-section-end next)))))
- (if (< offset (window-height))
- (recenter offset)))))
+ (magit-section-end next))
+ (line-number-at-pos
+ (magit-section-beginning next)))))
+ (if (and (< window-min-height offset)
+ (< offset (window-height)))
+ (recenter (- offset))))))
(message "No next section"))))
(defun magit-prev-section (section)
2. magit-goto-previous-section
when the point is at the end of buffer, 'p' jumps to the big headings
which could be a few hundred lines back. I didn't try to fix this.
3. magit-refresh-buffer
Moving to `old-line' should be the absolute last resort. The magit
buffer contains a large number of hidden lines and in the event of
discarding items ('k'), `old-line' can point to a complete random
item and it often does.
In my fix (which is done without understanding how sectioning works
in magit), I try also recording the next section.
Log:
A hack to make magit-refresh-buffer work better
when discarding an item.
Modified magit.el
diff --git a/magit.el b/magit.el
index 7218b52..b5589d0 100644
--- a/magit.el
+++ b/magit.el
@@ -1389,16 +1389,25 @@ Please see the manual for a complete description of
Magit.
(section-line (and old-section
(count-lines
(magit-section-beginning old-section)
- (point)))))
+ (point))))
+ (old-section2 (and old-section (magit-next-section old-section)))
+ (old-path2 (and old-section2
+ (magit-section-path old-section2))))
(if magit-refresh-function
(apply magit-refresh-function
magit-refresh-args))
(magit-refresh-marked-commits-in-buffer)
- (let ((s (and old-path (magit-find-section old-path magit-top-section))))
+ (let* ((s (and old-path (magit-find-section old-path magit-top-section)))
+ (s2 (and old-path2 (magit-find-section old-path2
magit-top-section))))
(cond (s
(goto-char (magit-section-beginning s))
(forward-line section-line))
+ ;; try the next section in case of current one being
+ ;; deleted
+ (s2 (goto-char (magit-section-beginning s2)))
(t
+ ;; this should be the absolute last resort as the
+ ;; buffer contains a large number of hidden lines
(magit-goto-line old-line)))
(dolist (w (get-buffer-window-list (current-buffer)))
(set-window-point w (point)))
--
H A P P Y H O L I D A Y S!