Read settings from buffer variables first, if available
Enable changing settings on a buffer-basis. QueryCommandComplete new tries to read every configuration setting from the buffer-level variables (b:qcc_*) before reading the global score ones (g:qcc_*). This means that now you can have different buffers calling completely different completion functions (and options). This patch builds on top of the idea bootstrapped by @equalsraf on his branch[1]. [1]: https://github.com/equalsraf/querycommandcomplete.vim/commit/7e9a7a602f4ae9c0355ca27cada4ba7173c6ec59
- Id
- ca2ada33a2585856cbb1287a18360e4069d6c68a
- Author
- Caio
- Commit time
- 2013-06-17T21:45:34+02:00
Modified README
Contributors:
Brian Henderson https://github.com/bhenderson
Mark Stillwell https://github.com/marklee77
+ Rui Abreu Ferreira http://ruiabreu.org
Setup:
This plugin exports the completion function QueryCommandComplete,
au BufRead /tmp/mutt* setlocal omnifunc=QueryCommandComplete
Settings:
+ Note: Overriding settings on a buffer-basis is supported. So
+ b:qcc_query_command takes precedence over g:qcc_query_command
+
g:qcc_query_command
External command that queries for contacts
If empty, QueryCommandComplete tries to guess what command to
Modified plugin/querycommandcomplete.vim
" Contributors:
" Brian Henderson https://github.com/bhenderson
" Mark Stillwell https://github.com/marklee77
+" Rui Abreu Ferreira http://ruiabreu.org
"
" Setup:
" This plugin exports the completion function QueryCommandComplete,
" au BufRead /tmp/mutt* setlocal omnifunc=QueryCommandComplete
"
" Settings:
+" Note: Overriding settings on a buffer-basis is supported. So
+" b:qcc_query_command takes precedence over g:qcc_query_command
+"
" g:qcc_query_command
" External command that queries for contacts
" If empty, QueryCommandComplete tries to guess what command to
finish
endif
+function! s:GetSetting(name)
+ let global_option = 'g:qcc_' . a:name
+ let local_option = 'b:qcc_' . a:name
+
+ let result = ''
+ if exists(local_option)
+ let result = {local_option}
+ elseif exists(global_option)
+ let result = {global_option}
+ endif
+
+ return result
+endfunction
+
" Try to use mutt's query_command by default if nothing is set
-if !exists("g:qcc_query_command")
+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','')
function! s:MakeCompletionEntry(fields)
let entry = {}
- let entry.word = s:ApplyFieldsToFormatString(a:fields, g:qcc_format_word)
- let entry.abbr = s:ApplyFieldsToFormatString(a:fields, g:qcc_format_abbr)
- let entry.menu = s:ApplyFieldsToFormatString(a:fields, g:qcc_format_menu)
+ let entry.word = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_word'))
+ let entry.abbr = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_abbr'))
+ let entry.menu = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_menu'))
let entry.icase = 1
return entry
endfunction
endif
let results = []
- let cmd = g:qcc_query_command
+ let cmd = s:GetSetting('query_command')
if cmd !~ '%s'
let cmd .= ' %s'
endif