Emacs and Slime startup script - emacs

Every time I start work, I fire up Emacs, M-x cd to a working directory, M-x slime to start Slime, then do run (ql:quickload 'myproject) in the slime repl, (or , load-system myproject) followed by , +p myproject to switch the current package in the repl.
Lastly I run call a (start-server) in the repl to get my web server started.
I'd like for this all to be just a single Emacs keystroke or command. It's embarrassing that I have to ask this, since it's all lisp, but I can't quite figure out the interplay between Emacs and Slime here. Yet as a programmer I feel like I should automate all tedious processes - and I foresee several more steps being added to this.
I guess the tricky part is sending slime commands and then waiting for quicklisp to finish before sending the next command.
Any pointers would be appreciated!
Edit: Thanks to Svante for the C-c ~ hint, which was news to me

On the Emacs side, you can bind a key to a command than calls slime with additional arguments:
(defun my-lisp ()
(interactive)
(slime (concat "sbcl --load " <path-to-your-lisp-script>)))
And in your Lisp script, for example:
(ql:quickload :my-system)
(in-package :my-package)
(start-server)

Related

Emacs Slime - Comma doesn't work

I have emacs 24.5.1 on windows with slime installed. I am using sbcl for lisp. When I open up slime, it works, but whenever I try to use comma to invoke a command, it just enters a comma. I can't get to the slime command menu. Is there any other way to get to the command menu besides comma?
Found the solution.
When going to the slime git website, they said you should include this in your initialization file
(setq slime-contribs '(slime-fancy))
It works after adding that to init.el (equivalent of .emacs)

Cross compile on Emacs

How do I create/issue compilation command on Emacs, so I don't need to switch back and forth between it and console? My usual compilation procedure I'd like to see as Emacs command:
$ export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH
$ cd my/project
$ make CROSS_COMPILE=arm-linux-gnueabihf- all
I tried to make my own version of M-x compile command following instructions, but failed as I'm not familiar with Lisp and Emacs internals enough. Please note, that projects in question are big (i.e. kernel) with multi directories and Makefiles, so the approaches (closest Makefile, default directory etc.) described in the previous link are not a solution. Bonus points if you could bind it to a single key, like Fx key on modern IDEs.
P.S. I'm aware that there's similar question, but it's outdated and doesn't cover cross compile issue, I hope there's a better solution nowadays.
You can create a custom function that runs a specific compile command in a specific directory, like this:
(defun my-compile ()
(interactive)
(let ((default-directory "~/my/project"))
(compile "export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH && make CROSS_COMPILE=arm-linux-gnueabihf- all")))
And then bind it to some convenient key:
(global-set-key [f12] 'my-compile)
Ctrl U Meta x compile should ask you what compilation command to use. You could type make CROSS_COMPILE=arm-linux-gnueabi all
Otherwise, configure your compilation-command Emacs variable, perhaps in your ~/.emacs; and you might make that a file-local variable.
You could put in your ~/.emacs the following untested lines
(load-library "compile")
(global-set-key [f12] 'recompile)
(setq compilation-command "make CROSS_COMPILE=arm-linux-gnueabihf all")
BTW, your export PATH=... could be added e.g. in your ~/.bashrc, or you could have a shell script running that exact make with the appropriate PATH and have that script be your Emacs compilation-command (perhaps even "temporarily", i.e. just in your emacs session)

What is wrong with my emacs/slime setup (compile-and-load/eval not working)?

I can run emacs and start slime (with M-x slime). At this point I get the REPL in the inferior-lisp buffer and can run lisp there. But when I open up lisp code in another buffer none of the slime-goodness works (C-x C-e, C-c C-k etc.) and I keep seeing this in the Messages buffer (with an increasing count-number):
slime-connection: Not connected.
Polling
"/var/folders/B9/B9B5J15dH+aNt5J5gkROEk+++TI/-Tmp-/slime.3202".. (Abort with `M-x
slime-abort-connection'.) [69 times]
Makes me think slime is not connecting to the correct lisp interpreter, but since I am very new to emacs and lisp I am stuck here. My setup is:
Mac OSX Snow Leopard
GNU Emacs 23.2
emacs-starter-kit
very few customizations: arnab.el and the files under arnab/
The following is what I did to get Common Lisp and Clojure to work in the same Emacs installation, along with the excellent emacs-starter-kit. This won't let you use both at the same time (you have to restart Emacs to switch from CL to Clojure or vice versa)
I believe that the version of SLIME in ELPA is old, but works for Clojure. Newer version of SLIME won't work for Clojure. Additionally, this version of SLIME seems to be stripped down (no swank-loader.el?) and won't work with Common Lisp.
These are the steps I did to get this to work, it's just what worked for me. All of the bits are under active development, so I think breakage in this area is pretty likely.
With a fresh Emacs (no configuration at all, so move anything .emacs somewhere else for the moment) install ELPA:
http://tromey.com/elpa/install.html
From within Emacs, install the packages "slime" and "slime-repl". (M-x package-list-packages then C-s slime then i to select and x to install)
Move the files in ~/.emacs.d/elpa/slime-20100404 and ~/.emacs.d/elpa/slime-repl-20100404 to a new directory like ~/hacking/lisp/elpa-slime.
Throw out the ELPA install: $ rm -rf .emacs.d.
Now clone the emacs-starter-kit and move it to .emacs.d. I only did this with a fresh copy from technomancy's Github, so try that first if you have problems.
Get the latest SLIME with CVS:
cvs -d :pserver:anonymous:anonymous#common-lisp.net:/project/slime/cvsroot co cvs-slime
I don't think OS X comes with CVS installed, so you'll need to install it from Macports, Homebrew or something.
I put cvs-slime in ~/hacking/lisp.
Hopefully it's obvious what the Emacs Lisp below does:
(defun slime-common-lisp ()
(interactive)
(setq inferior-lisp-program "/usr/local/bin/sbcl") ; your Common Lisp impl
(add-to-list 'load-path "~/hacking/lisp/cvs-slime/") ; your SLIME from CVS directory
(require 'slime)
(slime-setup '(slime-repl))
(slime))
(defun slime-clojure ()
(interactive)
(add-to-list 'load-path "~/hacking/lisp/elpa-slime")
(require 'slime)
(slime-setup '(slime-repl))
(slime-connect "localhost" 4005))
For Clojure you'd have to start the Clojure runtime and swank-clojure on port 4005, I think using Leiningen is the approved method:
Create a new project:
$ lein new project
$ cd project
In project.clj:
(defproject newclj "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
Then:
$ lein deps
$ lein swank
Edited to add:
If you find that Paredit in the SLIME REPL is broken while using this setup, check this out:
http://www.emacswiki.org/emacs/ParEdit#toc3
At least one other potential issue with this is that, AFAICT, if you open a Common Lisp source file and then start SLIME, you won't be able to send forms from the first buffer to the SLIME buffer. So open a SLIME buffer before opening any Common Lisp source files, and it should work. This doesn't seem to apply to Clojure.
References:
emacs setup for both clojure and common lisp with slime-fancy (slime-autodoc)
https://github.com/technomancy/swank-clojure/issues/closed#issue/31/comment/544166
If u have correctly install slime in your system then better use sbcl and add the following line in your ~/.emacs
(setq inferior-lisp-program "/usr/bin/sbcl")
/usr/bin/sbcl can be different according to your sbcl installation path.

Why clojure starts with 'M-x slime' for my Aquamacs without any setup?

I have Aquamacs running on my Mac.
I installed the ESK for Aquamacs and it installs ELPA at ~/.emacs.d/elpa. With ELPA, I installed clojure-mode/clojure-est-mode/slime/slime-repl/swank-clojure.
The thing is that when I run 'M-x slime', clojure is run. Why is this? I'm curious as I don't have any setup for slime in my .emacs and even in /Users/smcho/Library/Preferences/Aquamacs Emacs/{Preferences.el, customizations.el}. I mean, I don't have (setq inferior-lisp-program "clojure") or something.
Or, does it have to do with my 'swank-clojure' installation? I see something like this at the inferior-lisp buffer.
(require 'swank.swank)
(swank.swank/ignore-protocol-version nil)
...
#ServerSocket ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=51847]
That's because of swank-clojure.el, a deprecated elisp program. Don't use it, as per my post here, on your next question. It may have bugs and thus isn't suitable to use. Use M-x slime-connect instead, after starting swank up with lein swank.
As Isaac said, swank-clojure.el sets 'slime-lisp-implementations' for clojure (in short, a way to start java with swank-clojure in classpath so that swank can be started). Then slime connects to this port and you get the repl.
The problem with this approach is that, you will need to setup classpath upfront. This gets tedious for each and every project you want to work on. So, best way is to use M-x swank-clojure-project or lein swank and then M-x slime-connect. I prefer swank-clojure-project.

How can I abort an evaluation in Clojure Box (Emacs)?

I've been caught up in long running computations lately thanks to Project Euler and I'd like to know how to abort an evaluation and return to the REPL prompt. I'm running the standard Clojure Box version of Emacs. I tried the obvious REPL > Interrupt Lisp Process and Slime > Interrupt Command but neither kill the execution and return my REPL prompt.
Hit control c twice. If you're in *slime-repl clojure* then C-c C-c will kill the process and return you to the repl prompt. If you're in the *inferior-lisp* buffer, then you'll probably kill the clojure process, meaning that you'll have to restart slime (with M-x slime). If you don't have a slime repl buffer then, M-x slime-repl should give you one. You can use this as a repl to get a few extra features (try pressing the comma and tab, and see what's available ;)
When things get really fowled you can kill your lisp instance with M-x slime-quit-lisp and then restart it with M-x slime