cohama / lexima.vim

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

Mishandled Space with custom rule #39

Closed thirtythreeforty closed 8 years ago

thirtythreeforty commented 8 years ago

I tried to add the following rule:

call lexima#add_rule({'char': '<Space>', 'at': '( \+.*\%# \+)', 'leave': ' '})

This should allow me to continue typing after opening parentheses with an added space:

foo( | )

should now become

foo(  |)

instead of the stock behavior:

foo(  | )

This works fine... once. But if I have another set of parentheses with spaces anywhere in the file above the cursor, I cannot insert spaces in parentheses at all! Pressing spacebar in this file does nothing:

foo(  )
bar(|)

This is very weird. Does the regex match beyond the current line?

cohama commented 8 years ago

I could not reproduce this problem, sorry. Your vimrc is necessary to investigate the exact cause of that. But, I found out a related problem and I have fixed. Please try fix-39 branch.

thirtythreeforty commented 8 years ago

The fix-39 branch does help somewhat. Now, instead of being unable to type spaces at all, I can type spaces, but the spacing rules are not triggered. That is, with the original rules applied, pressing spacebar here:

foo(  )
bar(|)

Now results in

foo(  )
bar( |)

Better, but there's still a problem. I'll try to bisect my vimrc and see if I can nail down the reason.

thirtythreeforty commented 8 years ago

Update, with the following minimal vimrc, and with only Pathogen and Lexima.vim installed, I still have the problem I described in my previous comment.

set nocompatible

runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect()
execute pathogen#helptags()

" Extra shortcuts for lexima.vim
call lexima#add_rule({'char': ')', 'at': '(.*\%#.*)', 'leave': ')'})
call lexima#add_rule({'char': '}', 'at': '{.*\%#.*}', 'leave': '}'})
call lexima#add_rule({'char': ']', 'at': '\[.*\%#.*\]', 'leave': ']'})
" These rules trigger the bug.
call lexima#add_rule({'char': '<Space>', 'at': '( \+.*\%# \+)', 'leave': ' '})
call lexima#add_rule({'char': '<Space>', 'at': '{ \+.*\%# \+}', 'leave': ' '})
call lexima#add_rule({'char': '<Space>', 'at': '[ \+.*\%# \+]', 'leave': ' '})

This is on the fix-39 branch, commit 02efdbc140cb56f4d20362fa0f1c6522641c414a.

cohama commented 8 years ago

I could reproduce the problem thanks to your vimrc. I will try to fix it.

cohama commented 8 years ago

I found out the exact cause of the problem. Your at pattern in the last rule is treated as a collection pattern (e.g. [a-zA-Z])

Try escaping [

call lexima#add_rule({'char': '<Space>', 'at': '\[ \+.*\%# \+]', 'leave': ' '})
thirtythreeforty commented 8 years ago

Hey, thanks for the troubleshooting. I must have missed the notification, sorry for ignoring you! I'll try this when I get back to my computer.