How to run cargo from Emacs - emacs

I'm writing tests in Rust with Emacs. Is it possible to run the cargo run command of my test file in Emacs itself, rather than switching to the terminal for every build?

From your Cargo.toml file (or the project root directory), run M-x compile and then enter cargo run and then hit RET. From that same directory you can run M-x recompile.
You could bind the above to short key bindings, but you should probably investigate cargo.el.

rustic mode provides an interface to a number of cargo commands. Among other things you can build, lint, and run tests at point. In the guide Configuring Emacs for Rust development I'm describing setup and usage in detail.

Related

Clojure in VSCode, Calva messes with compile path?

So I setup a project with Lein, test and run, works fine. I open it in VSCode (where Calva is installed) and when running the same test: lein run test I get C:\Users\felix\AppData\Local\Temp\clojure-3239065182638120769.edn So there is something when I open the project in VSCode with Calva that makes Lein suddenly look for the .clj files in my Local Temp folder. How can I make it stop looking elsewhere, why could it run it fine before I opened it in VSCode?
lein test is the way to do it, here's a great write up on leiningen's test process: https://medium.com/helpshift-engineering/the-convoluted-magic-of-leiningen-test-selectors-2eb6c452dfcf
Another awesome thing is you can just run the tests in calva!
https://calva.io/test-runner/

Reloading/Recompiling/Refreshing .beam files inside a terminal

I use Eclipse and Erlide to develop in Erlang. To run the software I enter the ebin/ directory with my terminal since I don't like the console Eclipse provides. However after each change I have to exit and re-enter erl in the terminal to reload the .beam files that have been changed. Eclipse automatically generates new .beam files into the ebin/ directory after every save.
I know I can manually compile it with the c(filename) command, but that would require me to move to the src/ directory, compile the files, and move them back to the ebin/ directory. This requires a lot more work that just exiting and entering the Erlang terminal.
I have heard of makefiles, but I don't know if they can be ran from within an Erlang terminal.
The reason I don't want to exit the terminal is because I will lose my history of previous commands. If I'm using modules:methods with long names this takes a lot of typing time for each change made.
Is there any method to reload the .beam files in the current directory while in an Erlang terminal? Or is there any way to load the previous command history of the Erlang terminal?
You can use the l(Module). command in the shell which loads, or reloads, a module from the current directory into Erlang.
I would suggest something like active or sync but straightforward approach with c/1, l/1 and nl/1 works too
[edited]
Run your application from eclipse and check the node name, the default is #. Shut that down.
Start a separate erlang node with the same name. Now when running the application from eclipse that node will get used and you can use the shell in the terminal, while erlide will be able to reload beam code automatically when saving files.

What's the configuration file name for Emacs ansi-term?

I tried to create a .emacs-bash file and that works for M-x shell. But if I use the ansi-term, it appears that the .emacs-bash file is not loaded... How can I solve this?
I used M-x ansi-term and then \bin\bash.
The ~/.emacs_SHELLNAME (or ~/.emacs.d/init_SHELLNAME.sh) behaviour is special to the shell function (which, naturally, knows that you're going to be running a shell).
ansi-term is a terminal emulator. It doesn't know what kind of process you're going to be running with it, so it doesn't attempt to apply any custom config files.
If you run a shell in the terminal, that shell should apply its normal rules for config files, so I would try .bashrc for starters.
Failing that, read the bash man page to see what the rules are. Environment variables would likely come into play (and you could test for environment variables in your .bashrc to provide Emacs-specific behaviour).

Emacs + GDB + SCons + Step through Debugging

When compiling a project via a makefile using the Emacs compile command, when gdb is run on the resultant binary the application can be stepped through. However, when building using a large project with SCons, attempting to step through does not work in that Emacs doesn't seem to know which files to load or how they're related to the binary.
What does one have to do to do step through in Emacs? If Emacs can't support SCons natively then how can this be done manually; make must be using some mechanism to alert Emacs to a file's presence.
Are you sure your make and scons compile options are the same? It sounds like your scons build is lacking debug symbols (in gcc, use the -g option).
I don't use Scons. I can't help but ask if you have done the Scons IDEIntegration as given in the Working within Emacs and XEmacs section. It says Scons builds in a different directory that Emacs does not look at by default, so you have to move the files to make Emacs look at them. But that is for navigating through build error messages. I hope it works for gdb too.

How do I set up the Clojure classpath in Emacs after installing with ELPA?

I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.
I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.
What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help.
As mac says, you can use
M-x swank-clojure-project
to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.
Alternatively, if you are using leiningen, you can start that in a terminal with the command
$ lein swank
from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command
M-x slime-connect
Finally a third option which I'd recommend is to connect via Emacs/slime (with M-x slime-connect) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.
#!/bin/bash
java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"
This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway.
You want:
M-x swank-clojure-project
This adds all jars in your /lib dir.
If you want to :use a clojure file (bar.clj), in for instance /foo you would do:
(ns foo
(:use foo.bar))
Sorry I cannot help you with an answer, but maybe your question is wrong:
I myself haven't started a clojure session from within Emacs for ages. I think the better way is to describe all your dependencies in a single place (e.g. the maven pom.xml or leiningen's project.clj) and then start a swank session with those dependencies. I.e. add the swank-clojure lib to your (dev-)dependencies and then use lein swank or maven swank (not sure about the last one -- haven't used that much and not in a while) from the command line to start a swank session and use M-x slime-connect to attach to that session.
The advantage is that you get all the things in your classpath that you need -- and not more, so you cannot mistakenly use something from the repl that your final project doesn't know about.
This blog post gives a good summary how to do this right.