views:

1301

answers:

2

Hello StackOverflowers, 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 :)

+1  A: 

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

mquander
+16  A: 

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
Gorgeous. I really like this. Thanks you. Is there a way to turn it on automatically for any lisp file?
John Lawrence Aspden
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
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
Awesome. Thank you very much! I wish I could upvote you again.
John Lawrence Aspden