can I use common lisp and Clojure from within emacs at the same time?
I would like to have each lisp-REPL in its own buffer, and If i did this how could I controll which buffer sent its data to which lisp?
Yes. In the documentation to Slime you will find slime-lisp-implementations. Here is how I have it defined in my .emacs:
(setq slime-lisp-implementations
'((cmucl ("/usr/local/bin/lisp") :coding-system iso-8859-1-unix)
(sbcl ("/usr/local/bin/sbcl" "--core" "/Users/pinochle/bin/sbcl.core-with-swank") :init (lambda (port-file _) (format "(swank:start-server %S :coding-system \"utf-8-unix\")\n" port-file)))
(clozure ("/Users/pinochle/bin/ccl"))
(clojure ("/Users/pinochle/bin/clojure") :init swank-clojure-init)))
You start up your lisps using M-- M-x Slime. It will ask you which Lisp to start up, and you use the name you defined in slime-lisp-implementations. In this example, I would use cmucl, sbcl, clozure or clojure.
You can switch the "active" REPL using the command C-c C-x c. For more info, see the Slime Documentation on controlling multiple connections.
Related
Working through SICP using Emacs, Geiser, and MIT Scheme, I decided to switch over to Racket in order to properly do the exercises in section 2.2.4 involving the Picture Language.
Configuration
I got a setup together that works for MIT Scheme and Racket using the following ~/.emacs configuration:
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(setq geiser-mit-binary "/usr/bin/scheme")
(setq geiser-racket-binary "/usr/bin/racket")
(setq geiser-active-implementations '(mit racket))
(add-to-list 'auto-mode-alist '("\\.rkt\\'" . geiser-mode))
Workflow with MIT Scheme
Here's my workflow for working with MIT Scheme:
First, I open a file (fib.scm) using emacs fib.scm. I'm asked to pick the Scheme implementation, which I answer with mit.
Second, I write my fib function, press C-c C-z to open a REPL.
Third, I switch back to the code buffer with C-x o and evaluate it using C-c C-b.
Fourth, I switch to the REPL buffer with C-x o and evaluate some expressions.
This it how it looks like:
Workflow with Racket
Here's my (intended) workflow for working with the SICP language of Racket:
First, I open a file (fib.rkt) using emacs fib.rkt. Interestingly, I'm not asked to pick a Scheme implementation.
Second, I write my fib function, but use #lang sicp in the first line. Then I open the REPL using C-c C-z.
Third, I switch back to the code buffer with C-x o and evaluate it using C-c C-b, which gives no error message, but prints => #<void> at the very bottom.
Fourth, I switch back to the REPL buffer with C-x o, where I fail to evaluate an expression like (fib 3):
2 racket#> (fib 3)
3 fib: undefined;
4 cannot reference an identifier before its definition
5 in module: top-level
6 context...:
7 body of top-level
8 /usr/share/racket/collects/racket/repl.rkt:11:26
This it how it looks like:
What am I doing wrong? Is it the configuration, is it the way I use it?
Example with sicp-pict
When I run the following code using the Racket workflow from above, the picture of Einstein is properly displayed:
#lang sicp
(#%require sicp-pict)
(paint einstein)
So my setup is not entirely broken…
Addendum
Having re-installed the geiser-racket package, I'm now able to start a REPL. I'm also able to evaluate the entire buffer using C-c C-b, which prints => #<void> to the bottom of the screen.
However, when I try to actually invoke a function, I get this error:
1 Welcome to Racket v8.6 [cs].
2 racket#> (fib 3)
3 +: contract violation
4 expected: number?
5 given: #<procedure:fib>
6 context...:
7 /usr/share/racket/collects/racket/private/norm-define.rkt:52:83: body of top-level
8 /usr/share/racket/collects/racket/repl.rkt:11:26
Edit: Oh dear, it was a simple syntax error... my bad! Everything is fine now!
To finish things up, I just post the steps I have taken to get everything to run:
Use melpa instaed of melpa-stable (~/emacs):
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
Refresh the packages after re-opening Emacs:
M-x package-refresh-contents
Install racket-mode:
M-x package-install RET racket-mode
Install the package geiser-racket:
M-x package-install RET geiser-racket
Extend your Geiser config (~/emacs):
(setq geiser-mit-binary "/usr/bin/scheme")
(setq geiser-racket-binary "/usr/bin/racket")
(setq geiser-active-implementations '(mit racket))
Start using the picture language:
#lang sicp
(#%require sicp-pict)
(paint einstein)
Open it in Emacs:
emacs ../examples/einstein.rkt
Start a Racket REPL and evaluate the whole buffer:
C-c C-z
C-x o
C-c C-b
An image of Einstein should appear.
Is there a way to see the arguments for a common lisp function and its documentation from within emacs? Or also to see a list of all available functions?
SLIME automatically loads eldoc-mode - this is the mode that displays function arguments in the minibuffer. If you mean cl library of Emacs Lisp, you can load it using M-xeldoc-mode.
Another useful SLIME feature is the C-c C-d C-d - this pops a new buffer with documentation about the function.
These are very useful too:
C-c C-w C-aslime-who-specializes
C-c C-w C-bslime-who-binds
C-c C-w C-cslime-who-calls
C-c C-w RETslime-who-macroexpands
C-c C-w C-rslime-who-references
C-c C-w C-sslime-who-sets
C-c C-w C-wslime-calls-who
C-c C-w aslime-who-specializes
C-c C-w bslime-who-binds
C-c C-w cslime-who-calls
C-c C-w mslime-who-macroexpands
C-c C-w rslime-who-references
C-c C-w sslime-who-sets
C-c C-w wslime-calls-who
It should be obvious what they do from their names.
Addidionally, there's an auto-complete plugin for SLIME which can show documentation and function arguments in a drop-down menu (well, sort of), visually similar to how Visual Studio or Eclipse do it. I think it's called ac-slime and is installable through ELPA.
You can get the documentation of a function with documentation. (Following examples for getting information about the function list.)
(documentation 'list 'function)
"Returns constructs and returns a list of its arguments."
To get the argument-list, there is typically an implementation dependent function arglist in some package. You can search this function with (apropos 'arglist). This will give you a list of all interned symbols whose names contain arglist.
For example in CMUCL it is (swank-backend::arglist 'list), in CLISP it is just (arglist 'list), etc.
N.B. If you use SLIME, you should see the available arguments below anyway.
Sort of. The manual GNU Emacs Common Lisp Emulation comes with GNU Emacs -- it is CL in the main (dir-level) Info menu. Consult the function index for the list of documented functions. But the documentation is somewhat incomplete, and it documents only the Emacs implementation, which sometimes differs from the Common Lisp spec.
Consult the Common Lisp documentation for precise info about the language.
Common Lisp Hyperspec
Common Lisp the Language, 2nd Edition
Everything below is from http://cl-cookbook.sourceforge.net/emacs-ide.html
Q2. Viewing HyperSpec from within Emacs
Q2 I like having access to the HyperSpec when I'm in Emacs, but why does it have to use an external browser? Why
can't I just see the HyperSpec in Emacs?
A2 If you use the Emacs add-on package W3 (or W3M which provides similar functionality), you can display HTML pages
inside of Emacs. Once you have W3 and the HyperSpec both installed, use code similar to the following to access the
HyperSpec from the Shift-F1 key:
(global-set-key [(shift f1)]
'(lambda ()
(interactive)
(let ((browse-url-browser-function
'browse-url-w3)
(common-lisp-hyperspec-root
"file://c:/home/docs/Hyperspec/")
(common-lisp-hyperspec-symbol-table
(concat common-lisp-hyperspec-root
"Data/Map_Sym.txt"))
(hyperspec-prog
"c:/home/site/ilisp/extra/hyperspec"))
(load-library hyperspec-prog)
(common-lisp-hyperspec
(thing-at-point 'symbol)))))
Note that the "let" in the above code sets the browse-url-browser-function to W3 for just the HyperSpec. You can
either set the variable globally (if you want to always use W3 or some other specific browser) or locally (if you
want to use a specific browser and not the default one).
I am configuring AUCTeX in emacs.
Most of the configurations are put in a LaTeX-mode-hook. When I open a main.tex file, I notice that the major mode is latex-mode and my hooked configurations are not activated. I have to M-x Tex-latex-mode to activate them. But the major-mode is still latex-mode.
(add-hook 'LaTeX-mode-hook
(lambda ()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; auctex
(setq TeX-auto-save t)
(setq TeX-parse-self t)
))
So I would like to know what is the difference of these modes and how can I turn on AUCTeX automatically when I open a *.tex file.
The modes provided by AUCTeX are listed at https://www.gnu.org/software/auctex/manual/auctex.html#Modes-and-Hooks and they are
plain-TeX-mode
LaTeX-mode
ams-TeX-mode
ConTeXt-mode
Texinfo-mode
docTeX-mode
Instead,
tex-mode
plain-tex-mode
latex-mode
slitex-mode
doctex-mode
(note the different capitalization) are the major modes provided by the TeX mode package shipped with Emacs.
If you want to open all *.tex files with AUCTeX LaTeX mode add this to your .emacs:
(add-to-list 'auto-mode-alist '("\\.tex$" . LaTeX-mode))
Actually, this shouldn't be necessary, because AUCTeX defines the tex-mode.el mode names as alias of its own modes.
TLDR: Use latex-mode or LaTeX-mode (they mean the same thing), no need to change auto-mode-alist, and use LaTeX-mode-hook for hooking into AucTeX.
Setting up AucTeX can be quite confusing, because it uses advice to override Emacs' built-in support for TeX and friends.
So, after installing AucTeX from ELPA, you should see the following in C-h f latex-mode:
This function has :override advice: ‘TeX-latex-mode’.
Same for all the other tex modes, though the list of modes that AucTeX overrides depends on the value of the TeX-modes variable.
The function LaTeX-mode is not defined in AucTeX (any more?): it's defined in core Emacs, with a cryptic comment about compatibility:
;; The following three autoloaded aliases appear to conflict with
;; AUCTeX. However, even though AUCTeX uses the mixed case variants
;; for all mode relevant variables and hooks, the invocation function
;; and setting of `major-mode' themselves need to be lowercase for
;; AUCTeX to provide a fully functional user-level replacement. So
;; these aliases should remain as they are, in particular since AUCTeX
;; users are likely to use them.
;; Note from Stef: I don't understand the above explanation, the only
;; justification I can find to keep those confusing aliases is for those
;; users who may have files annotated with -*- LaTeX -*- (e.g. because they
;; received them from someone using AUCTeX).
;;;###autoload
(defalias 'TeX-mode #'tex-mode)
;;;###autoload
(defalias 'plain-TeX-mode #'plain-tex-mode)
;;;###autoload
(defalias 'LaTeX-mode #'latex-mode)
What this all means is that, at least in 2021, you do not need to change auto-mode-alist to use AucTeX; just installing it is enough for it to override Emacs' builtin functionality.
Unfortunately, there's one last source of confusion. Even though LaTeX-mode is now mostly just a useless alias for latex-mode, it turns out that code in AucTeX that overrides latex-mode does not call latex-mode-hook (it calls LaTeX-mode-hook, which is different. So the LaTeX- variables, which are the AucTeX ones (as opposed to the lowercase ones that are builtin with Emacs), are still useful.
I am using sbcl with GNU Emacs 24.3.1 and the 2012-04-14 release of SLIME, on Arch Linux to write some Common Lisp code. When writing an expression, if I type, for example
(if
the minibuffer will display
(if TEST THEN &OPTIONAL ELSE)
Is there a mode or SLIME setting that can make the argument that I'm currently editing be highlighted in the minibuffer? For example, if I type
(if (> x y)
it would be great if
(if TEST *THEN* &OPTIONAL ELSE)
or something similar was displayed in the minibuffer.
The strange thing is that you have documentation in minibuffer with this configuration. Maybe your distribution also loads it from a different location.
Please try this config:
(setq inferior-lisp-program "/usr/bin/sbcl")
(add-to-list 'load-path "~/.emacs.d/slime-2012-04-14/")
(require 'slime)
(require 'slime-autoloads)
(slime-setup '(slime-autodoc))
It tells Emacs to load and use slime-autodoc module that displays documentation and in minibuffer and highlights it as you'd like it to be.
Maybe you'd also like to update to a more recent SLIME version (the current one in ELPA is 20130402).
I use flymake in Emacs to check code written in several languages. However, I can't see any way to use flymake on elisp itself.
I'm aware of elint-current-buffer, and byte-compile-file, which both give useful warnings about undefined variables etc. Oddly, they don't always give the same errors: for example, elint doesn't warn about (require 'cl). I've also tried auto-compile-mode (available on MELPA) but this still writes the warnings to a separate buffer.
I would really like my elisp code to be underlined when I make mistakes, as I type. How do I do this? I've configured flymake before, but that was with external programs, not Emacs itself.
The Emacs wiki has this to say about flymake for emacs lisp, though it doesn't seem very complete.
flycheck supports Emacs Lisp "out of the box", though.
Erefactor is pretty decent, and available from the wiki as well as melpa: http://www.emacswiki.org/emacs/erefactor.el
I also like to run checkdoc post-save:
(defun emagician/run-checkdoc ()
"run checkdoc on save if it is an elisp file"
(if (and (eq major-mode 'emacs-lisp-mode)
(> (length buffer-file-name)
(length package-user-dir))
(not (string= (concat package-user-dir "/")
(substring buffer-file-name 0 (+ 1 (length package-user-dir))))))
(checkdoc)))
(add-hook 'after-save-hook 'emagician/run-checkdoc)
Now there is elisp-flymake-byte-compile backend for flymake built in.
To enable add this to config:
(add-hook 'emacs-lisp-mode-hook #'flymake-mode)