Permalink
Browse files

Merge branch 'from_marklee77'

Closes pull request #2:
    #2

* from_marklee77:
  Make multiline support configurable
  restored multiline support
  Add support for "%s" in qcc_query_command
  • Loading branch information...
2 parents e0d84b2 + f5ef1d1 commit 987a67a054d99d3481f3db58eb030a709bc2b64c @caio committed Dec 29, 2012
Showing with 24 additions and 10 deletions.
  1. +24 −10 plugin/querycommandcomplete.vim
@@ -51,10 +51,11 @@ endif
" 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!"
@@ -75,6 +76,8 @@ endfunction
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 = {}
@@ -107,12 +110,12 @@ function! s:GenerateCompletions(findstart, base)
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
@@ -138,11 +141,22 @@ function! s:GenerateCompletions(findstart, base)
return results
endfunction
-function! QueryCommandComplete(findstart, base)
- let cur_line = getline(line('.'))
+function! s:ShouldGenerateCompletions(line_number)
+ let current_line = getline(a:line_number)
+
+ if current_line =~ g:qcc_pattern
+ return 1
+ endif
- " TODO: Figure out a way to handle multiline
- if cur_line =~ g:qcc_pattern
+ 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

0 comments on commit 987a67a

Please sign in to comment.