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

Selectively enable delimitMate_expand_cr? #271

Open
demon386 opened this issue Feb 22, 2018 · 1 comment
Open

Selectively enable delimitMate_expand_cr? #271

demon386 opened this issue Feb 22, 2018 · 1 comment

Comments

@demon386
Copy link

Hi, I want to be able to enable "delimitMate_expand_cr" only for curly braces {} but not parentheses (), while keeping other functions the same for the two.

Is this possible?

@demon386 demon386 changed the title selective enable delimitMate_expand_cr? Selectively enable delimitMate_expand_cr? Feb 22, 2018
@adriaanzon
Copy link

Similarly, I wanted to enable it for >:< so HTML tags are automatically expanded when I press Return inside an empty tag. But of course I didn't want to have the other delimitMate features for the >:< pair.

I hacked the following together:

imap <silent> <expr> <CR> <SID>delimitMateCR()
imap <silent> <expr> <BS> <SID>delimitMateBS()
imap <silent> <expr> <C-h> <SID>delimitMateBS()

function! s:delimitMateCR()
  call s:temporary_matchpairs()
  return "\<Plug>delimitMateCR"
endfunction

function! s:delimitMateBS()
  call s:temporary_matchpairs()
  return "\<Plug>delimitMateBS"
endfunction

" Hack: Temporarily change delimitMate_matchpairs to make delimitMateCR and
" delimitMateBS work with more characters
function! s:temporary_matchpairs()
  if exists('s:matchpairs_timer')
    call timer_stop(s:matchpairs_timer)
  endif
  if !exists('b:delimitMate_matchpairs')
    let b:delimitMate_matchpairs = g:delimitMate_matchpairs . ',>:<'
    silent DelimitMateReload
  endif
  let s:matchpairs_timer = timer_start(100, {-> execute(['unlet! b:delimitMate_matchpairs', 'DelimitMateReload'])})
endfunction

This temporarily adds >:< to b:delimitMate_matchpairs when you press Return or Backspace.

Although this works, it would be nice if delimitMate had an option to specify the characters for delimitMateCR and delimitMateBS.

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