Sunday, June 8, 2014

Re: How can a highlight group combine custom attributes and a link?

On Friday, June 6, 2014 2:06:51 AM UTC-4, Tony Mechelynck wrote:
> On 04/06/14 17:19, boss@airbladesoftware.com wrote:
>
> > Hello!
>
> >
>
> > I am aware of one way for a highlight group to contain both custom attributes and a link to another group:
>
> >
>
> > :hi Foo guifg=red
>
> > :hi! link Foo Comment
>
> >
>
> > :hi Foo
>
> > Foo xxx guifg=red
>
> > links to Comment
>
> >
>
> > Are there any other ways to do this?
>
> >
>
> > The context is I have a plugin which defines a default highlight group:
>
> >
>
> > :hi default link Foo Comment
>
> >
>
> > In a user's vimrc, they specify the attributes they actually want:
>
> >
>
> > :hi Foo guifg=red
>
> >
>
> > However instead of seeing this:
>
> >
>
> > :hi Foo
>
> > Foo xxx guifg=red
>
> >
>
> > ...they see this:
>
> >
>
> > :hi Foo
>
> > Foo xxx guifg=red
>
> > links to Comment
>
> >
>
> > And I cannot figure out why this is happening. (https://github.com/airblade/vim-gitgutter/issues/176)
>
> >
>
> > Thanks in advance!
>
> >
>
> > Yours,
>
> > Andy Stewart
>
> >
>
>
>
> I think it is a minor bug. You didn't say if the highlight definition
>
> for "Comment" is actually "guifg=red" in the colorscheme you're using,
>
> but if it isn't you could check what happens.
>
>
>
> I *think* that using ":hi! link" with a bang on a from-group which
>
> already exists (as in your first example) should undo the preexisting
>
> definition and replace it with the link, while using ":hi default link"
>
> on a from-group which already exists (as in your second example, since
>
> plugins are processed after the vimrc) should completey ignore the link
>
> (and keep the preexisting definition).
>
>
>
> If the actual color for the Foo group is the same as for Comment in the
>
> first case but is red (and Comment is not red) in the second example,
>
> then highlight groups are created properly, it's just the display which
>
> is wrong; but how two different situations can be displayed identically
>
> in this "list groups" variant of the command beats me.
>
>
>
> If in both cases the highlight for Foo is the same, either red both
>
> times or the same as Comment both times, then either there is a bug or I
>
> have misunderstood the workings of either the exclamation mark or the
>
> "default" argument in the :highlight command.

I am the user who is having the issues and I think I have discovered the underlying bug. As mentioned above, `:hi [default] link From To` should only do the link if From has no settings, and if default is omitted, should issue the error "E414: group has settings, highlight link ignored". In fact, at least on Ubuntu 14.04 package vim-gtk 7.4.052-1ubuntu3, this only happens if From has no *terminal* settings, unless you are running the command from gvim once it has started. If From has only gui settings and either running console vim is used or the commands are found in the startup files, the `:hi link From To` acts as though From has no settings and performs the link anyway.

Here is a simple example:

$ vim -u NONE
:hi Foo guifg=blue
:hi link Foo Error

The above should error out but it does not. Here is a full example to show that this happens on both vim and gvim:

$ mv .vim vim-bak
$ mv .vimrc vimrc-bak
$ cat >.vimrc <<EOF
hi GuiTest guifg=blue
hi CtermTest ctermfg=blue
hi GuiTest
hi CtermTest
hi default link GuiTest Error
hi default link CtermTest Error
hi GuiTest
hi CtermTest
EOF
$ gvim # or vim

This gives the following result:

GuiTest xxx guifg=blue
CtermTest xxx ctermfg=12
GuiTest xxx guifg=blue
links to Error
CtermTest xxx ctermfg=12

The expected result is that neither GuiTest nor CtermTest link to Error.

Note, however, that if you try to run those same commands once the gui has started, you get the expected error message. But this only works in gvim; regular vim exhibits the same bug as putting it in the vimrc file.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: