Vim syntax: "highlight" keyword not highlighted inside functions

117 views
Skip to first unread message

François Ingelrest

unread,
Nov 5, 2008, 11:10:12 AM11/5/08
to vim...@googlegroups.com
Hi all,

If I put this in a foo.vim file:

----
highlight Comment guifg=White guibg=Black

function! Foo()

highlight Comment guifg=White guibg=Black

endfunction
----

The first "highlight" line is highlighted, but not the second one. It
seems that's because it's inside a function. Is it intended, or is
this a bug in the vim syntax file?

Roberto Miura Honji

unread,
Nov 6, 2008, 4:41:39 PM11/6/08
to vim...@googlegroups.com
I'm using highlight inside a function and It's working.
Do you call the function?
If you only define a function on foo.vim, this only will be defined. Try append a follow line in a foo.vim: call Foo()

2008/11/5 François Ingelrest <francois....@gmail.com>



--
----------------------------------------------
Roberto Miura Honji
LAS - Laboratório de Administração e Segurança de Sistemas
Engenharia de Computação - 2006
Instituto de Computação - UNICAMP

email: miura...@gmail.com (principal)
email: ra06...@students.ic.unicamp.br
msn:   miura...@msn.com
-------------------------------------------

François Ingelrest

unread,
Nov 7, 2008, 2:08:38 AM11/7/08
to vim...@googlegroups.com
On Thu, Nov 6, 2008 at 22:41, Roberto Miura Honji <miura...@gmail.com> wrote:
> I'm using highlight inside a function and It's working.

You get the same color highlighting inside and outside the function?
For me the highlighting works inside functions for most statements,
but not for the 'highlight' statement itself (see attached
screenshot).

> Do you call the function?
> If you only define a function on foo.vim, this only will be defined. Try
> append a follow line in a foo.vim: call Foo()

This doesn't make a difference. Actually, I'm not sure the syntax file
checks that functions are called to highlight them.

screenshot.png

François Ingelrest

unread,
Nov 7, 2008, 2:12:22 AM11/7/08
to vim...@googlegroups.com

I should add that I'm using Vim 7.2.26, compiled by myself using the
sources from the CVS, so I guess the syntax file also comes from the
CVS. I get the same result when using Vim -u NONE -U NONE, and
enabling only syntax highlighting after that.

Tony Mechelynck

unread,
Nov 8, 2008, 10:02:06 PM11/8/08
to vim...@googlegroups.com

Yeah, looks like the syntax/vim.vim script doesn't recognise the same
syntax groups for some statements when they are inside a function. With
the default GUI colours, here's what I see:

line
word isolated (=> links to) inside func (=> links to)
highlight Comment guifg=white guibg=black
highlight vimHighlight => Statement vimIsCommand
Comment vimHiGroup => Type vimIsCommand
guifg vimHiGuiFgBg => Type vimIsCommand
= vimHiKeyList vimOper => Statement
white vimHiGroup => Type vimIsCommand
guibg vimHiGuiFgBg => Type vimIsCommand
= vimHiKeyList vimOper => Statement
black vimHiGroup => Type vimIsCommand
syn sync fromstart
syn vimSyntax => Statement vimIsCommand
sync vimSynType => Type vimIsCommand
fromstart vimSyncC => Type vimIsCommand
filetype plugin indent on
filetype vimFTCmd => Statement vimCommand => Statement
plugin vimFTOption => Type vimIsCommand
indent vimFTOption => Type vimIsCommand
on vimFTOption => Type vimCommand => Statement

The other ones that I tried were highlighted identically inside
functions and out of them.

I found this out by means of the following command (which gives four
replies but 1 and 3 are equal, and so are 2 and 4, AFAICT):

command -nargs=0 -bar WhatSyntax echomsg
synIDattr(synID(line("."),col("."),0),"name")
synIDattr(synIDtrans(synID(line("."),col("."),0)),"name")
synIDattr(synID(line("."),col("."),1),"name")
synIDattr(synIDtrans(synID(line("."),col("."),1)),"name")


Notice the many instances of various syntax groups becoming vimIsCommand
(which has no highlights defined) when inside a function block.

Maybe contains=TOP should be added to the definition of the vimFuncBody
syntax group? Dr.Chip, what do you think?


Best regards,
Tony.
--
I've given up reading books; I find it takes my mind off myself.

Anton Sharonov

unread,
Nov 9, 2008, 5:14:07 AM11/9/08
to vim...@googlegroups.com
> I should add that I'm using Vim 7.2.26, compiled by myself
> using the sources from the CVS, so I guess the syntax file also
> comes from the CVS. I get the same result when using Vim -u
> NONE -U NONE, and enabling only syntax highlighting after that.

> ... so I guess the syntax file also
> comes from the CVS. ...

Unfortunately, it is not true. At least for SVN, (and I suspect
that for CVS it is as well the case) there are recent versions of
the runtime files (don't ask me why, for me it is also _very_
confusing). Anyway, to get recent runtime files, please use
rsync, as described on Tony's howto [1] about compiling vim.

--
Anton

[1] Tony's how to for VIM compilation
UNIX:
http://users.skynet.be/antoine.mechelynck/vim/compunix.htm
WINDOWS:
http://users.skynet.be/antoine.mechelynck/vim/compile.htm

Anton Sharonov

unread,
Nov 9, 2008, 5:17:28 AM11/9/08
to vim...@googlegroups.com
%s/there are recent versions/there is no recent versions/

Sorry for small typo.

--
Anton

2008/11/9, Anton Sharonov <anton.s...@gmail.com>:

François Ingelrest

unread,
Nov 9, 2008, 6:53:26 AM11/9/08
to vim...@googlegroups.com
On Sun, Nov 9, 2008 at 11:14, Anton Sharonov <anton.s...@gmail.com> wrote:
> Unfortunately, it is not true. At least for SVN, (and I suspect
> that for CVS it is as well the case) there are recent versions of
> the runtime files (don't ask me why, for me it is also _very_
> confusing). Anyway, to get recent runtime files, please use
> rsync, as described on Tony's howto [1] about compiling vim.

Thanks for pointing this. I've updated my runtime files, but the
highlight problem is nevertheless still there.

François Ingelrest

unread,
Nov 23, 2008, 11:56:41 AM11/23/08
to vim...@googlegroups.com
Hi all,

No news on this issue?

Erik Falor

unread,
Nov 24, 2008, 3:15:59 PM11/24/08
to vim...@googlegroups.com
After looking at syntax/vim.vim, I noticed that the syntax cluster
that defines what's allowed within a function body didn't include the
syntax item for highlights. Neither did it include the syntax item for
abbreviations. I added those lines, and re-set the 'filetype' option,
and sure enough, the highlight and abbrev keywords were highlighted.
For all I know, there are other Vim script elements that aren't being
highlighted as well.

Offhand, I'd say that this is merely an oversight. Dr. Chip, would
you care to weigh in on this?

I've attached the patch with the aforementioned changes.

--
Erik Falor
Registered Linux User #445632 http://counter.li.org
vim.vim.diff

Charles Campbell

unread,
Nov 24, 2008, 3:30:09 PM11/24/08
to vim...@googlegroups.com
I've had a syntax/vim.vim, last modified Nov 7, that had vimHighlight in
it. Still didn't have vimAbb, though; however, the header said "NOT
RELEASED" so it hasn't been on my website, I'm afraid. I've updated my
website:
http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax.
Eventually I'll push it on up to the Official Vim Master (aka Bram
Moolenaar).

Regards,
Chip Campbell


François Ingelrest

unread,
Nov 25, 2008, 2:04:41 AM11/25/08
to vim...@googlegroups.com
On Mon, Nov 24, 2008 at 21:30, Charles Campbell
<Charles.E...@nasa.gov> wrote:
> I've had a syntax/vim.vim, last modified Nov 7, that had vimHighlight in
> it. Still didn't have vimAbb, though; however, the header said "NOT
> RELEASED" so it hasn't been on my website, I'm afraid. I've updated my
> website:
> http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax.

Thanks, it's fine now.

Reply all
Reply to author
Forward
0 new messages