Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'*pattern*': [a, b] does not work when a and b are equal #15

Open
rbonvall opened this issue Mar 10, 2013 · 4 comments
Open

'*pattern*': [a, b] does not work when a and b are equal #15

rbonvall opened this issue Mar 10, 2013 · 4 comments

Comments

@rbonvall
Copy link

I'm creating text objects for LaTeX code. In LaTeX, inline equations can be typed \(like this\) or $like this$. I tried to create text objects for both with the following configuration:

\  'paren-math': {
\     '*pattern*': ['\\(', '\\)'],
\     'select-a': 'a\',
\     'select-i': 'i\',
\   },
\  'dollar-math': {
\     '*pattern*': ['[$]', '[$]'],
\     'select-a': 'a$',
\     'select-i': 'i$',
\   },

but only the first one worked. I also tried '*pattern*: '[$][^$]*[$]', also with no positive results.

Am I missing something? Is there another simple way to create text objects where the delimiters are the same (like the ones vim has for quoted text) without defining the selection functions?

@kana
Copy link
Owner

kana commented Mar 11, 2013

Thank you for the report. It is a known issue. See also #2.

\  'dollar-math': {
\     '*pattern*': ['[$]', '[$]'],
\     'select-a': 'a$',
\     'select-i': 'i$',
\   },

but only the first one worked. I also tried '*pattern*: '[$][^$]*[$]', also with no positive results.

select-a and select-i imply that a pair of regular expressions is given to *pattern*, while select implies that a single regular expression is given to *pattern*.
So, if you want to avoid using functions, try the following definitions instead:

\   'dollar-math-a': {
\     '*pattern*': '\$[^$]*\$',
\     'select': 'a$',
\   },
\   'dollar-math-i': {
\     '*pattern*': '\$\zs[^$]*\ze\$',
\     'select': 'i$',
\   },

But it's better to support such usage. The function to select a region for '*pattern*': [begin, end] is textobj#user#select_pair. Do you have any idea to improve it?

@rbonvall
Copy link
Author

Hi @kana,
thanks for providing a workaround. I'll take a look at the source code to see if I can fix the select_part funcion.

@kana
Copy link
Owner

kana commented Mar 16, 2013

vim-textobj-user internally uses searchpairpos() to find a region surrounded by a pair of patterns. It is a special kind of search function, because it takes care of nested structures. And it always fails if given patterns are equivalent. I looked into its implementation, and I guess that it is an intentional behavior to avoid getting stuck.

So that it seems to be necessary to implement a searchpairpos()-like function which also works fine with equivalent patterns.

@kana
Copy link
Owner

kana commented Mar 16, 2013

Perhaps it would be better to change the whole algorithm used in textobj#user#select_pair() instead of sticking to searchpairpos(). Anyway, I'll look into the problem more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants