5

I am an Emacs and Common Lisp novice. I have successfully installed SLIME in my Emacs, but I noticed it does not have rainbow parentheses (which comes as a surprise). How do I enable this feature? Thanks in advance.

missingfaktor
  • 90,905
  • 62
  • 285
  • 365
  • Seasoned Lisp programmers would find rainbow parens to be a huge nuisance (since [parens are supposed to be "invisible"](http://mumble.net/~campbell/scheme/style.txt) (see the Parenthetical Philosophy section)), so from that point of view, the lack of rainbow parens is probably not as much of a surprise as you might think. – C. K. Young Jul 02 '12 at 13:58

1 Answers1

7

There's a Rainbow Delimiters mode over on emacswiki which might suit you - otherwise there's a bunch of other parenthesis appearance packages there as well.


Update: This worked for me.
This is probably still not as novice-friendly as it could be. I've had 20 years of on-and-off use to help me forget what being a total Emacs novice is like...

First, make sure there's an .emacs file in your home directory. C-x C-f [visit-buffer] followed by ~/.emacs and Enter should do the trick.

You also need a directory to save your elisp files in.
"~/.emacs.d/" is usually on the load-path, so using that is the easiest way to get started.
Create it if it doesn't exist.

Next, download rainbow-delimiters.el. It should go into your elisp folder from the previous step.
Type M-x byte-compile-file, followed by Return, then the path to your rainbow-delimiters.el (this step is only for efficiency).

Now enter the following in your .emacs:

(require 'rainbow-delimiters)
(add-hook 'slime-repl-mode-hook 'rainbow-delimiters-mode)

and save (C-x C-s) and restart.

(A "mode hook" is a function (or rather list of functions) that is called when Emacs switches to a specific mode.).

If you don't want to restart Emacs just to try it, you can position the cursor at the end of each expression and type C-x C-e [eval-last-sexp] (this also works in the interactive "*scratch*" buffer).

Starting slime with M-x slime after this gave me coloured parentheses.

The colour scheme is customizable; the easiest way of finding the options is M-x customize-apropos (hit Return), type rainbow (hit Return).

HTH.

Oh, and look through the built-in tutorial (C-h t) if you haven't already. Emacs has a slightly peculiar vocabulary, so reading the documentation (C-h i) now and then is good, and there's plenty of "oh, it can do that" moments in there.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • I am an Emacs novice. Google searches on the topic led me to the pages you mention, but I couldn't figure out how to get any of that work with SLIME. – missingfaktor Jul 02 '12 at 11:33
  • @missingfaktor: Did you get rainbow to work in other modes than Slime? I'm fairly sure the relevant mode hook for Slime is `slime-repl-mode-hook`, in case that's what you're missing. – molbdnilo Jul 02 '12 at 11:53
  • I lack the necessary Emacs knowledge to comprehend what you're saying. No, I haven't yet managed to get rainbow working on any other mode. Actually I have no other Lisp mode installed. – missingfaktor Jul 02 '12 at 12:00
  • @missingfaktor Did you download rainbow-delimiters.el? Did you place it in your emacs load path, if you don't know what that is, see this: http://emacswiki.org/emacs/LoadPath Once you have that file installed, following the instructions on emacs wiki should be a breeze. – anio Jul 02 '12 at 13:02
  • Thank you for the detailed steps. I followed them. Now [I am also unable to get SLIME work](http://stackoverflow.com/questions/11291428/slime-connect-not-working), so I can't tell if the rainbow parentheses feature was correctly installed. – missingfaktor Jul 02 '12 at 13:35
  • I got SLIME working. And I followed all the steps mentioned here. Yet rainbow feature isn't working for me. :( – missingfaktor Jul 03 '12 at 11:31
  • @missingfaktor: Are you sure? My rainbow colour scheme was so unsaturated that I had to squint to see it. (Of course you're sure, I just have no idea what could be going wrong.) Sorry I can't help. – molbdnilo Jul 03 '12 at 12:30
  • 1
    (Please don't hit me!) All this while I was checking the editor window. The hook however was for REPL. The rainbows were working fine on REPL. Adding `lisp-mode-hook` enabled them for main editor too. Thanks! – missingfaktor Jul 03 '12 at 13:45