Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligning windows #1

Open
lerouxrgd opened this issue Jan 27, 2021 · 1 comment
Open

Aligning windows #1

lerouxrgd opened this issue Jan 27, 2021 · 1 comment

Comments

@lerouxrgd
Copy link

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 ?

@mgalgs
Copy link
Owner

mgalgs commented Jan 27, 2021

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)...

JohnC32 added a commit to JohnC32/diffview-mode that referenced this issue Mar 22, 2022
1. Add Diffview menu
2. Add diffview--next-file bound to "}" (similar to diff-mode)
3. Add diffview--prev-file bound to "{"
4. Add diffview--align-windows bound to "l". This is from issue mgalgs#1, 'Aligning Windows'. I briefly looked at trying to use align windows instead of scroll-all-mode per the comment on the issue. However, I couldn't get it work work nicely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants