On Sun, 18 Jun 2006 at 11:26pm, Bram Moolenaar wrote:

>
> Hari Krishna Dara wrote:
>
> > I have a command with custom completion function that employs the :redir
> > mechanism to determines the matches. This used to work fine in Vim6.3,
> > but is broken in Vim7.0. I don't see any sandbox restrictions that could
> > apply in this case, but even if they do, the command for which I am
> > redirecting the output itself is very simple, it is just an :echo on a
> > simple string, something like this:
> >
> > :Echo delete
> >
> > and the command Echo is defined as
> >
> > :command! -complete=file -nargs=* Echo :echo <q-args>
> >
> > Is this a bug in Vim7 or some change that is not backwards compatible?
> > What would be the change that caused this to break?
>
> You don't give enough information to write a meaningful reply.
>

Sorry, I thought my description was complete enough, but anyway, here I
extracted the code that breaks.

command! -complete=file -nargs=* GUDebugEcho :echo <q-args>
function! UserFileExpand(fileArgs)
    return substitute(GetVimCmdOutput('GUDebugEcho ' . a:fileArgs),
'^\_s\+\|\_s\+$', '', 'g')
endfunction

If UserFileExpand() is called from custom completion function, it no
longer captures any output (this works fine in 6.3), but it works fine
if you call from command line or scripts.

This doesn't work (this is just a dummy command to show the epansion
doesn't return anything, the input() prompt shows that expansion didn't
work):
:TT abc<Tab>

Where TT is defined as:
command! -nargs=* -complete=custom,CustComplete TT :echo <q-args>
function! CustComplete(ArgLead, CmdLine, CursorPos)
  let ArgLead = UserFileExpand(a:ArgLead)
  call input('ArgLead: '.a:ArgLead.' expanded: ' . ArgLead)
  return ArgLead
endfunction

This works:
:echo UserFileExpand('abc')

And this too works:
echo CustComplete('abc', '', 0)

The GetVimCmdOutput() is simply a wrapper around :redir and here is how
it is defined:

function! GetVimCmdOutput(cmd)
  let v:errmsg = ''
  let output = ''
  let _z = @z
  let _shortmess = &shortmess
  try
    set shortmess=
    redir @z
    exec a:cmd
  catch /.*/
    let v:errmsg = substitute(v:exception, '^[^:]\+:', '', '')
  finally
    redir END
    let &shortmess = _shortmess
    if v:errmsg == ''
      let output = @z
    endif
    let @z = _z
  endtry
  return output
endfunction

-- 
Thanks,
Hari

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to