I saw a teacher in iTunes U doing this: have 2 windows open in Emacs, the top is the Scheme (or Lisp) source code, and the bottom is the Scheme interpreter. He seems to press something on the keyboard and the whole Scheme statement will be copied down to the buffer below. How is that done?
Asked
Active
Viewed 186 times
2
-
Does he select a region in top window and just the marked text is copied or is the entire top window inserted into the bottom window? – Melioratus Dec 15 '15 at 20:17
-
I think he presses one set of keys and the current statement is copied down to window below – nonopolarity Dec 15 '15 at 23:41
1 Answers
4
Here's how to do it with vanilla Emacs commands:
- C-SPC C-M-n M-w mark the list with a region and copy it to the kill ring.
- C-x o C-y switch to other window and paste.
- C-x o switch back to the original window.
Here's how to evaluate an expression before point with geiser:
- C-x C-e calls
geiser-eval-last-sexp
.
There's no need to use the REPL window at all if you can just evaluate the expression in place.
Here's how to evaluate an expression before or after point using lispy interface to geiser
:
- e calls
lispy-eval
.
Defun for the first method
(defun copy-sexp-to-other-window ()
(interactive)
(let* ((end (save-excursion (forward-list 1) (point)))
(str (buffer-substring (point) end)))
(save-window-excursion
(other-window 1)
(insert str "\n"))))
Perhaps you'll want to remove save-window-excursion
, since you'll want to press RET in the REPL at some point.

abo-abo
- 13,943
- 1
- 29
- 43
-
(1) to (3) works... but the other method, if need to install geiser, then I might consider it because I don't know how much I will use this for. However, if I am familiar with how to do a macro on keyboard (`C-x (`), is there a way just to do a macro for step 1 to 3 and then bind it to `C-x C-e` and then save it in the emacs start up file? – nonopolarity Dec 15 '15 at 13:04
-
Geiser is a good REPL for Scheme. If you're serious about using Scheme in Emacs, you'll learn it sooner or later. I can add a simple defun that you can save, but using REPL is much better. – abo-abo Dec 15 '15 at 13:12
-
-
Doesn't Geiser have send-defun out of the box? I think the description matches that behavior. – wvxvw Dec 15 '15 at 13:24
-
@wvxvw I mentioned `geiser-eval-last-sexp` which does send-defun basically. I'm not sure if it has a function that actually copies text. – abo-abo Dec 15 '15 at 13:39
-
@abo-abo by the way, do you know of a way to go to the beginning of the statement automatically? So if the cursor is some where in the middle of the statement, then it would copy the whole thing, instead of needing us to move the cursor to the front of the statement. `backward-list` seems to not work as it moves only to the outer `(` – nonopolarity Dec 15 '15 at 17:32
-
1
-
Just looked it up at home: `C-M-x` is mapped to `geiser-eval-definition` which does almost everything except copying to the REPL (it could be useful to copy to REPL for the purpose of saving the history for example). Also, you could get the selected region a bit easier with `C-M-h` = `select-defun`. – wvxvw Dec 15 '15 at 21:46