在一个缓冲区中将点移动到与不同缓冲区中的点相同的行号 [英] Move point in one buffer to the same line number as the point in a different buffer

查看:96
本文介绍了在一个缓冲区中将点移动到与不同缓冲区中的点相同的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我有两个缓冲区分开并排。我移动到左侧缓冲区中的一行,并且我想要执行某些,将正确的缓冲区中的点移动到相同的行号。例如,如果我在左侧缓冲区中的第26行,我运行一些宏,瞧我在正确的缓冲区上的第26行。

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-模式。如果缓冲区同步开始(例如,两个缓冲区中的位置在同一行号上),并且如果我坚持基本行移动,它将起作用。但是,如果我 isearch-forward-regexp 或者page-up / page-down,它会很快失去同步。如果有一个可以重新同步的命令,那么这解决了我的问题。

  • 将当前行号保存在寄存器中,并在 goto-line 。保存和恢复位置总是回到相同的缓冲区。

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

推荐答案

这块Emacs Lisp应该做你想要的:

This piece of Emacs Lisp should do what you want:

(goto-line (line-number-at-pos) (window-buffer (next-window))

要绑定到一个键序列,

(global-set-key (kbd "C-c l")
  (lambda ()
    (interactive)
    (goto-line (line-number-at-pos) (window-buffer (next-window)))))

这篇关于在一个缓冲区中将点移动到与不同缓冲区中的点相同的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆