在completefunc中传递vim参数

时间:2016-01-13 13:06:26

标签: vim

我正在撰写vimscript,其中使用completefunc作为:

" GetComp: Menu and Sunroutine Completion {{{1
function! GetComp(arg, findstart, base)
if a:findstart
    " locate the start of the word
    let line = getline('.')
    let start = col('.') - 1
    while start > 0 && line[start - 1] =~ '\a'
        let start -= 1
    endwhile
    return start
else
    echomsg '**** completing' a:base
python << EOF
import vim
import os
flsts = [' ']

path = "."
for dirs, subdirs, files in os.walk(path):
    for tfile in files:
        if tfile.endswith(('f90', 'F90', 'f', 'F')):
            ofile = open(dirs+'/'+tfile)
            for line in ofile:
                if line.lower().strip().startswith(vim.eval("a:arg")):
                    modname = line.split()[1]
                    flsts.append(modname)
vim.command("let flstsI = %s"%flsts)                    
EOF
if eval("a:arg") = "module"
  for m in ["ieee_arithmatic", "ieee_exceptions", "ieee_features", "iso_c_bindings", "iso_fortran_env",  "omp_lib", "omp_lib_kinds"]
    if m =~ "^" . a:base
      call add(flstsI, m)
    endif
  endfor
elseif eval("a:arg") = "subroutine"
for m in ["alarm()", "date_and_time()", "backtrace", "c_f_procpointer()", "chdir()", "chmod()", "co_broadcast()", "get_command()", "get_command_argument()", "get_environment_variable()", "mvbits()", "random_number()", "random_seed()"]
  if m =~ "^" . a:base
    call add(flstsI, m)
  endif
endfor
endif

return flstsI
endif
endfunction

我将其称为2个不同的论点:

inoremap <leader>call  call <C-o>:set completefunc=GetComp("subroutine", findstart, base)<CR><C-x><C-u>
inoremap <leader>use  use <C-o>:set completefunc=GetComp("module", findstart, base)<CR><C-x><C-u>

但是这样做会产生错误:Unknown function GetComp(

我不知道如何打电话给他们。 如果我不使用arg,那么,使用此reply,我可以完美地称之为。 请帮助。

1 个答案:

答案 0 :(得分:1)

您必须在完成时附加上下文。如果仔细查看my message on vi.se,您将看到一个允许将数据绑定到用户完成的框架。从你的映射中,它只是一个关于附加哪个上下文的问题。

一种简化的方法是从映射中执行(准备)函数,并具有将在完成函数中使用的函数集脚本全局变量。