The problem: I have two buffers split side-by-side. I move to a line in the left buffer and I want to do something which moves the point in the right buffer to the same line number. For example, if I'm on line 26 in the left buffer I run a macro of some kind and voila I'm on line 26 on the right buffer.
Things I've tried which haven't worked as I liked (or at all):
scroll-all-mode
. It works if the buffers are in sync to begin with (e.g. point is on the same line number in both buffers) and if I stick to basic line movement. But it quickly loses sync if I isearch-forward-regexp
or page-up/page-down. If there was a command which could "resync" then this solves my problem.goto-line
. Saving and restoring positions always goes back to the same buffer.This piece of Emacs Lisp should do what you want:
(goto-line (line-number-at-pos) (window-buffer (next-window))
To bind it to a key sequence,
(global-set-key (kbd "C-c l")
(lambda ()
(interactive)
(goto-line (line-number-at-pos) (window-buffer (next-window)))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With