Skip to content

Commit 0e21582

Browse files
committed
add command line #362
1 parent 0087124 commit 0e21582

File tree

6 files changed

+79
-3
lines changed

6 files changed

+79
-3
lines changed

autoload/easycomplete.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,9 +2806,15 @@ function! easycomplete#BackToOriginalBuffer()
28062806
endfunction
28072807

28082808
function! easycomplete#CmdlineEnter()
2809+
call easycomplete#cmdline#enter()
28092810
endfunction
28102811

28112812
function! easycomplete#CmdlineLeave()
2813+
call easycomplete#cmdline#leave()
2814+
endfunction
2815+
2816+
function! easycomplete#CmdlineChanged(pfx)
2817+
call easycomplete#cmdline#changed(a:pfx)
28122818
endfunction
28132819

28142820
function! easycomplete#Textchanged()

autoload/easycomplete/cmdline.vim

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
let g:easycomplete_cmdline_typing = 0
3+
4+
function! easycomplete#cmdline#changed(pfx)
5+
return
6+
try
7+
let item_list = s:normalize(["abc","aaa","aaaasf","asdfsefd","asssfd","aaaas","bsd","aadsfafafaf"])
8+
let word = s:GetTypingWord()
9+
call s:console("x", getcmdpos(), strlen(word))
10+
let start_col = getcmdpos() - strlen(word)
11+
call easycomplete#pum#complete(0, item_list)
12+
catch
13+
echom v:exception
14+
endtry
15+
endfunction
16+
17+
function! easycomplete#cmdline#enter()
18+
let g:easycomplete_cmdline_typing = 1
19+
endfunction
20+
21+
function! easycomplete#cmdline#leave()
22+
let g:easycomplete_cmdline_typing = 0
23+
endfunction
24+
25+
function! easycomplete#cmdline#typing()
26+
return v:false
27+
if !exists("g:easycomplete_cmdline_typing")
28+
let g:easycomplete_cmdline_typing = 0
29+
endif
30+
return g:easycomplete_cmdline_typing
31+
endfunction
32+
33+
function! s:GetTypingWord()
34+
let line = getcmdline()
35+
let pos = getcmdpos() - 1
36+
37+
if pos < 0
38+
return ''
39+
endif
40+
41+
let start_pos = pos
42+
while start_pos > 0 && line[start_pos - 1] =~ '\k'
43+
let start_pos -= 1
44+
endwhile
45+
46+
return line[start_pos:pos+1]
47+
endfunction
48+
49+
function! s:normalize(list)
50+
let new_list = []
51+
for item in a:list
52+
call add(new_list, {
53+
\ "word":item,
54+
\ "abbr":item,
55+
\ "kind":'c',
56+
\ "menu":"p"
57+
\ })
58+
endfor
59+
return new_list
60+
endfunction
61+
62+
function! s:console(...)
63+
return call('easycomplete#log#log', a:000)
64+
endfunction

autoload/easycomplete/log.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function! easycomplete#log#log(...)
8080
call call(s:log, a:000)
8181
endif
8282
call s:GotoOriginalWindow()
83+
redraw
8384
endfunction
8485

8586
function! s:GotoBottom()

autoload/easycomplete/pum.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ function! s:OpenPum(startcol, lines)
190190
call s:InitBuffer(a:lines)
191191
let buffer_size = s:GetBufSize(a:lines)
192192
let pum_pos = s:ComputePumPos(a:startcol, buffer_size)
193+
if easycomplete#cmdline#typing()
194+
let pum_pos.row = &window
195+
endif
193196
let pum_opts = deepcopy(s:default_pum_pot)
194197
call extend(pum_opts, pum_pos)
195198
if empty(s:pum_window)

plugin/easycomplete.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ augroup easycomplete#NormalBinding
584584
autocmd CursorMovedI * call easycomplete#CursorMovedI()
585585
autocmd CmdlineEnter * noa call easycomplete#CmdlineEnter()
586586
autocmd CmdlineLeave * noa call easycomplete#CmdlineLeave()
587+
autocmd CmdlineChanged : noa call easycomplete#CmdlineChanged(":")
588+
autocmd CmdlineChanged @/ noa call easycomplete#CmdlineChanged("/")
587589
autocmd BufLeave * noa call easycomplete#BufLeave()
588590
if has("nvim")
589591
autocmd WinScrolled * noa call easycomplete#WinScrolled()

snippets/vim.snippets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ snippet guard script reload guard
99
endif
1010
let $1 = 1${0}
1111
snippet f function
12-
fun! ${1:`expand('%') =~ 'autoload' ? substitute(matchstr(expand('%:p'),'autoload/\zs.*\ze.vim'),'[/\\]','#','g').'#' : ''`}${2:function_name}(${3})
13-
${0}
14-
endf
12+
function! ${1:function_name}(${2:param})
13+
${0:"}
14+
endfunction
1515
snippet t try ... catch statement
1616
try
1717
${1}

0 commit comments

Comments
 (0)