smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

Using sp-splice-sexp on ruby parentheses should replace parens with spaces

Open dgtized opened this issue 12 years ago • 4 comments

Currently if you hit M-s in the middle of the code below it transforms from

test(foo,bar) => testfoo,bar

Given that parentheses are optional in ruby I would expect the default transformation to leave a space where at least the beginning parentheses is to avoid joining words together. I would expect the behavior to be

test(foo,bar) => test foo,bar

I don't know if this should also apply to single quotes or strings or other braces.

dgtized avatar Dec 20 '13 09:12 dgtized

Right, better handling of parenthesis is on my todo list. Right now it's still relying on smartparens default behaviour for them, which is not correct (slurping and barfing only work in trivial cases).

This might take a while before I look into it though, with the holiday season and so on...

Jell avatar Dec 20 '13 12:12 Jell

Should be simple enough to repurpose sp--unwrap-sexp to take optional opening/closing replacement---right now it only deletes the regions occupied by the delimiters.

I'm thinking what would be a good way to specify the replacements though. I suppose it'll need a customize variable. Or maybe a pair property if the replacement with spaces isn't always correct.

So that's the question on you: is it always valid to replace the parens with spaces? Can't there be a construct where it would not make sense in ruby?

Though I think that having it as pair property would be more flexible for the future anyway.

Fuco1 avatar Dec 20 '13 14:12 Fuco1

I'd say that would be a very useful feature that would simplify the rest of the ruby config (which is already way too much complex :p)

If you can make it so that the parenthesis is replaced by "just one space", that would be super perfect and work everywhere. Bonus if it can be smart about end of line (i.e. no extra space at the end of the line).

Jell avatar Dec 20 '13 15:12 Jell

What about other types of parens as @dgtized mentioned? I think I'll make it a pair property where you can specify a cons of beg/end replacements... with some special form with tests if the replacement should occur or not.

Fuco1 avatar Dec 20 '13 15:12 Fuco1