How to enable tab completion in Scala's MainGenericRunner REPL (interactive interpreter)? - scala

I've added a REPL (read eval print loop) to may Java project1 which is build with maven. The REPL can be started with a script. The relevant parts are
declare -r GRADLE_CLASSPATH="$(gradle :minidns-repl:printClasspath --quiet |tail -n1)"
java \
-Dscala.usejavacp=true \
-classpath "${GRADLE_CLASSPATH}" \
scala.tools.nsc.MainGenericRunner \
-i minidns-repl/scala.repl
This works so far. The only thing that is missing which would make the REPL perfect is tab completion. I know from Scala that it does support this.
How can I enable it for MainGenericRunner?
1: Feel free to test the REPL:
git clone https://github.com/rtreffer/minidns.git \
&& cd minidns \
&& ./repl`
Then perform a DNS query, e.g. c.query("wikipedia.org", TYPE.A)

Although current scala repl has autocompletion feature right now it is not working very well. (that's aside the issue mentioned by som-snytt).
If you need the working completions in repl you best bet would be Ammonite REPL which also has some more features then the standard repl.
NOTE: I haven't tested tab completions in 2.11.8, but it looks like they had been rewritten from scratch and are looking very promising.

There's a known issue with the way -i is handled, that breaks completion.
There's also a fix pending, but I don't if it will get into 2.11.8, which also has an entirely new completion feature.

Related

Running scala shell script : Nothing happens

If I run the below script (saved as jarAccessTest.sh, which is an executable file) in a command line, nothing happens:
#!/bin/sh
# exec scala -classpath "/usr/local/google/home/vvasuki/sanskritnlpjava/target/sanskritnlp-1.0-SNAPSHOT.jar " "$0" "$#"
exec scala "$0" "$#"
!#
# import sanskritnlp.transliteration._;
print "hello"
I just see no output. Nothing. Command prompt does not return either.
What is happening here? I have to type Ctrl+C to stop whatever is happening.
EDIT: Using scala 2.9 in ubuntu 14.04 : http://i.imgur.com/VMYKnUX.png
Your pre-packaged version of Scala is from a long time ago and a galaxy far, far away.
You'll do better to download the latest 2.11.6 from the website.
When the scala runner runs a script, it starts a compile server process. If that process is borked, you may have to kill it or run fsc -shutdown to ask it nicely to go away.
You can try adding the -nc option to your script to eliminate that factor, i.e., scala -nc says no compile daemon.
Finally, if you're just testing your library, it's more common to run scala -cp my.jar and experiment from the REPL. Or if you are using SBT, start the console from there.
Anonymous suggests adding: "They seriously let you type anything on here"
To which I'll append the advice from the other answer, to run fsc -verbose. And note that they threaten to stop supporting fsc because it has issues which are maddening when they occur. For that reason, I prefer scala -nc for brief testing and scalac -d script.jar script.scala where script is an App.
The problem on the original computer was never really explained, though it is pointed out that use of the '-nc' flag worked.
The original problem might with the compilation daemon's ability to open a port. From the man page for fsc:
The first time it is executed, the daemon is started automatically.
On subsequent runs, the same daemon can be reused, thus resulting in a faster compilation. The tool is especially effective when repeatedly
compiling with the same class paths, because the
compilation daemon can reuse a compiler instance.
One way to check if this is the problem is to run fsc on its own with the verbose flag. For example, make a script called hello.scala with
println("Hello")
in it, and run
fsc -verbose hello.scala
If this shows the compile server unable to connect, you've identified your problem. A first thing to try in that case would be to check that your hosts file is kosher.
(I had a similar problem, and this is what I found).
you have a few changes to do on your code, mainly on the # line which is not a comment in scala.
#!/bin/sh
# exec scala -classpath "/usr/local/google/home/vvasuki/sanskritnlpjava/target/sanskritnlp-1.0- SNAPSHOT.jar " "$0" "$#"
exec scala "$0" "$#"
!#
// import sanskritnlp.transliteration._;
print ("hello\n")

How to pass multiple parameters into SBT in command line?

I am learning scala course on coursera.
The assignment can be submit like this:
$ sbt shell
> submit myemail mypassword
This works well. However, I was wondering whether I can submit in Bash directly instead of in sbt shell, I tried like this:
$ sbt submit myemail mypassword
And this
$ sbt submit "myemail mypassword"
But neither works.. Does anyone have ideas about this? Thanks!
After reading the manual, I found
$ sbt "submit myemail mypassword"
works well...

sbt: Unable to specify application configuration in mingw

I am trying to launch an application using sbt's application launcher.
This application is defined as:
#!/bin/sh
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #"/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
However, when I launch it, it gives me this error:
$ ~/bin/cs n8han/giter8
Error during sbt execution: Could not find configuration file 'C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig'. Searched:
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
However, the file is present there. So, I think it's because of some quirk in the way sbt handles mingw file path.
Does anybody know how I can get it working?
In Cygwin I used
java -jar "`cygpath -m "$HOME/.conscript/sbt-launch.jar"`" "#file:///C:/Users/cvanvranken/.conscript/n8han/conscript/cs/launchconfig" "$#"
I expect you will be able to get yours to work with something similar, perhaps this:
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/Users/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
or
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar "#file:///C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$#"
if those fail, you still definitely need to use the file:// protocol.
Also note the three directories it is searching in the error message
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/
file:/C:/Users/salil.wadnerkar/
file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/
no matter what you put in the launchconfig parameter, if it is not recognized then those directories are searched by default. So you could have gibberish in your parameter and still see the same exact error you are getting now.
you can set the launch config path relative to the .conscript folder -
java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar #n8han/conscript/cs/launchconfig "$#"

Intellij IDEA showing error on legit Scala code

I am new to Scala and IntelliJ IDEA. I am learning Lift from Simply Lift examples. I have setup my IDE as per instructions provided here. I am using Maven based approach.The Scala plugin is versioned (0.4.1084 -- latest as of June 30, 2011). IntelliJ IDEA version is 10.5.
The archetype is
-DarchetypeGroupId=net.liftweb \
-DarchetypeArtifactId=lift-archetype-blank_2.8.1 \
-DarchetypeVersion=2.3 \
-DarchetypeRepository=http://scala-tools.org/repo-releases \
-DremoteRepositories=http://scala-tools.org/repo-releases \
-DgroupId=com.company \
-DartifactId=lift_test \
-Dversion=1.0
When I started coding the Snippet and Sitemap example. I see IDE show error (and nasty wavy line below the code) at the following line
Menu.i("Info") / "info" submenus (
Menu.i("About") / "about" >> Hidden >> LocGroup("bottom"),
Menu.i("Contact") / "contact",
Menu.i("Feedback") / "feedback" >> LocGroup("bottom")
),
The error says,
Expression of type (Menu.Menuable , Menu.Menuable with Menu.withSlash,
Menu.Menuable) doesn't conform to expected type ConvertableToMenu
However, when I run a Maven > Install or Compile 'Boot.scala from IDEA they seem to run without error.
I am having hard time on getting Scala/Lift working perfectly on either of the two IDEs, IDEA and Eclipse.
Please let me know what am I missing?
I have added a bug report, you may see it here http://youtrack.jetbrains.net/issue/SCL-3429?projectKey=SCL
The plugin is still under development. Good code red and bad code green are both issues that arise in every day usage. If you want to help with the development of the plugin, please file a bug report with a short example demonstrating your issue.
http://youtrack.jetbrains.net/issues/SCL

What is the most efficient way to run programs in Emacs after M-x compile 'ing

I have started using M-x compile to compile programs in say, C.
What is the most efficient way to run the executable e.g. a.out. At the moment I'm using M-! ./a.out. Basically, what is the best code-compile-run procedure to follow?
Almost all the tutorials mention how compilation is done, but I haven't seen one which addressed this issue?
Thanks,
Samuel
I often just append the run command at the end of the build:
M-x compile RET gmake && ./a.out
The && will tell the shell to only invoke a.out when the compilation is successful.
Though I often run the program from an existing shell buffer (M-x shell), or from one of many shells that I manage with package very much like screen.
I use the extension smart-compile+, it allows you to specify
quite convenient rules depending on the name of the file/buffer you are editing.
For example, in my .emacs I specify the following rule for when running
smart-compile in a project euler file:
(add-to-list 'smart-compile-alist
'("euler.*\\.[Cc]+[Pp]*$" . "g++ -O2 -Wall -pedantic -Werror -Wreturn-type %f -lm -lgmpxx -lgmp -o ../bin/%n && time ../bin/%n")
)
First you specify the filename pattern for the rule, then the path where it should be executed, then the compile command.
In the above case, I add && time ../bin/%n to run the program directly after it has been successfully compiled.
My first choice is for interactive development; code, load files into the REPL, resolve errors (With C-x `, just as with M-x compile), and then play with the code in the REPL.
If that's not an option, I use eshell as a generic REPL. Compile, switch to eshell, run, test, repeat.
Add a rule to your makefile to compile and run your program, so M-x compile will compile and run, test, valgrind-test... whatever