On debugging Elisp

Was playing around with Elixir, installed elixir-mode, but indentation wasn’t working.

About to give up, but took it as an opportunity to learn how to debug Elisp, and … whoa, it was effortless.

(debug-on-entry #'elixir-indent-line)

Hit Tab, and bang, right in the debugger, which is well-documented. Hit d to continue execution, see every expression being evaluated.

Decided to add some “print statements” (yes, right within the ~/.emacs.d/elpa/elixir-mode-1.0.0/ sources!), which in this case was something like

(message "Debug: cur-indent computed = `%s', current-indentation = `%s'" cur-indent (current-indentation))

Had to iterate a few times, but it was trivially (load-file ...) and hit Tab, watch the *Messages* buffer, repeat.

Turned out to be a typo, one of the calls to (setq not-indented ... was mis-spelled as (setq not-idented ...

Great, I thought, except … I found I was using an older version of the package, so the right fix here turned out to be … uninstall older version of elixir-mode, install the new one, get on with life. But heh, I still feel like I “leveled up” in my Emacs use today 😀

P.S. the original error is preserved in this marmalade mirror.

Fixing a SLIME/Swank version problem

Installing a bunch of packages willy-nilly resulted in this configuration problem for me: starting slime resulted in this frustrating error message: Versions differ (2014…) slime vs (2009…) swank

It asks you whether to continue. If you say ‘n’, sorry, no slime for you ! If you say ‘y’, no fancy slime for you; you have to be content with the Comint buffer mode

If you want to fix this, you’re going to have to fix a possible mismatch somewhere.

In my case, I ran locate swank-loader.lisp and found two instances: one under /usr/share/common-lisp/... and the other under /usr/share/emacs24/site-lisp/..., you will probably have different paths but similarly conflicting.

Running dpkg -S on the first, I found it came from the cl-swank package, so I uninstalled it.

Now, slime refused to start because it was trying to load the missing swank-loader.lisp file.

Luckily, this was simply a matter of running M-x customize-variable swank-backend and set it to the remaining path (e.g. in my case, "/usr/share/emacs24/site-lisp/google/slime/swank-loader.lisp")

After this, M-x slime worked as usual!

W3m with Emacs on OSX

Why would you want to do this? (You probably don’t :P)

In my case, I have a similar setup on a Linux box, and I like consistency, so …

  • Get w3m. I used MacPorts, you can use brew, it’s really up to you. If you’re using the former, run sudo port install w3m (assuming, of course, that you’ve installed MacPorts).

  • Get emacs-w3m: Run M-x package-install w3m (or select it from M-x list-packages)

Unfortunately, Emacs doesn’t seem to be very good with dependencies, so before installing w3m you’ll also have to manually install mew (I found this in the package repository) and apel (which I had to install the “old-fashioned” way — get this tarball, then run make and sudo make install … though if you find a better way please let me know!)

  • Now you can run M-x w3m, and you should see something like this (after navigating to google.com:

Emacs w3m
Emacs w3m

Here are a few keyboard shortcuts to get you started:

C-t T => Open a new session
g => Open URL
C-c C-s => Browse open sessions
C-c C-c => Submit form
Tab => Next link

You can navigate either using C-p, C-n, C-a, C-e or else (vim-style) using j, k, l, h.


Using AllegroCL with Emacs

One way is the SLIME way — similar to any other lisp/scheme implementation, install it, set inferior-lisp-program, add (slime-setup '(slime-fancy)) to your .emacs, and run M-x slime. Boom! Done.

There is another way, using an Emacs Lisp connection suggested by Franz (the guys who sell AllegroCL).

You’ll need to add this to your Emacs file (depending on when and what you download, your path may be slightly different):

(load-file "/Applications/AllegroCLexpress.app/Contents/Resources/eli/fi-site-init.el")

This done (and loaded), run fi:common-lisp. The first time you do this, it’ll ask you which buffer name to use (use the suggested default), the host (leave it set to the default, localhost — though this should illustrate how easy a remote session would be!), a process directory (pick some local directory, say ~/lisp/ ?) and paths to the image name and image file, which will correspond to alisp and alisp.dxl respectively, in the app’s directory.

At this point, you should see something like this:

Allegro CL  Emacs
Allegro CL Emacs

Now at this point, it’s a matter of getting comfortable in the environment. Obvious similarities to Slime include the appearance of the function’s argument list once you press space after the name of the function. It might help to think of this as a sort of combination of Slime and Paredit. So for example, C-c ] acts as a “super parenthesis”, adding as many closing parentheses as needed.

Here are a few other “helpers”:

  • M-D => Describe symbol
  • C-c i => Insert the argument list of the function
  • C-c f => Lookup the function reference in a browser (defaults to Safari on OSX)
  • C-c Tab => Autocomplete name under cursor
  • C-c ? => Apropos
  • C-c c => List callers

… and so on. Ultimately, the whole point is just to make writing, running and debugging code easier!

(Disclaimer: this isn’t necessary at all; AllegroCL comes with an IDE (though you’ll need to install X11 to use it). Since I’m used to using Emacs in general and haven’t used an IDE for a while now, this is something I prefer, but everything here is entirely a matter of personal preference!)

Solarized (everywhere!)

The black text on white background always seemed to cause me eye strain. On the other hand, the white-on-black or green-on-black seem too intense (too high-contrast) after a while, and made switching to a browser with its white background (yes, I’ve tried out the “high contrast” extension in chrome, it screws up colors too much for my taste) a jarring experience.

Then I came across Solarized (yes, late to the party, but that’s ok), and now I’ve enabled it across everything I use — which in my case happens to be a a couple of environments — OSX (terminal, emacs) and Linux (terminal(s), emacs). Here’s what I did for each:


Run M-x package-install (you might have to run M-x list-packages to refresh the list), and select solarized-theme. This assumes you have the MELPA package archive configured. If not, add this line:

(setq package-archive (("melpa" . "http://melpa.milkbox.net/packages/")))

Once the package is installed, add the following to your .emacs:

(load-theme 'solarized-dark t)

Gnome terminal

Run the following:

wget --no-check-certificate https://raw.github.com/seebi/dircolors-solarized/master/dircolors.ansi-dark
mv dircolors.ansi-dark .dircolors
git clone https://github.com/sigurdga/gnome-terminal-colors-solarized.git
cd gnome-terminal-colors-solarized


Run the following:

git clone https://github.com/coolwanglu/guake-colors-solarized.git
cd guake-colors-solarized


Download this zip file, then from the iTerm Preferences, select “Profiles -> Color -> Load Preset”, and select the theme from the solarized directory in the unzipped contents, then select the imported theme.

That’s it! Have a happy solarized rest-of-your-life !

Getting Started on OSX

Here’s what I did, though perhaps a better order of steps exists:

  • Downloaded Emacs for OSX

  • Downloaded ClozureCL from the Mac App Store.

  • Downloaded Quicklisp

  • Ran ClozureCL, then “File -> Load File …”, and selected quicklisp.lisp downloaded earlier.

  • Ran (quicklisp-quickstart:install)

  • Ran (ql:add-to-init-file) to make sure I don’t have to repeat this step again

  • Ran (ql:quickload :quicklisp-slime-helper). This downloaded SLIME and told me what to add to my .emacs:

`(load (expand-file-name “~/quicklisp/slime-helper.el”))`

  • Made a useful symlink:

  `ln -s /Applications/Clozure CL.app/Contents/MacOS/dx86cl64 ~/bin/ccl`

  • Added a reference to this in my .emacs:

`(setq inferior-lisp-program “~/bin/ccl”)`

  • Ran emacs, M-x slime works !

(or as the prompt says, “Happy hacking!”)