Merge branch 'from_marklee77'
Closes pull request #2: https://github.com/caio/querycommandcomplete.vim/pull/2 * from_marklee77: Make multiline support configurable restored multiline support Add support for "%s" in qcc_query_command
- Id
- 987a67a054d99d3481f3db58eb030a709bc2b64c
- Author
- Caio
- Commit time
- 2012-12-29T20:07:21+01:00
Modified plugin/querycommandcomplete.vim
" use mutt query command as default
if !exists("g:qcc_query_command")
let s:querycmd = system('mutt -Q query_command 2>/dev/null')
- let s:querycmd = substitute(s:querycmd, '^query_command=\"\(.*\) .%s.\"\n', '\1','')
+ let s:querycmd = substitute(s:querycmd, '^query_command="\(.*\)"\n', '\1','')
if len(s:querycmd)
let g:qcc_query_command = s:querycmd
+ let g:qcc_multiline = 1
autocmd FileType mail setlocal omnifunc=QueryCommandComplete
else
echoerr "QueryCommandComplete: g:qcc_query_command not set!"
call s:DefaultIfUnset('g:qcc_line_separator', '\n')
call s:DefaultIfUnset('g:qcc_field_separator', '\t')
call s:DefaultIfUnset('g:qcc_pattern', '^\(To\|Cc\|Bcc\|From\|Reply-To\):')
+call s:DefaultIfUnset('g:qcc_multiline', 0)
+call s:DefaultIfUnset('g:qcc_multiline_pattern', '.*')
function! s:MakeCompletionEntry(name, email, other)
let entry = {}
return s:FindStartingIndex()
endif
- if a:base =~ '^ *$'
- return []
- endif
-
let results = []
- let cmd = g:qcc_query_command . ' ' . shellescape(a:base)
+ let cmd = g:qcc_query_command
+ if cmd !~ '%s'
+ let cmd .= ' %s'
+ endif
+ let cmd = substitute(cmd, '%s', shellescape(a:base), '')
let lines = split(system(cmd), g:qcc_line_separator)
for my_line in lines
return results
endfunction
-function! QueryCommandComplete(findstart, base)
- let cur_line = getline(line('.'))
+function! s:ShouldGenerateCompletions(line_number)
+ let current_line = getline(a:line_number)
- " TODO: Figure out a way to handle multiline
- if cur_line =~ g:qcc_pattern
+ if current_line =~ g:qcc_pattern
+ return 1
+ endif
+
+ if ! g:qcc_multiline || a:line_number <= 1 || current_line !~ g:qcc_multiline_pattern
+ return 0
+ endif
+
+ return s:ShouldGenerateCompletions(a:line_number - 1)
+endfunction
+
+function! QueryCommandComplete(findstart, base)
+ if s:ShouldGenerateCompletions(line('.'))
return s:GenerateCompletions(a:findstart, a:base)
endif
endfunction