Jump to content
rme

using Emacs and SLIME with Opusmodus

Recommended Posts

rme    3

If you want to use Emacs and SLIME with Opusmodus, that is possible.

 

Here are steps that work:

  1. If you haven't already done so, install Quicklisp.
  2. Evaluate (ql:quickload "quicklisp-slime-helper"). Follow its instructions and put
    (load (expand-file-name "~/quicklisp/slime-helper.el"))
    into your ~/.emacs file.
  3. Start Opusmodus, and evaluate (cl-user::start-swank). This should print something like ";; Swank started at port: 4005".
  4. Now, start your Emacs.  Type M-x slime-connect and you'll be prompted for a host (use the default, which is 127.0.0.1) and then a port. The port needs to match the port (default 4005) that was printed out earlier.
  5. You are now connected to Opusmodus. You should be able to say stuff like (list-plot '(1 2 3)) from the SLIME repl and have it work.

 

The function cl-user::start-swank basically does (load "home:quicklisp;setup") and then (ql:quickload :swank) and then (swank:create-server :port 4005 :dont-close t), so there's no magic going on there.

 

If you run into trouble, let me know and I'll try to help out.

 

Share this post


Link to post
Share on other sites

Thank you Matthew for the instructions.

All is working fine.

 

Alternatively you could put

(ql:quickload "quicklisp-slime-helper")
(cl-user::start-swank)

into the 'Quicklisp Start.lisp file which you find in the Opusmodus/Extension folder.

This way all you need to do is to start Opusmodus then Emacs and finally type M-x slime-connect

Share this post


Link to post
Share on other sites

With the setup above, Opusmodus also works from within Org Babel (http://orgmode.org/org.html#Working-with-source-code) -- in case anyone of you wants to do Literate Programming with Opusmodus :)  I like using Emacs Orgmode for writing documentation, papers, slides for classes etc., and having code "live" in your text is great. 

 

Torsten

 

Share this post


Link to post
Share on other sites

Using Opusmodus with autocompletion is fun: https://github.com/purcell/ac-slime.

 

After installing (simply with M-x package-list-packages, and then selecting ac-slime) and configuring it as described at the website link above, I additionally enforced that autocompletion is loaded whenever I load a Lisp file in Emacs with the following line in my .emacs file. 

 

(add-hook 'lisp-mode-hook (function (lambda () (auto-complete-mode 1))))

 

Best,

Torsten

Screen Shot 2017-08-26 at 15.40.55.png

Share this post


Link to post
Share on other sites

Slime provides convenient ways to access documentation, e.g., by calling describe with a shortcut (^C ^D ^D). However, for some reason calling describe on functions and variables in Clozure CL (the Lisp compiler of Opusmodus) does not show their actual documentation string (other Lisp compilers include such information).

 

So, I added that myself. If you use the Emacs+Slime interface for Opusmodus, consider putting the definitions below in a file that is automatically loaded by Opusmodus (e.g., any file in ~/Opusmodus/Extensions/). 

 

Best,

Torsten

 

;;; Extend describe output 
(defmethod describe-object :after ((thing symbol) stream)
  "Add documentation string of functions and variables at end of describe output."
  (declare (ignore stream))
  (let ((fbound (fboundp thing)))
    (when fbound
      (let ((doc (ccl::%get-documentation fbound t)))
        (when doc
          (format T "DOCUMENTATION:~%")
          (format T doc)))))
  (when (boundp thing)
    (format T "DOCUMENTATION:~%")
    (format T (ccl::%get-documentation thing 'variable)))
  )

(defmethod describe-object :after ((thing function) stream)
  (declare (ignore stream))
  (format T (ccl::%get-documentation thing t)))

 

Share this post


Link to post
Share on other sites
22 hours ago, torstenanders said:

No -- no extra setup required, only the setup above. Then you can open an Org file with Common Lisp snippets and evaluate them as explained in the Org mode doc.

 

Best,

Torsten

 

Edit: The setup can be improved by adding the following line to your ~/.emacs file. Without this added setting, you can evaluated Lisp in an Org buffer Lisp code block when opening the code block in Lisp mode (C-c '). With the addition, you can also evaluated the code blocks directly in the Org buffer with C-c C-c.

 

(require 'ob-lisp)

 

Example:

 - Start Opusmodus and Emacs and get them talking to each other as explained above

 - Open/create an Org file in Emacs and add a Lisp code block, e.g., the following

 

#+begin_src lisp
(+ 1 2)
#+end_src

 

 - Evaluate this code block by moving the cursor somewhere inside and then press C-c C-c -- the result is added to the buffer.

 - Open this code block by moving the cursor somewhere inside and then press C-c ' -- a temporary buffer in Lisp mode with the code is shown, with all bells and whistles of the Emacs Lisp environment you set up

 

For more information on code blocks, how to export them, communication between code block, the various customisations etc. see the Org manual (http://orgmode.org/org.html#Working-with-source-code). 

 

Best,

Torsten

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×