1

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?

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

Here's how to do it with vanilla Emacs commands:

  1. C-SPC C-M-n M-w mark the list with a region and copy it to the kill ring.
  2. C-x o C-y switch to other window and paste.
  3. C-x o switch back to the original window.

Here's how to evaluate an expression before point with geiser:

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

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

  • (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
  • oh I am interested in knowing that defun... – nonopolarity Dec 15 '15 at 13:16
  • Doesn't Geiser have send-defun out of the box? I think the description matches that behavior. – wvxvw Dec 15 '15 at 13:24
  • 1
    beginning-of-defun – abo-abo Dec 15 '15 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.