Trailing parens

41 views
Skip to first unread message

Chris Ford

unread,
Nov 24, 2013, 2:11:59 PM11/24/13
to vimcl...@googlegroups.com
Hi all,

I regularly refactor Clojure forms and then tidy them with =ip. This works great for handling indentation, but there's one thing that it misses that keeps catching me out.

Following what I believe to be good Clojure style, this...

(defn foo [x]
  (+ x 1)
)

should become...

(defn foo [x]
  (+ x 1))

Is there any way to tidy up trailing parentheses? Is there a command other than = I should be using?

Cheers,

Chris

PS I'm using Fireplace, but I assume this behaviour is controlled by the static files.


guns

unread,
Nov 24, 2013, 2:26:56 PM11/24/13
to vimcl...@googlegroups.com, Chris Ford
On Sun 24 Nov 2013 at 10:11:59PM +0300, Chris Ford wrote:
> Hi all,
>
> I regularly refactor Clojure forms and then tidy them with *=ip*. This
> works great for handling indentation, but there's one thing that it misses
> that keeps catching me out.
>
> Following what I believe to be good Clojure style, this...
>
> (defn foo [x]
> (+ x 1)
> )
>
> should become...
>
> (defn foo [x]
> (+ x 1))
>
> Is there any way to tidy up trailing parentheses? Is there a command other
> than *= *I should be using?

People generally use plugins that offer balanced bracket insertion such
as paredit.vim or vim-sexp¹.

It sounds like you might like the "electric-return" feature from
paredit.vim.

If you just want to manually join the bracket on the next line, you can
always use vim's join-lines command: J

Unfortunately, Vim unhelpfully adds a space when joining ] and }. There
may be a plugin to fix that, but I opted to patch vim instead. (patch
attached)

HTH

guns

¹ This is an S-Expression plugin that I wrote earlier in the year. It
differs philosophically from paredit.vim (text objects vs. emacs style
editing), but they both offer balanced bracket insertion for Clojure.
join.patch

Chris Ford

unread,
Nov 24, 2013, 2:54:15 PM11/24/13
to guns, vimcl...@googlegroups.com, Chris Ford
Thanks for the J tip. I didn't know about it, and it makes fixing the problem when it occurs much easier.

I do actually use paredit.vim and I'm very happy with it. However, unless I've misunderstood your mail, it doesn't offer a way to recover from a trailing paren once you've created one.

True, when I use paredit.vim, I don't create trailing parens as I make the fn. However, once I start messing around with it, deleting and moving stuff, I often end up with trailing parens as collateral damage. Is there any command that I can apply to a paragraph that will format it according to default Clojure conventions?

Cheers,

Chris

guns

unread,
Nov 24, 2013, 3:02:22 PM11/24/13
to Chris Ford, vimcl...@googlegroups.com
On Sun 24 Nov 2013 at 10:54:15PM +0300, Chris Ford wrote:

> True, when I use paredit.vim, I don't create trailing parens as I
> make the fn. However, once I start messing around with it, deleting
> and moving stuff, I often end up with trailing parens as collateral
> damage. Is there any command that I can apply to a paragraph that will
> format it according to default Clojure conventions?

I don't think an formatting plugin exists ATM, but there has been
interest in creating one. I imagine this would be exposed as an nREPL
function if it ever happens.

guns

Chris Ford

unread,
Nov 24, 2013, 3:22:56 PM11/24/13
to guns, Chris Ford, vimcl...@googlegroups.com
Thanks for your help. Joining lines goes a long way to remove the annoyance anyway.

Chris
Reply all
Reply to author
Forward
0 new messages