Open Pitometsu opened 8 years ago
Any updates here? :scream_cat:
There's already implemented similar logic in https://github.com/Fuco1/smartparens/blob/6ce2f7af6d28391cc9ce7325bf1797b8b71a7910/smartparens-latex.el#L56
I don't know, there seems to be a lot of edge cases. For example in lisp you can type (foo
which would result into ( foo |)
... but maybe I just want to write (foo bar)
(no leading space). Having to hit backspace would be annoying.
I think this would have to be implemented on a case-by-case basis as per major-mode
, and even better maybe as a set of functions that users can use in their own config (so they wouldn't need to reimplement all the logic).
However it is quite simple to do so. If you specify this as a post-handler it will do what you want ("| " "SPC")
.
Here's my config for java-style docstrings
(sp-local-pair 'php-mode "/**" "*/" :post-handlers '(("| " "SPC")
(my-php-handle-docstring "RET")))
The "string syntax" for specifying these hooks is described here: https://github.com/Fuco1/smartparens/wiki/Permissions#insertion-specification
If this is universal enough for C++ we can set it up for C++, but I wouldn't do it as a global thing.
You right here, agree: spaces would be convenient only just after the first paren. Updated behaviour proposal here:
action | result |
---|---|
( => |
(\|) |
<space> => |
(_\|_) |
<space> => |
(__\|__) |
<backspace> => |
(_\|_) |
word => |
(_word\|_) |
<space> => |
(_word_\|_) |
<backspace> => |
(_word\|_) |
<backspace> x4 => |
(_\|_) |
<backspace> => |
(\|) |
For sure, there's should be some flag to enable/disable such behaviour (not sure about per-mode).
It should work even for already exist pairs with content:
action | result |
---|---|
(\| example) => |
(\|example) |
<space> => |
(_\|example_) |
<space> => |
(__\|example__) |
<backspace> x2 => |
(\|example) |
I implemented a load of my own code to achieve this. Although I'd quite happily delete my hard work to have it supported by smartparens!
The logic I ended up with was:
SPACE after open paren also inserts one before the matching end paren.
SPACE before closing paren does not insert one after matching open paren.
(foo |)
on your way to typing (foo bar)
DELETE either space (after open paren, or before close paren) removes one from the matching paren, so long as there are not fewer spaces there.
It took some experimentation to get this logic right, but I can report that it works well.
@edam Do you think your code is in state that could be contributed to smartparens? I would be happy to add a feature like this.
Obviosuly we would need to make it a bit configurable for people to at least have a way to disable it, so there would be some extra work required.
@Fuco1 it is currently implemented in terms of a loadable extension, but I would be happy to rework it in to a branch. I could do with cleaning up a few things anyway.
@edam Maybe we can ship it as an additional config that can be required or enabled by some flag. Feel free to put the code somewhere and we can have a look!
@edam is the code available somewhere, in your config or as a package / repo?
Feature request
To solve this question in right way, it should be implemented as part of
smartparens
(most adequate parentheses-drive mode).Propose next behaviour:
when smartparens-space-in-parens
(example-string\|)
<space>
=>( example-string \|)
<backspace>
=>(example-string\|)