diffview-mode
diffview-mode copied to clipboard
Aligning windows
The side by side windows can become unaligned depending on how we navigate the buffers.
I came up with this function to solve this:
(defun diffview-align-windows ()
(interactive)
(let ((align-to-line (line-number-at-pos))
(align-from-top (- (line-number-at-pos (point))
(line-number-at-pos (window-start)))))
(when
(cond
((string= (buffer-name (current-buffer))
diffview--minus-bufname)
(switch-to-buffer-other-window diffview--plus-bufname))
((string= (buffer-name (current-buffer))
diffview--plus-bufname)
(switch-to-buffer-other-window diffview--minus-bufname)))
(goto-char (point-min))
(forward-line (1- align-to-line))
(recenter align-from-top)
(other-window 1))))
It could be added to diffview-mode-map on a key such as l, what do you think ?
This looks great! I'd certainly take a PR.
Major bonus points if you can figure out how to replace (scroll-all-mode) with your function (I think you could do it in a post-command-hook?), in which case I don't think you'd even need the keybinding. EDIT: actually I guess you'd still need the keybinding since there's still the possibility of scrolling the buffers in a way that isn't handled by the proposed post-command-hook... So maybe we wouldn't get much out of replacing (scroll-all-mode)...