cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
996 stars 46 forks source link

Add custom characters to be autoclosed #9

Closed mateusbraga closed 9 years ago

mateusbraga commented 9 years ago

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 commented 9 years ago

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

mateusbraga commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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.

cohama commented 9 years ago

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 commented 9 years ago

Still not working.

cohama commented 9 years ago

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

cohama commented 9 years ago

I have fixed. Please try again.

mateusbraga commented 9 years ago

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!