Permalink
Browse files

Stop checking settings during source

This patch removes the need of having g:qcc_query_command set to
anything prior to loading QueryCommandComplete.
  • Loading branch information...
1 parent ca2ada3 commit 14791f2d19d77b0887057e82e21e7934bc39103b @caio committed Jun 17, 2013
Showing with 19 additions and 16 deletions.
  1. +19 −16 plugin/querycommandcomplete.vim
@@ -98,21 +98,6 @@ function! s:GetSetting(name)
return result
endfunction
-" Try to use mutt's query_command by default if nothing is set
-if empty(s:GetSetting('query_command'))
- let s:querycmd = system('mutt -Q query_command 2>/dev/null')
- 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!"
- finish
- endif
-endif
-
let g:loaded_QueryCommandComplete = 1
let s:save_cpo = &cpo
set cpo&vim
@@ -230,8 +215,26 @@ function! s:ShouldGenerateCompletions(line_number)
return s:ShouldGenerateCompletions(a:line_number - 1)
endfunction
+function! s:CheckSettings()
+ " Try to use mutt's query_command by default if nothing is set
+ if empty(s:GetSetting('query_command'))
+ let s:querycmd = system('mutt -Q query_command 2>/dev/null')
+ 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!"
+ return 0
+ endif
+ endif
+ return 1
+endfunction
+
function! QueryCommandComplete(findstart, base)
- if s:ShouldGenerateCompletions(line('.'))
+ if s:CheckSettings() && s:ShouldGenerateCompletions(line('.'))
return s:GenerateCompletions(a:findstart, a:base)
endif
endfunction

0 comments on commit 14791f2

Please sign in to comment.