Send Line To Any REPL

Send the current line to the REPL, evaluate it and move to the next line. Works for lots of languages and does the right thing navigating to the next line.

If you learned this in ESS then you already love it. If you didn’t then you probably will now

(use-package eval-in-repl
  :ensure t
  :config
  (setq eir-jump-after-eval nil)
  (setq eir-always-split-script-window t)
  (setq eir-delete-other-windows t)
  (setq eir-repl-placement 'right)
  ;; ielm support (for emacs lisp)
  (require 'eval-in-repl-ielm)
  ;; for .el files
  (define-key emacs-lisp-mode-map (kbd "<C-return>") 'eir-eval-in-ielm)
  ;; for *scratch*
  (define-key lisp-interaction-mode-map (kbd "<C-return>") 'eir-eval-in-ielm)
  ;; for M-x info
  (eval-after-load "info"
    '(define-key Info-mode-map (kbd "<C-return>") 'eir-eval-in-ielm))
  ;; Shell support
  (require 'eval-in-repl-shell)
  (add-hook 'sh-mode-hook
            '(lambda()
               (local-set-key (kbd "C-<return>") 'eir-eval-in-shell)))
  ;; Version with opposite behavior to eir-jump-after-eval configuration
  (defun eir-eval-in-shell2 ()
    "eval-in-repl for shell script (opposite behavior)
This version has the opposite behavior to the eir-jump-after-eval
configuration when invoked to evaluate a line."
    (interactive)
    (let ((eir-jump-after-eval (not eir-jump-after-eval)))
      (eir-eval-in-shell)))
  (add-hook 'sh-mode-hook
            '(lambda()
               (local-set-key (kbd "C-M-<return>") 'eir-eval-in-shell2)))
  ;; racket-mode support (for Racket; if not using Geiser)
  (require 'racket-mode) ; if not done elsewhere
  (require 'eval-in-repl-racket)
  (define-key racket-mode-map (kbd "<C-return>") 'eir-eval-in-racket))

Leave a Reply

Your email address will not be published. Required fields are marked *