简体   繁体   中英

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

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

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

For what it may be worth...

Selecting the line you want to execute and Cc Cr usually does the job. Provided the hook s are present.

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 (
  2. Move to the other window Cx o
  3. Yank Cy
  4. Move back 1 window Cu -1 , Cx o
  5. Stop macro recording Cx )
  6. Name that macro 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:

  1. Insert the macro into a file Mx insert-kbd-macro <RET> yank-other-window <RET>
  2. Bind to a key (global-set-key [CM-.] 'yank-other-window)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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