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. 开发者_Python百科But it quickly loses sync if Iisearch-forward-regexp
or page-up/page-down. If there was a command which could "resync" then this solves my problem.- Saving current line number in a register and using that register value in
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)))))
精彩评论