summaryrefslogtreecommitdiff
path: root/files/vim/autoload/Juliana.vim
blob: 660aa17a71b41f7dcad81a280942831ec15eb62e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
" https://github.com/neitanod/vim-clevertab

function! Juliana#Init()
  let g:Juliana#has_selection = 0
  augroup JulianaPersistAu
    autocmd ModeChanged [V\x16]*:i let g:Juliana#has_selection = 1
    autocmd InsertLeave * let g:Juliana#has_selection = 0
    " Don't trigger autocomplete until a character is typed.
    autocmd ModeChanged [nvV\x16]:i setglobal noac | autocmd InsertCharPre * setglobal ac | autocmd! InsertCharPre *
  augroup END
endfunction

function! Juliana#CompleteTab(type)
  if a:type == "START"
    let g:Juliana#stop = 0
    return ""
  endif
  if !g:Juliana#stop
    " Vanilla <Tab> if we are at the front of a line.
    if a:type == "TAB" && col(".") >= col("$") && !pumvisible()
      let g:Juliana#stop = 1
      return "\<Tab>"
    elseif a:type == "ALIGN" && !pumvisible() " Align if !pumvisible().
      let g:Juliana#stop = 1
      if g:Juliana#has_selection
        return "\<ESC>gv=i"
      else
        return "\<ESC>\<C-v>=i"
      endif
    elseif a:type == "NEXT" " If pumvisible(), goto the next result.
      let g:Juliana#stop = 1
      return "\<C-n>"
    endif
  endif
  return ""
endfunction

function! Juliana#CompleteSTab(type)
  if a:type == "PREV"
    if pumvisible() " If pumvisible(), goto the previous result.
      return "\<C-p>"
    else
      return "\<Tab>" " <S-Tab> = <Tab>
    endif
  endif
endfunction

function! Juliana#CompleteNTab(type)
  if a:type == "FOLD"
    if foldlevel(line(".")) " Toggle fold if on a fold.
      return "za"
    else
      return "\<Tab>"
    endif
  endif
endfunction