Sunday, June 24, 2012

Re: How to tell if highlight has been defined

On Sun, Jun 24, 2012 at 10:39 PM, Ben Fritz <fritzophrenic@gmail.com> wrote:
> On Sunday, June 24, 2012 7:53:11 PM UTC-5, Richard wrote:
>> Consider the highlight
>>
>> :hi MyHi ctermbg=46 guibg=#00ff00
>>
>> In a script, is it possible to test whether or not its
>> been defined.
>>
>> If one uses:
>>
>> :hi MyHi
>>
>> it will produce an Error message or the highlight terms.
>> What is want is something like:
>>
>> if ! defined_highlight("MyHi")
>>    :hi MyHi ....
>> endif
>>
>
> Maybe use :try ... :catch to try getting the highlight info if it exists, and catch the error if it does not.
>
> :help :try
> :help :catch

To elaborate, this should do the trick:

function! HighlightDefined( highName )
try
silent execute 'hi ' . a:highName
return 1
catch
return 0
endtry
endfunction

Salman

--
You received this message from the "vim_use" 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

No comments: