Autocompletion, Jump to documentation, Swank and Slime

In the prior part I stated that I would look into autocompletion and documentation lookup/jumping and that’s exactly what I’ve done and I’m happy with the results.


Autocompletion now works by way of Auto Complete Mode which really surprised me on the upside. It will accept a file of keywords per major mode that will be used for autocompletion. One for Clojure is already supplied in the download, I added one for PicoLisp.

This is the pertinent section in my zhenrik.el file (I had to rename it to make sure it’s loaded last by the starter kit):

(add-to-list 'ac-dictionary-directories "~/.emacs.d/henrik/dict")
(require 'auto-complete-config)
(setq ac-auto-start 3)
(add-to-list 'ac-modes 'picolisp-mode)
(setq ac-ignore-case t)

First we add the dictionaries folder to the list, this is the folder where we put our custom word list for PicoLisp major mode too. Then we load the default configuration and modify it by setting the autocomplete start cut off to 3 characters. Finally we add picolisp-mode to the list of autocomplete modes. It’s weird that this has to be done manually, it should be enough to simply drop the file in the dictionary folder and name it picolisp-mode to handle the connection between dictionary and major mode.

OK so now we need to hit some kind of key combination to jump to the documentation of the language construct we currently have the cursor on, in our case we have Clojure and PicoLisp, a Clojure jump is easy since the url is straightforward with the keyword at the end. This is not the case with PicoLisp as a url can look like this for instance: Note the refM part there. Below is the code that manages all this anyway:

(defun browser-jump (base-url)
 (let (myword myurl)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning) (region-end))
           (thing-at-point 'symbol)))
  (setq myurl (concat base-url myword))
  (browse-url myurl)))

(defun clojure-jump () (interactive) (browser-jump ""))

(defun picolisp-jump ()
 (let (myword myurl)
   (setq myword
         (if (and transient-mark-mode mark-active)
             (buffer-substring-no-properties (region-beginning) (region-end))
           (thing-at-point 'symbol)))
  (setq myurl (concat "" (upcase (substring myword 0 1)) ".html#" myword))
  (browse-url myurl)))


(define-key clojure-mode-map (kbd "C-M-r") 'clojure-jump)
(define-key picolisp-mode-map (kbd "C-M-r") 'picolisp-jump)

The above is a modification of Xah Lee’s original Reference Lookup which is a post on his Emacs blog.

Finally I installed Swank and Slime for Clojure which was a breeze with the help of the install instructions.

Start with lein swank in the shell and then M-x slime-connect.

C-x C-e to evaluate the current expression.

C-c C-k to evaluate the whole buffer.

M-x slime-repl-clear-buffer to potentially get rid of a lot of output in the REPL.

M-x slime-interrupt (or C-c C-c) to kill/abort a long running operation that takes too long time.

M-x run-picolisp to start an inferior picolisp repl in a buffer. Make sure you have copied picolisp/bin/picolisp to /usr/bin/picolisp first, use C-c C-l to load the current file then C-c C-e to evaluate stuff.

Related Posts

Tags: , , ,