1

Scala REPL is great for short expressions, but multi-line expressions are difficult to edit, especially if there some syntax error somewhere, it requires reissuing the statements line by line.

On the other hand Emacs scala-mode2 looks nice, it would be awesome if I could just select a region of the buffer and send it to Scala REPL, and see the results in a minibuffer.

Is this possible? Googling didn't produce any positive answer. or do you think this would be an useful feature?

If I were to implement this, what would be the best approach? I was thinking that I could just have a Scala REPL running in the background and interacting with it via std in/out from Emacs.

1 Answer 1

1

Just in case anyone is interested, the below Emacs script will evaluate the region in the Scala REPL.

(defun eval-scala (start end)
  (interactive (list (point) (mark)))
  ;; start scala if it hasn't started yet
  (unless (get-process "scala-repl")
    (let ((process-connection-type nil))  ; use a pipe
      (start-process "scala-repl" "*scala*"  "scala"))
    (set-buffer "*scala*")
    (special-mode)
    )  
  ;; execute
  (process-send-region "scala-repl" start end)
  (process-send-string "scala-repl" "\n")
  ;;display buffer
  (display-buffer 
   (get-buffer "*scala*")
   '((display-buffer-reuse-window
      display-buffer-pop-up-window
      display-buffer-pop-up-frame)
     (reusable-frames . 0)
     (window-height . 8) (window-width . nil)     
   )
  )
)

Bind the above eval-scala function to your preferred short-cut key, e.g.

(global-set-key (kbd "C-e") 'eval-scala)
Sign up to request clarification or add additional context in comments.

1 Comment

Far better to use: (eval-after-load 'ensime '(define-key ensime-mode-map (kbd "<C-return>") 'eval-scala))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.