tmsvg / pear-tree

A Vim auto-pair plugin that supports multi-character pairs, intelligent matching, and more
MIT License
392 stars 12 forks source link

Detect comments for smart openers and smart closers #26

Closed bryclee closed 5 years ago

bryclee commented 5 years ago

I've noticed that the smart openers and smart closers don't quite work when there is an unpaired paren or bracket within a comment. For example:

// :( <- miscellaneous unpaired paren inside a comment

test(|)

I'd expect if I were to press ), that the cursor would then move to

test()|

Is it possible to ignore comments when deciding whether to use the smart closers or not?

tmsvg commented 5 years ago

Use the 'not_in' option in your pair rules:

let g:pear_tree_pairs = {
            \ '(': {'closer': ')', 'not_in': ['Comment']},
            \ '{': {'closer': '}', 'not_in': ['Comment']}
            " etc.
            \ }
bryclee commented 5 years ago

Hm... I tested this out with a minimal configuration but it still wasn't producing what I was hoping for.

In the above example, I was hoping to end up with the cursor like test()|, but instead I got test()|)

I'm using these settings:

Plug 'tmsvg/pear-tree'
let g:pear_tree_repeatable_expand = 0
let g:pear_tree_smart_openers = 1
let g:pear_tree_smart_closers = 1
let g:pear_tree_smart_backspace = 1
let g:pear_tree_pairs = {
            \ '(': {'closer': ')', 'not_in': ['Comment']},
            \ '{': {'closer': '}', 'not_in': ['Comment']},
            \ '[': {'closer': ']', 'not_in': ['Comment']}
            \ }
tmsvg commented 5 years ago

I should have mentioned, https://github.com/tmsvg/pear-tree/commit/4f3bc71e979a7ad743eb789aaaf8c23447cb44e7 fixed an issue that would have prevented this particular example from working. Try updating and see if it works.

bryclee commented 5 years ago

Thanks! After updating, this is working.