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

Add custom characters to be autoclosed #9

Closed
mateusbraga opened this issue Nov 13, 2014 · 10 comments
Closed

Add custom characters to be autoclosed #9

mateusbraga opened this issue Nov 13, 2014 · 10 comments

Comments

@mateusbraga
Copy link

Is it possible to allow for adding custom characters to be autoclosed by lexima?

For example, I would like to add '$' to be autoclosed when working on latex files.

@cohama
Copy link
Owner

cohama commented Nov 13, 2014

Yes, of course! Sorry but I don't know latex.
Please tell me what you want since I will give you an advice.

@mateusbraga
Copy link
Author

The rules would be the same as you already have right now for '(', ' and ".

In my case, I would add '$' to this list of custom characters and everytime I time $ I would get $|$.

@cohama
Copy link
Owner

cohama commented Nov 14, 2014

Sorry, I found a bug related '$' character.
I have fixed this bug and you can define '$' rule as follows.

" Please add below in your vimrc
call lexima#add_rule({'char': '$', 'input_after': '$', 'filetype': 'latex'})
call lexima#add_rule({'char': '$', 'at': '\%#\$', 'leave': 1, 'filetype': 'latex'})
call lexima#add_rule({'char': '<BS>', 'at': '\$\%#\$', 'delete': 1, 'filetype': 'latex'})

You will get

Before Input After
` ` $
`$ $` $
`$ $` <BS>

@mateusbraga
Copy link
Author

To get it to work I added the following to my .vimrc
autocmd BufRead,BufNewFile *.tex setlocal filetype=tex
autocmd FileType tex call lexima#add_rule({'char': '$', 'input_after': '$', 'filetype': 'tex'})
autocmd FileType tex call lexima#add_rule({'char': '$', 'at': '%#$', 'leave': 1, 'filetype': 'tex'})
autocmd FileType tex call lexima#add_rule({'char': '', 'at': '$%#$', 'delete': 1, 'filetype': 'tex'})

For anyone interested in this, see my mateusbraga/vimconfig.

Thanks!

@mateusbraga
Copy link
Author

I am reopening this because I think there is a bug in the add_rule. If I put the calls outside of the autocmd, it does not work.

Rephrasing: Adding the following lines to .vimrc does not work even when filetype=tex.:
call lexima#add_rule({'char': '$', 'input_after': '$', 'filetype': 'tex'})
call lexima#add_rule({'char': '$', 'at': '%#$', 'leave': 1, 'filetype': 'tex'})
call lexima#add_rule({'char': '', 'at': '$%#$', 'delete': 1, 'filetype': 'tex'})

But adding the lines from the previous comment work.

I think it is related to your plugin checking the filetype before it is actually set, but I don't know if that is true.

@mateusbraga mateusbraga reopened this Nov 14, 2014
@cohama
Copy link
Owner

cohama commented Nov 15, 2014

I noticed that *.tex file's filetype is plaintex.
Please try below

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

@mateusbraga
Copy link
Author

Still not working.

@cohama
Copy link
Owner

cohama commented Nov 15, 2014

Sorry, this is a bug in lexima's initialization.
I try to fix.

cohama added a commit that referenced this issue Nov 15, 2014
@cohama
Copy link
Owner

cohama commented Nov 15, 2014

I have fixed. Please try again.

@mateusbraga
Copy link
Author

Adding the following to .vimrc now works:

call lexima#add_rule({'char': '$', 'input_after': '$', 'filetype': 'tex'})
call lexima#add_rule({'char': '$', 'at': '%#$', 'leave': 1, 'filetype': 'tex'})
call lexima#add_rule({'char': '', 'at': '$%#$', 'delete': 1, 'filetype': 'tex'})

Thanks!

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