Skip to content

Commit

Permalink
Read settings from buffer variables first, if available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
caio committed Jun 17, 2013
1 parent 640a183 commit ca2ada3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README
Expand Up @@ -15,6 +15,7 @@ License: This file is placed in the public domain
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,
Expand All @@ -27,6 +28,9 @@ Setup:
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
Expand Down
28 changes: 23 additions & 5 deletions plugin/querycommandcomplete.vim
Expand Up @@ -15,6 +15,7 @@
" 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,
Expand All @@ -27,6 +28,9 @@
" 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
Expand Down Expand Up @@ -80,8 +84,22 @@ if exists("g:loaded_QueryCommandComplete") || &cp
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','')

Expand Down Expand Up @@ -150,9 +168,9 @@ endfunction

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
Expand Down Expand Up @@ -180,7 +198,7 @@ function! s:GenerateCompletions(findstart, base)
endif

let results = []
let cmd = g:qcc_query_command
let cmd = s:GetSetting('query_command')
if cmd !~ '%s'
let cmd .= ' %s'
endif
Expand Down

0 comments on commit ca2ada3

Please sign in to comment.