I use Aquamacs, and Aquamacs is pre-equipped with SLIME.
(setq inferior-lisp-program "/usr/local/bin/sbcl") #####!!!
(add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME/contrib")
(add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME")
(require 'slime)
(slime-setup)
As is asked in somewhere, I try to use Clojure by adding this code.
(add-to-list 'load-path "~/clojure/clojure-mode")
(setq inferior-lisp-program "/Users/smcho/bin/clj") ################
(require 'clojure-mode)
(setq auto-mode-alist
(cons '("\\.clj$ . clojure-mode")
auto-mode-alist))
(add-hook 'clojure-mode-hook
'(lambda ()
(define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp)))
)
I couldn't make it Clojure run with SLIME, but I'm satisfied with the current setting, the only problem is that because of the (setq inferior-lisp-program ...) code, I have to change the .emacs code depending on I use Clojure or SBCL.
Is there any way to solve this problem? Can I choose between multiple (inferior) Lisps?
Added
I could make Clojure run on Aquamacs. Please refer to Running Clojure with 'lein swank' on Aquamacs problem. Forget about the settings written above, if you want to run Aquamacs/Clojure. You need just one line, (slime-setup '(slime-repl)) and lein swank.
Sure, you can use C-u M-x slime instead of just M-x slime to have SLIME ask you for the name of the Lisp executable to be launched, with whatever is your default already filled in.
There's also a slime-lisp-implementations variable which I have configured like so:
(setq slime-lisp-implementations
`((clojure ,(swank-clojure-cmd) :init swank-clojure-init)
(sbcl ("sbcl") :coding-system utf-8-unix)))
I have to say that I just can't remember what this does for me anymore (if indeed it does anything)... Type C-h v slime-lisp-implementations to learn roughly what it's supposed to do. I seem to have to type sbcl if I want to start that, which is fine by me due to the high Clojure-to-SBCL ratio in my SLIME'ing.
Update:
I have just rediscovered M-- M-x slime (that first key is meta-minus for a negative argument), which prompts for one of the names of Lisp implementations in slime-lisp-implementations (with tab completion) and then starts the required Lisp. With the above example config, M-- M-x slime sbcl starts SBCL.
(I find this useful mostly because of how it allows one to configure more complex commands to start Lisp -- e.g. (sbcl-options ("sbcl" "--an-option" "--another-option") ...), (sbcl-clbuild ("/path/to/clbuild" "lisp") ...) -- and refer to them by name.)
Related
With this minimal init file:
(setq package-load-list '((slime t)))
(setq inferior-lisp-program "clisp")
(package-initialize)
(setq package-enable-at-startup nil)
(require 'slime)
(slime-setup)
(slime)
(find-file "~/t/del.lisp")
Everything seems to work, such as slime-eval-defun and slime-complete-symbol, except for looking up documentation. M-x slime-describe-symbol RET print RET results in this error:
CLHS-ROOT: variable *CLHS-ROOT-DEFAULT* has no value
What do I need to add in my init file to make it work?
I also tried downloading the hyperspec tar file and extracting it to a directory, and this code:
(setq package-load-list '((slime t)))
(setq inferior-lisp-program "clisp"
common-lisp-hyperspec-root "c:/run/HyperSpec/"
common-lisp-hyperspec-symbol-table "c:/run/HyperSpec/Data/Map_Sym.txt")
(package-initialize)
(setq package-enable-at-startup nil)
(require 'slime)
(slime-setup)
(slime)
(find-file "~/t/del.lisp")
That doesn't work either. I do not know if the bug is in that init file, or in the SLIME version I am using, because this is my first time with SLIME.
Versions:
MS Windows 7
Emacs version 24.3.1 (probably latest stable)
SLIME version 20130626.1151 (latest from MELPA) (One from Marmalade says it can't compile nil, I don't know what that means and so I am using one from MELPA instead)
GNU CLISP 2.49 (latest stable)
UPDATE
C-c C-d f RET print RET works fine. This is bound to slime-describe-function, which is undocumented, and not listed in SLIME menu. There is also slime-documentation-lookup which is bound to C-c C-d C-d which can open documentation for variables (not just functions) in a browser, and that works too. Looks like only `slime-describe-symbol doesn't work.
I haven't done it on Windows, but if I were you, I'd try to do this with Quicklisp: (ql:quickload "clhs") and follow the printed directions.
I'd also get SLIME from Quicklisp via (ql:quickload "quicklisp-slime-helper"), but if your slime works ok, no real need.
Assuming that SLIME is installed from an emacs package archive (preferably MELPA) (and that GNU CLISP is installed), here is combination of relevant portions from How to install Common Lisp and SLIME on MS Windows:
Assuming starting from scratch after commenting out any SLIME customization code you already have, start by putting the following code to your init file which should be evaluated after package-initialize:
(setq inferior-lisp-program "clisp")
(setq slime-auto-connect 'ask)
(defun my-slime-setup ()
(require 'slime)
(slime-setup))
(defvar my--slime-setup-done nil)
(defun my-slime-setup-once ()
(unless my--slime-setup-done
(my-slime-setup)
(setq my--slime-setup-done t)))
(defadvice lisp-mode (before my-slime-setup-once activate)
(my-slime-setup-once))
What that does is defining my-slime-setup and make sure the function runs just once if you are using SLIME that day. my-slime-setup is also a container to which you can add your own SLIME customization code.
Now to connect the downloaded documentation to SLIME, extract the downloaded archive and you will get a folder with name Hyperspec, and then you move that folder to the Emacs bin directory, or its parent directory, or its grandparent directory, Put the following code in Emacs init file.
(defun my-hyperspec-setup ()
(let ((dir (locate-dominating-file invocation-directory "HyperSpec/")))
(if dir
(progn
(setq common-lisp-hyperspec-root (expand-file-name "HyperSpec/" dir)))
(warn "No HyperSpec directory found"))))
and add my-hyperspec-setup to my-slime-setup like this:
(defun my-slime-setup ()
(my-hyperspec-setup)
(require 'slime)
(slime-setup))
and restart Emacs.
And now when you do M-x slime-describe-symbol RET print RET in a lisp buffer, it should show the description of PRINT in another buffer.
I should confess that I am sourcing from my own article and also answering my own question after about 8 months. The answer is tested with latest SLIME from MELPA and on a vanilla GNU Emacs.
According to the guide on the Internet, we can search in the HyperSpec for the symbol like "format" in emacs by typing C-c C-d h , However, I just cannot have it work, emacs just prompts that there's no completion for the symbol. Can somebody cope with it? thanks in advance!
Are you actually using the Slime REPL mode? Sometimes, when starting Slime without any configuration, you're not getting the REPL mode, and instead you'll be sitting in the *inferior-lisp* buffer.
First of all, check what the title of the buffer is. If it's *inferior-lisp*, it's not the correct one. It should read *slime-repl sbcl* (where sbcl refers to the CL implementation you're using).
If this is the case, then you need to make sure you enable slime-fancy in your Emacs init file. This is what I have:
(defun init-slime-configuration ()
(slime-setup '(slime-fancy slime-fuzzy))
(setq slime-load-failed-fasl 'never)
(define-key slime-repl-mode-map (kbd "C-<tab>") 'slime-fuzzy-complete-symbol)
(define-key slime-mode-map (kbd "C-<tab>") 'slime-fuzzy-complete-symbol))
(add-hook 'slime-load-hook 'init-slime-configuration)
This also allows me to use C-TAB for fuzzy expand.
I ran into this very problem after switching from the version of SLIME installed using Quicklisp (version 2.9) to that installed from MELPA (version 20141010.1357, as a dependency of ac-slime).
Using SLIME from Quicklisp worked fine with my local copy of the HyperSpec, using the settings:
(require 'slime-autoloads)
(add-to-list 'slime-contribs 'slime-fancy)
(setq slime-lisp-implementations
'((ccl ("ccl"))
(clisp ("clisp"))
(cmucl ("cmucl"))
(ecl ("ecl"))
(sbcl ("sbcl"))))
(setq slime-default-lisp 'sbcl)
(setq common-lisp-hyperspec-root "file:/usr/share/doc/HyperSpec/")
(setq common-lisp-hyperspec-symbol-table "file:/usr/share/doc/HyperSpec/Data/Map_Sym.txt")
I then completely removed and reinstalled Quicklisp (without reinstalling SLIME!), then installed ac-slime from MELPA using the Emacs package manager.
By chance I happened to notice that when I tried to lookup documentation in the HyperSpec, Emacs opened a hidden buffer with an empty file named "Map_Sym.txt" in it.
Looking at the full pathname of this file using C-h v buffer-file-name [RET] revealed that it was set to "/home/miki/file:/usr/share/doc/HyperSpec/Data/Map_Sym.txt".
As an experiment, I tried removing the "file:/" from the last two lines of my settings, to make them read:
(setq common-lisp-hyperspec-root "/usr/share/doc/HyperSpec/")
(setq common-lisp-hyperspec-symbol-table "/usr/share/doc/HyperSpec/Data/Map_Sym.txt")
It appears to have resolved the issue. Why this works, I don't know (it differs from the documentation). A bug or undocumented change, maybe?
SLIME
I'm pretty new to both Clojure & emacs and I've been trying to set up SLIME for Clojure. The official documentation implicitly assumes you know what your doing with emacs. There isn't just a bunch of code you can stick into your configuration files. Since I am interested in Clojure for Data Analysis, I don't really want to deal with Leiningen if at all possible, but I want the dynamic environment that slime provides.
I have installed Clojure from git in /opt/clojure/ and clojure-contrib in /opt/clojure-contrib and I can get a repl. I installed swank-clojure, clojure-mode, and slime from github in `~/.bin following this tutorial. I changed a few things around when this wasn't working by adding some stuff from the comments section of the official documentation.
When I start slime with M-x slime I get a continuous Polling "/tmp/slime.14113".. (Abort with 'M-x slime-abort-connection'.).
Here is my init-clj.el:
;; clojure-mode
(add-to-list 'load-path "~/.bin/clojure-mode")
;; swank-clojure
(add-to-list 'load-path "~/.bin/swank-clojure")
(setq swank-clojure-jar-path "/opt/clojure/clojure.jar"
swank-clojure-extra-classpaths (list
"~/.bin/swank-clojure/src/swank"
"/opt/clojure/clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar"))
(require 'swank-clojure)
;; slime
(eval-after-load "slime"
'(progn (slime-setup '(slime-repl))))
(add-to-list 'load-path "~/.bin/slime")
(require 'slime)
(eval-after-load 'slime '(setq slime-protocol-version 'ignore))
(slime-setup '(slime-repl))
(require 'clojure-mode)
(require 'clojure-test-mode)
Here is the error I get when I call it when ants.clj is open:
(progn (load "/home/kca/.bin/slime/swank-loader.lisp" :verbose t) (funcall (read- from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.14113" :coding-system "iso-latin-1-unix"))
Clojure 1.2.0-master-SNAPSHOT
user=> java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)
Inferior Lisp
I made a script in .bin/ called clj-repl that holds the java command to start a repl. I then M-x set-variable inferior-lisp-program /home/wdkrnls/.bin/clj-repl. Emacs complains its the wrong type.
The best way to use Clojure is to start by installing Leiningen.
Then install Swank Clojure as a Leiningen plugin.
Next, I'd recommend stripping your current custom Clojure setup from .emacs, and installing ELPA, and then setting up the following initialization code in your .emacs file:
;; Find this line, added by ELPA:
(require 'package)
;; and add the following expression:
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/") t)
;; ... and the rest of the ELPA init code
(package-initialize)
Then, run package-list-packages and install clojure-mode and slime (and paredit for good measure), and anything else you might want.
This should have you all set up and ready to use SLIME in (Leiningen) Clojure projects. And despite the seemingly complex procedure here, you can create a single "uberjar" from your projects to deploy on other servers with absolutely no dependency hassle.
Try the method detailed here. It takes a couple of minutes to set everything up from scratch on a clean unix or mac box:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html
I followed the instructions as best I could for installing terminal SLIME on Mac OS X, but when I press M-x it does not prompt me.
I installed emacs and Lisp using the following two sudo commands:
sudo port install emacs +carbon
sudo port install sbcl slime
I got the following instructions:
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime")
(require 'slime-autoloads)
(setq slime-lisp-implementations
`((sbcl ("/opt/local/bin/sbcl"))
(abcl ("/opt/local/bin/abcl"))
(clisp ("/opt/local/bin/clisp"))))
(add-hook 'lisp-mode-hook
(lambda ()
(cond ((not (featurep 'slime))
(require 'slime)
(normal-mode)))))
(eval-after-load "slime"
'(slime-setup '(slime-fancy slime-banner)))
Populate the initialization list in SLIME-LISP-IMPLEMENTATIONS with
the correct paths to the Common Lisp exectuables you wish to use.
I'm not sure what that last bit means...
Anyways, I've never used Lisp or emacs before, most literal n00b directed instructions would be best. Just the bare minimum to write and execute common lisp with emacs.
Thanks!
Looks like you're on the right track already. Since you've only installed sbcl, and not the other lisps, just cut your initialization code down to this:
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime")
(require 'slime-autoloads)
(setq slime-lisp-implementations `((sbcl ("/opt/local/bin/sbcl")))
(add-hook 'lisp-mode-hook
(lambda () (cond ((not (featurep 'slime)) (require 'slime) (normal-mode)))))
(eval-after-load "slime" '(slime-setup '(slime-fancy slime-banner)))
After that, use M-x slime, and you should be good to go.
I set up emacs for both clojure and common lisp, but I want also (slime-setup '(slime-fancy)) for common lisp. If I add that line to init.el, clojure won't work: it gives me repl, but it hangs after I run any code.
My configuration
For clojure:
I set up clojure-mode, slime, slime-repl via ELPA
I run $ lein swank in project directory
Then M-x slime-connect to hack clojure
For common lisp I place this after ELPA code in init.el:
(add-to-list 'load-path "~/.elisp/slime")
(require 'slime)
(add-to-list 'slime-lisp-implementations '(sbcl ("/opt/local/bin/sbcl") :coding-system utf-8-unix))
;; (slime-setup '(slime-fancy))
So if I uncomment the last line, clojure will be broken. But slime-fancy a very important meta package for hacking common lisp.
Is there a way to set them both up to work without changing configuration and restarting when I need to switch languages?
Update
I found that slime-autodoc loaded with slime-fancy is the cause of hangs.
(slime-setup '(slime-fancy))
(setq slime-use-autodoc-mode nil)
This configuration lets run both common lisp and clojure SLIMEs. Even simultaneously. But without slime-autodoc.
I also found I'm using the CVS version of SLIME since I manually do (add-to-list 'load-path "~/.elisp/slime") after ELPA code. That does not solve the problem. Maybe there is a version from some magic date which works with clojure? Here a guy says CVS version works for him: http://www.youtube.com/watch?v=lf_xI3fZdIg&feature=player_detailpage#t=221s
Here is a solution. (using hooks)
That is ugly but quite convenient.
(add-hook 'slime-connected-hook
(lambda ()
(if (string= (slime-lisp-implementation-type) "Clojure")
(setq slime-use-autodoc-mode nil)
(setq slime-use-autodoc-mode t))
))
(add-hook 'slime-mode-hook
(lambda ()
(if (eq major-mode 'clojure-mode)
(slime-autodoc-mode 0)
(slime-autodoc-mode 1))))
Update
If the problem still exists on the slime-repl buffer, try the following code:
(add-hook 'slime-repl-mode-hook
(lambda ()
(if (string= (slime-lisp-implementation-type) "Clojure")
(progn (setq slime-use-autodoc-mode nil)
(slime-autodoc-mode 0))
(progn (setq slime-use-autodoc-mode t)
(slime-autodoc-mode 1)))))
I've been contemplating on the same problem recently. The issue is that the SLIME in ELPA is trimmed down and is next to useless for Common Lisp. One way you can circumvent the problem is to check out SLIME from CVS from the same date as the checkout was done for the ELPA package and add manually the missing stuff. Someone on #clojure told me he did that and the solution worked.
I personally find such a solution pretty ugly, but until someone manages to get the Clojure support into upstream SLIME there won't be a better one.
Alternatively you can add features to the slime-setup one by one and see what feature exactly is causing the problem with the Clojure evaluation - after all slime-fancy is simply a metafeature that just loads the most popular contrib features.
Btw you don't need the lines
(add-to-list 'load-path "~/.elisp/slime/contrib")
(setq slime-backend "~/.elisp/slime/swank-loader.lisp")
(require 'slime)
The contrib dir will be added automatically to the load path, the back-end is the default and if you're using 'slime-autoloads you should require slime before that, since this defeats the purpose of the autoload.
I use sbcl, clozure, and clojure: Getting Emacs, Slime, Common Lisp (SBCL, Clozure), and Clojure to Work Together