【问题标题】:Execute Scala code from within Emacs在 Emacs 中执行 Scala 代码
【发布时间】:2014-03-31 11:05:05
【问题描述】:

Scala REPL 非常适合短表达式,但多行表达式很难编辑,特别是如果某处存在语法错误,则需要逐行重新发出语句。

另一方面,Emacs scala-mode2 看起来不错,如果我可以选择缓冲区的一个区域并将其发送到 Scala REPL,然后在 minibuffer 中查看结果,那就太棒了。

这可能吗?谷歌搜索没有产生任何肯定的答案。 或者您认为这会是一个有用的功能吗?

如果我要实现这个,最好的方法是什么?我在想我可以让一个 Scala REPL 在后台运行,并通过 Emacs 的标准输入/输出与它进行交互。

【问题讨论】:

    标签: scala emacs read-eval-print-loop


    【解决方案1】:

    以防万一有人感兴趣,下面的 Emacs 脚本将评估 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)     
       )
      )
    )
    

    将上面的eval-scala函数绑定到你喜欢的快捷键,例如

    (global-set-key (kbd "C-e") 'eval-scala)
    

    【讨论】:

    • 更好用:(eval-after-load 'ensime '(define-key ensime-mode-map (kbd "") 'eval-scala))
    猜你喜欢
    • 1970-01-01
    • 2020-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2011-02-08
    相关资源
    最近更新 更多