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

Case-sensitive #136

Open
aloispichler opened this issue Jul 20, 2022 · 10 comments
Open

Case-sensitive #136

aloispichler opened this issue Jul 20, 2022 · 10 comments

Comments

@aloispichler
Copy link

Here,
call lexima#add_rule({'char': '(', 'at': '\\Big\%#', 'input_after': '\Big)', 'filetype': 'tex'})
call lexima#add_rule({'char': '(', 'at': '\\big\%#', 'input_after': '\big)', 'filetype': 'tex'})
there seems to be an issue with case-sensitive comparisons, as both expand the same way.

@cohama
Copy link
Owner

cohama commented Jul 20, 2022

Try to use \c pattern and with_submatch feature, which is like

call lexima#add_rule({'char': '(', 'at': '\c\\\(big\)\%#', 'input_after': '\\\1)', 'filetype': 'tex', 'with_submatch': 1})

@aloispichler
Copy link
Author

aloispichler commented Jul 21, 2022

I did not see \c in the docs, but this works very nicely, indeed!
Now, \big( expands with \big) and \Big( with \Big). I use your trick now for the Latex environment \[…\]. Thanks!

A related issue is:

Before          Input      After            Comment
(|)             )          ()|              this works
\[…|\]          \]         \[…\]|           desired
\big(…|\big)    \big)      \big(…\big)|     desired

Overwriting the extension, as above, is the expected, natural behavior. Is there a hidden trick which does that automatically?

@cohama
Copy link
Owner

cohama commented Jul 21, 2022

\c is a vanilla vim feature, not lexima.vim's (see also :help \\c).

Yes, you do not need hidden tricks but you can write your own rules explicitly.

lexima's leave feature can be used to achieve these rules.

For example,

call lexima#add_rule({'char': '\', 'at': '\%#\\]', 'leave': ']', 'filetype': 'tex'})
call lexima#add_rule({'char': '\', 'at': '\c\%#\\big)', 'leave': ')', 'filetype': 'tex'})

These rule will work as the follows. A single char \ is better to map, but you can change the key what you like.

Before          Input      After
\[…|\]          \          \[…\]|
\big(…|\big)    \          \big(…\big)|

Note that lexima's leave rule can only apply auto input text, see :help lexima-rules-leave.

@aloispichler
Copy link
Author

aloispichler commented Jul 23, 2022

Thank you for the \c and \C – did not know them. Aligato!
Tried now to implement the norm in LaTeX:

Before   input   after
\'       |       \|'\|

where ' is the cursor position. I tried

	call lexima#add_rule({'char': '|', 'at': '\\\%#', 'input_after': ' \|', 'filetype': 'tex'})

but this does not seem to work. Perhaps an issue with special characters or escaping?

@4513ECHO
Copy link
Contributor

Using | in lexima.vim is tricky a bit. You have to use <Bar> instead of actual | in char . It is native vim's way. Please see :help map-bar. lexima.vim use char as {lhs} of :imap as we've been told before.
But in other places such as at, you have to use actual |.
Hmm, I think this should be written in the document.

@4513ECHO
Copy link
Contributor

Or, I think lexima.vim should report user-friendly error when lexima#add_rule() receive invalid char as {lhs}.

@aloispichler
Copy link
Author

aloispichler commented Jul 24, 2022

Thank you, this helps indeed :-)
So I thought that <Tab> can be used in the same way as you suggest to leave. So I tried

	call lexima#add_rule({'char': '[',     'at': '\\\%#', 'input': '[	', 'input_after': ' \]', 'filetype': 'tex'})
	call lexima#add_rule({'char': '\]',    'at': '\\\[', 'leave': ']', 'filetype': 'tex'})
	call lexima#add_rule({'char': '<Tab>', 'at': '\\\[', 'leave': ']', 'filetype': 'tex', 'input': '<Tab>'})
	call lexima#add_rule({'char': '<BS>',  'at': '\\\[\%#\\\]', 'delete': 2, 'filetype': 'tex'})

However, for this to work, there seems to be a hidden trick again…

@4513ECHO
Copy link
Contributor

How doesn't it work?
As we've told before, we have to know the difference between String and Regex. ( There is the docuemnt about type of properties in :help lexima-rules. ) Regex have to be escaped when we use some special characters, but String must not be escaped. It is taken as raw string.

@aloispichler
Copy link
Author

aloispichler commented Jul 24, 2022

I know the documentation. Here is another example, where I tried multiple variants to leave by typing <Tab> (as is the standard with UltiSnips, for example).

	call lexima#add_rule({'char': '(',     'at': '\c\\\(big\)\%#', 'input_after': '\\\1)', 'with_submatch': 1})
	call lexima#add_rule({'char': ')',     'at': '\\big(', 'leave': ')'})
	call lexima#add_rule({'char': '<Tab>', 'at': '\\big(', 'leave': ')'})
	call lexima#add_rule({'char': '<BS>',  'at': '\\big(\%#\\big)', 'delete': 5})

The snippets above insert a <Tab> on typing <Tab>, but it is supposed to leave.
So far, I did not manage to get this running and your help is highly appreciated.

@cohama
Copy link
Owner

cohama commented Jul 25, 2022

Hmm, I think this should be written in the document.
Or, I think lexima.vim should report user-friendly error when lexima#add_rule() receive invalid char as {lhs}.

Agree. In this case, it would be better to report an error.

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

3 participants