53

I would like rainbow parens for editing Clojure in Emacs and since VI does this I assume that in Emacs it should be something like M-x butterfly or something :)

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284

3 Answers3

63

This is an old question now, but I recently wrote RainbowDelimiters mode for this. It's a 'rainbow parens'-type mode which colors all parens, brackets and braces, made with Clojure programming in mind.

It highlights the whole buffer, not just the parens surrounding point.

The most important thing is that it's FAST - all the other rainbow paren modes I've tried slow down editing (especially scrolling) quite a lot. I put significant effort into profiling and optimizing it so doesn't have any noticeable impact on scrolling/editing speed.

You can find info about it at the EmacsWiki page, and the mode itself is at rainbow-delimiters.el.

Brian Burns
  • 20,575
  • 8
  • 83
  • 77
Jeremy Rayman
  • 820
  • 10
  • 7
23

I'm using highlight-parentheses-mode from the script mquander mentioned. It doesn't provide much of a rainbow effect out of the box, but it is customisable:

(setq hl-paren-colors
      '(;"#8f8f8f" ; this comes from Zenburn
                   ; and I guess I'll try to make the far-outer parens look like this
        "orange1" "yellow1" "greenyellow" "green1"
        "springgreen1" "cyan1" "slateblue1" "magenta1" "purple"))

I believe I've lifted the actual colours from Vimclojure. Note that Vimclojure highlights all parentheses in the file, whereas with highlight-parentheses-mode only the parens which actually contain the point will be highlighted (and only a limited number of levels). I happen to find this behaviour useful, but it is perhaps a bit lacking in the prettiness area in comparison with the Vimclojure way.

I now notice I've never gotten 'round to fixing those outer paren colours actually... Maybe I will now that you've reminded me about it.

Michał Marczyk
  • 83,634
  • 13
  • 201
  • 212
  • Gorgeous. I really like this. Thanks you. Is there a way to turn it on automatically for any lisp file? – John Lawrence Aspden Mar 10 '10 at 15:40
  • 1
    Glad to hear that. :-) And yes, you can include it in the default setup for Lisp editing by placing something like `(add-hook 'clojure-mode-hook (lambda () (highlight-parentheses-mode t) (paredit-mode t)))` in your `~/.emacs`. You can do the same thing with `slime-repl-mode-hook`, `emacs-lisp-mode-hook` etc., although in that case you'll probably want to factor out the `lambda` to a named function and use something like `(add-hook 'clojure-mode-hook #'my-lisp-setup)`. – Michał Marczyk Mar 10 '10 at 20:34
  • 5
    Um, somehow `paredit` slipped in there... Which is ok, as that is the Holy Grail of Lisp editing. Every Lisper needs to try it out, and if you're already using Emacs it's an *absolute must*. – Michał Marczyk Mar 10 '10 at 20:36
  • Awesome. Thank you very much! I wish I could upvote you again. – John Lawrence Aspden Mar 11 '10 at 13:27
  • The parentheses are too narrow(default), and you have to be in that code block. [rainbow-delimiters](https://github.com/Fanael/rainbow-delimiters) is recommended, the colors of parentheses are more distinct. – CodyChan Nov 28 '14 at 08:01
2

Here's a mode for that which I have used in the past briefly. Here's another one which I haven't tried.

mqp
  • 70,359
  • 14
  • 95
  • 123