简体   繁体   English

Emacs中的Scala REPL

[英]Scala REPL in Emacs

I like to do my Scala development in Emacs, and from time to time, I use the REPL to test out snippets of code or to load and test some code I've just written. 我喜欢在Emacs中进行Scala开发,并且不时地使用REPL来测试代码片段或者加载和测试我刚刚编写的一些代码。 I'm using Scala 2.9.1, and I've noticed that when I open the REPL in a terminal buffer, things are substantially broken. 我正在使用Scala 2.9.1,我注意到当我在终端缓冲区中打开REPL时,事情基本上已经被打破了。 In particular, I am unable to remove any characters from the current line, and cannot move the cursor backward on the current line. 特别是,我无法从当前行中删除任何字符,并且无法在当前行上向后移动光标。 This is highly frustrating as any time I mistype something, I have to begin the command anew. 这是非常令人沮丧的,因为任何时候我输入错误的东西,我必须重新开始命令。 I was wondering if anyone else is having this problem using the Scala REPL under Emacs, and if anyone has a potential solution. 我想知道是否有其他人在使用Emacs下的Scala REPL时遇到此问题,并且如果有人有潜在的解决方案。

I find that rlwrap (readline wrapper) plays well with emacs' ansi-term and scala. 我发现rlwrap (readline包装器)与emacs的ansi-term和scala配合得很好。 Just call "rlwrap scala", and you'll have the usual bash line editing, as well as history, working properly. 只需调用“rlwrap scala”,您就可以正常进行bash行编辑以及历史记录。 As a bonus, your history will span multiple invocations of scala, so you won't lose everything you've typed after exiting the Scala REPL. 作为奖励,您的历史将跨越scala的多次调用,因此您不会丢失在退出Scala REPL后输入的所有内容。

If rlwrap doesn't work for you, just switching to line-mode in ansi-term (Cx Cj by default) will allow you to use emacs-style editing on the line, but without the shell niceties like history and completion. 如果rlwrap不适合你,只需在ansi-term中切换到行模式(默认为Cx Cj)就可以在行上使用emacs风格的编辑,但是没有像历史和完成这样的shell细节。

Ensime has already been mentioned, so I'll just second that as a great option if you don't mind the setup involved. 已经提到了Ensime,所以如果你不介意所涉及的设置,我会把它作为一个很好的选择。

You may install ENSIME and follow instructions . 您可以安装ENSIME按照说明操作 I don't know about your way to invoke REPL, but REPL called from ENSIME works (it allows moving the cursor backward and deleting symbols, I've checked). 我不知道你调用REPL的方式,但是从ENSIME调用的REPL工作(它允许向后移动光标并删除符号,我已经检查过)。

You could try using the ammonite repl , amm . 你可以尝试使用amm replamm I can confirm tab completion works in the emacs ansi-term . 我可以确认标签完成工作在emacs ansi-term This is true for its default mode (based on stty) or you can use JLine3 with amm . 这适用于其默认模式(基于stty),或者您可以将JLine3amm 一起使用。 Note that the Dotty (tentative Scala 3) repl, dotr , is also based on amm and also has working tab-completion in ansi-term . 请注意,Dotty(暂定Scala 3)repl, dotr也基于amm并且在ansi-term也有工作制表符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM