After upgrading my copy of the CSApprox plugin http://www.vim.org/scripts/script.php?script_id=2390 to version 4.00 I noticed that if a global Funcref is set to a script-local function in its defining script, the Funcref will be stored as pointing to s:<something>, not to <SNR>nn_<something>, i.e., the context is lost, and any attempt to invoke that Funcref from outside its defining script causes an error, because Vim tries to invoke the script-local function in the context of the caller.

I admit that my colorscheme has one fancy feature: it alternates the StatusLine and WildMenu highlights by means of a CursorHold,CursorHoldI autocommand. In Console mode with CSApprox installed, in a terminal capable of (88 or) 256 colours, this means setting highlights for these two highlight groups only, using a CSApprox function to get the ctermfg and ctermbg values without (for performance) running the whole plugin as the CursorScheme autocommand event would. A further complication is that the colorscheme is sourced early, by a :colorscheme statement in the vimrc, while the plugin/CSApprox.vim script is only sourced afterwards, together with other global plugins.

The following doesn't work (the first :let statement triggers an error):

if exists('g:CSApprox_approximator_function')
  let s:ctbg1 = g:CSApprox_approximator_function(0,   255, 0) " green
  let s:ctbg2 = g:CSApprox_approximator_function(255, 0,   0) " red
  let s:ctfg  = g:CSApprox_approximator_function(0,   0,   0) " black
else
  let s:ctbg1 = 'darkgreen'
  let s:ctbg2 = 'black'
  let s:ctfg  = 'white'
endif

The following, which uses the contents of the contents of the Funcref, works (it causes an early sourcing of autoload/csapprox/per_component.vim and autoload/csapprox/common.vim, with no ill effects AFAICS):

try
  let s:ctbg1 = csapprox#per_component#Approximate(0,   255, 0) " green
  let s:ctbg2 = csapprox#per_component#Approximate(255, 0,   0) " red
  let s:ctfg  = csapprox#per_component#Approximate(0,   0,   0) " black
catch
  let s:ctbg1 = 'darkgreen'
  let s:ctbg2 = 'black'
  let s:ctfg  = 'white'
endtry


Best regards,
Tony.
--
Real computer scientists despise the idea of actual hardware.  Hardware
has limitations, software doesn't.  It's a real shame that Turing
machines are so poor at I/O.

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui