Reputation: 718
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.
Upvotes: 1
Views: 698
Reputation: 718
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)
Upvotes: 1