Reply to message «How to check for a variable being set? 'defined' somehow 
doesn't work for me..», 
sent 11:56:06 09 June 2011, Thursday
by Asis Hallab:

Existing options cannot be undefined, so 
> if(defined(tags))
>   return "\<c-x>\<c-]>"
> endif
is not possible. I guess you need
    if !empty(&tags)
        return "\<C-x>\<C-]>"
    endif
This will check whether &tags option is empty. Note that &tags option has non-
empty default value, so you may want to use
    let s:defaulttags=(has('emacs_tags')?("./tags,./TAGS,tags,TAGS"):
                     \                   ("./tags,tags"))
    <...>
    if &tags isnot# s:defaulttags
        return "\<C-x>\<C-]>"
    endif

Original message:
> Dear Vimers,
> 
> How do I do something like the following:
> "
> if(defined(tags))
>   return "\<c-x>\<c-]>"
> endif
> "
> The tags-variable is the one set by :set tags="./tags".
> 
> How do I get the above to work?
> 
> Many thanks in advance!
> Asis
> 
> My Background is the following:
> Programming in Ruby I am using ctags in order to get tag-based completion.
> I want to configure the supertab-plugin to use also <C-x><C-]>
> (tag-completion).
> The manual states:
> "
>  In addition to the default completion contexts, you can plug in your own
>   implementation by creating a globally accessible function that returns
>   the completion type to use (eg. "\<c-x>\<c-u>").
> 
>     function MyTagContext()
>       if filereadable(expand('%:p:h') . '/tags')
>         return "\<c-x>\<c-]>"
>       endif
>       " no return will result in the evaluation of the next
>       " configured context
>     endfunction
>     let g:SuperTabCompletionContexts =
>         \ ['MyTagContext', 's:ContextText', 's:ContextDiscover']
> "
> I don't want to check, if the tags-file is readable, I want to check if the
> variable is set, because the rails-plugin sets it to ./tmp/tags and in
> other contexts it might be something else again..

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to