rhysd/vim-operator-surround

Backslash blocks don't work well

Opened this issue · 9 comments

I would like to have a \langle ... \rangle surround for use in latex.
Hence I have defined:

let g:operator#surround#blocks = {
\ '-' : [
\   {'block': ['\langle', '\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<', '>']},
\ ] }

And the following block with vim-textobj-user:

call textobj#user#plugin('latex', {
\   'code': {'pattern': ['\\langle\>', '\\rangle\>'], 'select-a': 'a<', 'select-i': 'i<' },
\ })

This allows me to change () to \langle\rangle using sra(<.
However I cannot change back. That is sra<( beeps and does nothing.
If I change to 'block': ['\\langle', '\\rangle'] I can do sra<(,
but then the original command inserts the wrong thing \\langle\\rangle

I seems to me this could be fixed by making sure we always search literaly, rather than using regex, when changing or deleting a surround.

A workaround appears to be adding an extra surround for searching:

let g:operator#surround#blocks = {
\ '-' : [
\  {'block': ['\langle', '\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<','>']},
\  {'block': ['\\langle', '\\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': []},
\ ] }
rhysd commented

Hi.

Strings in block are used as regular expression here. So backslash must be escaped with extra backslash. I think below works.

let g:operator#surround#blocks = {
\ '-' : [
\   {'block': ['\\langle', '\\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<', '>']},
\ ] }
rhysd commented

['\\langle\>', '\\rangle\>'] may be better as you mentioned.

The problem with this one seems to be when inserting the brackets. Here it is not used as a regular expression, but inserted verbatim, right?

rhysd commented

Ah, I understood. That's true. I'll consider how to resolve this issue..

I think, if searching could be made non regular expression, that would solve it. Likely it's not really needed if this hasnthasn't been a problem before.

rhysd commented

Exactly the solution resolves this issue. However, it breaks other block definitions which rely on regular expression.
I think it is good to enable to define inserted block text explicitly as below.

let g:operator#surround#blocks = {
\ '-' : [
\   {
\     'block': ['\\langle', '\\rangle'],
\     'block_text': ['\langle', '\rangle'],
\     'motionwise': ['char', 'line', 'block'],
\     'keys': ['<', '>']},
\ ] }

What do you think?

That would certainly work :-)
I guess I just can't imagine any cases where you'd want to insert a regular
expression verbatim as a bracket.

On Fri, Oct 9, 2015, 11:03 AM Linda_pp notifications@github.com wrote:

Exactly the solution resolves this issue. However, it breaks other block
definitions which rely on regular expression.
I think it is good to enable to define inserted block explicitly as below.

let g:operator#surround#blocks = {\ '-' : [\ {\ 'block': ['\langle', '\rangle'],

\ 'block_text': ['\langle', '\rangle'],

\ 'motionwise': ['char', 'line', 'block'],\ 'keys': ['<', '>']},\ ] }

What do you think?


Reply to this email directly or view it on GitHub
#25 (comment)
.

rhysd commented

e.g. HTML tag