LucHermitte / lh-brackets

LH's bracketing system for vim
Other
50 stars 2 forks source link

How make some brackets be completed even in string literals? #11

Closed alientechnology closed 7 years ago

alientechnology commented 7 years ago

As i see by default brackets not working inside string literals and comments, how to overcome this for some file types and brackets? Let's say i want { } for in string literals for rust.

LucHermitte commented 7 years ago

Currently I support the exact contrary with -context option.

For instance, if you add in a rust ftplugin:

Brackets { } -context=string
Brackets { } -context=string -visual=0 -trigger=µ

then { will expand only within string context, and µ will expand into {<cursor>} within strings.

In other words, I have to implement what you're looking for.

I guess I will add a -context!= option

alientechnology commented 7 years ago

Yeah, I see, but i don't get how to make it explain into {}<cursor> within string context, and into {<cursor>} in other contexts? When i add Brackets { } -context=string it looks like default Brackets { } stops to work. How can i look all contexts available for binding? Thanks.

LucHermitte commented 7 years ago

OK. I misunderstood what you were looking for. There is a very tricky (and undocumented) way then to achieve it.

" in case you reload your ft plugin, and if the default global insert-mode mapping for `{` is correct in your context
:silent! iunmap <buffer> {
:call lh#brackets#define_imap('{', [
  \ {'condition' : 'lh#syntax#name_at_mark(".") =~? "string"', 'action': '"{}"'},
  \ {'condition': 1, 'action':maparg('{', 'i')}],
  \ 1)

The first condition defines what to do within strings. The second conditions (which expresses the default action) executes the insert mode mapping already registered (here, the one :Brackets { } defines.

LucHermitte commented 7 years ago

Fixed by 2b14091a6a3fb4918d6aeb5deb3fec22a2ab948c