简体   繁体   English

如何将一行代码复制到REPL缓冲区并立即执行它,在Emacs中?

[英]how to copy a line of code to the REPL buffer and immediately execute it, in Emacs?

During the debugging with 2 buffers (with "editing buffer" on the left and "execution buffer" on the right) I often encounter the situation in which I need to copy one line of code from "editing buffer" to the "execution buffer" and immediately execute it (perhaps without leaving the "editing buffer!). 在使用2个缓冲区进行调试期间(左侧是“编辑缓冲区”,右侧是“执行缓冲区”)我经常遇到需要将一行代码从“编辑缓冲区”复制到“执行缓冲区”的情况。并立即执行它(可能没有离开“编辑缓冲区!)。

Does there exist a binding for that? 是否存在绑定? If not, how can I create one? 如果没有,我该如何创建一个?

It may be worth asking what language you are using and what kind or REPL. 可能值得询问您使用的是哪种语言以及使用何种语言或REPL。 For example, if you are using Slime with Common Lisp then you usually don't need to go to the actual REPL buffer to evaluate code. 例如,如果您使用Slime with Common Lisp,那么通常不需要转到实际的REPL缓冲区来评估代码。 In your code buffer you can put point at the end of a Lisp form and just do Cx Ce -- the same binding that evaluates a form in emacs-lisp-mode -- and it will evaluate it in the REPL. 在您的代码缓冲区中,您可以将点放在Lisp表单的末尾,然后执行Cx Ce - 在emacs-lisp-mode中评估表单的相同绑定 - 它将在REPL中对其进行评估。 I don't remember, but CMx probably works the same way in a Common Lisp buffer with Slime as it normally does with Emacs Lisp as well. 我不记得了,但CMx可能在使用Slime的Common Lisp缓冲区中的工作方式与通常使用Emacs Lisp一样。

At least some other modes work the same way -- in a buffer in shen-mode you can eval code the same way with an active inferior-shen session going, and I have used scheme modes that do the same thing too. 至少其他一些模式的工作方式相同 - 在shen模式的缓冲区中,你可以使用相同的方式使用相同的方式进行活动的下级会话,并且我也使用了同样的方案。 I think it's fairly standard if you have an inferior REPL going, that the corresponding language mode will re-bind those keys to evaluate forms in the REPL. 我认为如果你有一个较差的REPL,相应的语言模式将重新绑定这些键来评估REPL中的表单,这是相当标准的。

For what it may be worth... 对于它可能值得...

Selecting the line you want to execute and Cc Cr usually does the job. 选择要执行的行和Cc Cr通常可以完成这项工作。 Provided the hook s are present. 如果hook存在。

I don't know of an existing binding, but you can easily create a macro to move to the other window, yank and move back. 我不知道现有的绑定,但你可以轻松地创建一个宏来移动到另一个窗口,猛拉并向后移动。 The whole process would be: 整个过程将是:

  1. Start a macro Cx ( 启动宏Cx (
  2. Move to the other window Cx o 移动到另一个窗口Cx o
  3. Yank Cy Yank Cy
  4. Move back 1 window Cu -1 , Cx o 向后移动1个窗口Cu -1Cx o
  5. Stop macro recording Cx ) 停止宏录制Cx )
  6. Name that macro Cx Ck n yank-other-window 将宏命名为Cx Ck n yank-other-window

Next you want to save that function and bind it to a key in an ELisp file that's loaded when you start Emacs: 接下来,您要保存该函数并将其绑定到启动Emacs时加载的ELisp文件中的键:

  1. Insert the macro into a file Mx insert-kbd-macro <RET> yank-other-window <RET> 将宏插入文件Mx insert-kbd-macro <RET> yank-other-window <RET>
  2. Bind to a key (global-set-key [CM-.] 'yank-other-window) 绑定到一个键(global-set-key [CM-.] 'yank-other-window)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM