Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vim script for Tcl; request for input.

92 views
Skip to first unread message

Robert Hicks

unread,
Jun 26, 2006, 9:20:50 AM6/26/06
to
I am in the process of updating the "tcl.vim" syntax file. I have some
things working already like options being colors (i.e. -text, -padx).

I know that Tcl doesn't officially have a multi-line comment but
someone once requested that I color the following as a comment:

if {0} {
# everything in here is ignored by Tcl
}

Would any Tcl community Vim users want the colored as a comment or
colored as something else (either would make it stand out from code) or
just leave it alone?

Robert

Robert Hicks

unread,
Jun 26, 2006, 9:46:41 AM6/26/06
to
Another question would be for Tile support. Since Tile widgets are in
the format of ttk::widgetname, it shouldn't be too hard to incorporate
that.

Yes? No?

Glenn Jackman

unread,
Jun 26, 2006, 9:57:39 AM6/26/06
to
At 2006-06-26 09:20AM, Robert Hicks <sig...@gmail.com> wrote:
> I am in the process of updating the "tcl.vim" syntax file. I have some
> things working already like options being colors (i.e. -text, -padx).

Cool. I look forward to seeing it.

> I know that Tcl doesn't officially have a multi-line comment but
> someone once requested that I color the following as a comment:
>
> if {0} {
> # everything in here is ignored by Tcl
> }
>
> Would any Tcl community Vim users want the colored as a comment or
> colored as something else (either would make it stand out from code) or
> just leave it alone?

I would like to see the body coloured as a comment, but the actual [if]
command coloured as a statement. If possible.

--
Glenn Jackman
Ulterior Designer

Robert Hicks

unread,
Jun 26, 2006, 10:19:33 AM6/26/06
to

Glenn Jackman wrote:
> At 2006-06-26 09:20AM, Robert Hicks <sig...@gmail.com> wrote:
<snip>

>
> I would like to see the body coloured as a comment, but the actual [if]
> command coloured as a statement. If possible.
>

Do you know if it is a common thing to do that in Tcl?

Robert

Adrian Ho

unread,
Jun 26, 2006, 10:40:04 AM6/26/06
to
On 2006-06-26, Robert Hicks <sig...@gmail.com> wrote:
> I am in the process of updating the "tcl.vim" syntax file. I have some
> things working already like options being colors (i.e. -text, -padx).

Sounds good. 8-)

> I know that Tcl doesn't officially have a multi-line comment but
> someone once requested that I color the following as a comment:
>
> if {0} {
> # everything in here is ignored by Tcl
> }
>
> Would any Tcl community Vim users want the colored as a comment or
> colored as something else (either would make it stand out from code) or
> just leave it alone?

I never use that construct, but if I did, I'd probably say "color it as
a comment, since that's pretty much the net effect."

- Adrian

Robert Hicks

unread,
Jun 26, 2006, 11:14:02 AM6/26/06
to

I did it anyway. It was easy to do. I added Snit as well since it uses
the same construct.

Robert

Roy Terry

unread,
Jun 26, 2006, 11:21:05 AM6/26/06
to
"Robert Hicks" <sig...@gmail.com> wrote in message
news:1151331573....@b68g2000cwa.googlegroups.com...
I do it pretty commonly. I also do experiments and
incremental changes with code like
if { 0 && a couple of now moot expressions} { ...

It would be cute if you detected and comment-colored
that if statement as well.

BTW,
What are the main improvements you're aiming
for over the existing distributed
Tcl highlighter?


>
> Robert
>


Robert Hicks

unread,
Jun 26, 2006, 11:29:26 AM6/26/06
to

Roy Terry wrote:
> "Robert Hicks" <sig...@gmail.com> wrote in message
> news:1151331573....@b68g2000cwa.googlegroups.com...
> >
> > Glenn Jackman wrote:
> > > At 2006-06-26 09:20AM, Robert Hicks <sig...@gmail.com> wrote:
> > <snip>
> > >
> > > I would like to see the body coloured as a comment, but the actual [if]
> > > command coloured as a statement. If possible.
> > >
> >
> > Do you know if it is a common thing to do that in Tcl?
> I do it pretty commonly. I also do experiments and
> incremental changes with code like
> if { 0 && a couple of now moot expressions} { ...
>
> It would be cute if you detected and comment-colored
> that if statement as well.
>

That probably wouldn't be so hard since I could just color a statement
that starts with "if { 0".

> BTW,
> What are the main improvements you're aiming
> for over the existing distributed
> Tcl highlighter?

* all options like -text, -padx are colored. Not all were being caught
and colored.
* more Tcl and Tk commands colored
* there is folding now (basic as it is)
* other namespace support (ttk:: and snit::)
* optional things like the if {0} comment above
* cleaning it up a little
* coloring operators but this might not be doable by me

Now that I look at that list, I am almost done. I am open to
suggestions as well.

Robert

Earl Greida

unread,
Jun 26, 2006, 11:54:38 AM6/26/06
to

"Robert Hicks" <sig...@gmail.com> wrote in message
news:1151328050....@b68g2000cwa.googlegroups.com...

> I am in the process of updating the "tcl.vim" syntax file.


Can you post it when it is finished? The one that comes with Redhat/Fedora
linux is incomplete. I was able to add all the keywords and change the
colors to my liking, but I cannot figure out how to change the color of the
characters "{}[];".


Robert Hicks

unread,
Jun 26, 2006, 12:18:02 PM6/26/06
to

Absolutely. I have been posting it as I go on the Vim page at:

http://vim.sourceforge.net/scripts/script.php?script_id=1578

The coloring of those characters might be above my skill though. There
is a commented line called "tclOperators". It currently has issues that
I am looking into but may not implement.

Robert

George Petasis

unread,
Jun 26, 2006, 1:48:44 PM6/26/06
to Robert Hicks
O/H Robert Hicks έγραψε:

I never write comments like this, but it is not something uncommon.
It reminds me the comment highlighting that vim does for C (#ifdef 0 ...
#endif). Perhaps you can get help in implementing it if you look the
relevant C file.

Also, do you plan to give the improved file in vim developers, to be
included in vim distributions?

George

Robert Hicks

unread,
Jun 26, 2006, 2:18:43 PM6/26/06
to

George Petasis wrote:
> O/H Robert Hicks έγραψε:
> > Glenn Jackman wrote:
> >> At 2006-06-26 09:20AM, Robert Hicks <sig...@gmail.com> wrote:
> > <snip>
>
> Also, do you plan to give the improved file in vim developers, to be
> included in vim distributions?

When done, I plan to offer it up to the current tcl.vim maintainer (but
that one hasn't changed since 2004). If he still wants to maintain
tcl.vim but doesn't like what I have done, I will offer it on the Vim
site as an "alternative". If he doesn't want to maintain the tcl.vim
syntax file then I will ask him if I can be the maintainer and then I
will contact Bram to get mine included in the Vim distribution.

I hope that answers your question.

Robert

Michael A. Cleverly

unread,
Jun 26, 2006, 2:27:02 PM6/26/06
to

I think "if 0 {...}" is a fairly common idiom for commenting out large
blocks of code.

Though I personally always use if 0 instead of if {0}; ideally the
presence or lack of {}'s around the 0 shouldn't effect the coloring.

Michael

Robert Hicks

unread,
Jun 26, 2006, 2:41:02 PM6/26/06
to

I think I will pass on this for now. It is a bit beyond me. I have to
look and see if maybe some other syntax has implemented it or something
close.

Robert

Neil Madden

unread,
Jun 26, 2006, 3:19:47 PM6/26/06
to

While you're adding stuff from common extensions, it would be useful to
have stuff like "class", "type", "self", "this", "method", "public" etc
highlighted for when looking through code written with Itcl/Snit/other
OO extensions. Many of these terms are pretty common across OO
extensions, although you might also want to include XOTcl's Class,
instproc, filter, mixin etc (and looking ahead check the syntax for TIP
257), which are pretty much unique to XOTcl.

I presume you have added new 8.5 commands, like dict and chan? Perhaps
{expand} should be highlighted?

-- Neil

Robert Hicks

unread,
Jun 26, 2006, 3:38:56 PM6/26/06
to

Neil Madden wrote:
> Robert Hicks wrote:
> > Robert Hicks wrote:
> >> Another question would be for Tile support. Since Tile widgets are in
> >> the format of ttk::widgetname, it shouldn't be too hard to incorporate
> >> that.
> >>
> >> Yes? No?
> >
> > I did it anyway. It was easy to do. I added Snit as well since it uses
> > the same construct.
>
> While you're adding stuff from common extensions, it would be useful to
> have stuff like "class", "type", "self", "this", "method", "public" etc
> highlighted for when looking through code written with Itcl/Snit/other
> OO extensions. Many of these terms are pretty common across OO
> extensions, although you might also want to include XOTcl's Class,
> instproc, filter, mixin etc (and looking ahead check the syntax for TIP
> 257), which are pretty much unique to XOTcl.
>

I will have to look at [incr] Tcl and XOTcl to see what I can clue off
of. Snit was relatively easy. If it gets messy, I will pull all the OO
stuff and push those out to extender scripts that extend the basic
tcl.vim (i.e. xotcl.vim, itcl.vim, snit.vim).

I could also make the user put a switch in their .vimrc that switches
on the OO stuff:

let g:tclOO=1 or let g:tclXOTCL=1 or let g:tclSNIT=1

something like that. I am guessing that most people stick to one OO but
all of them could be supported. I think I would liked the named
"g:tclXOTCL" ones better as the user could add the ones that are being
used.

I added Snit because I like Snit. : )

> I presume you have added new 8.5 commands, like dict and chan? Perhaps
> {expand} should be highlighted?

No, not yet. I wanted to get the current stuff done before looking at
the 8.5 stuff. I don't foresee any issues though.

Robert

Neil Madden

unread,
Jun 26, 2006, 6:01:12 PM6/26/06
to
Robert Hicks wrote:
> Neil Madden wrote:
[...]

>> While you're adding stuff from common extensions, it would be useful to
>> have stuff like "class", "type", "self", "this", "method", "public" etc
>> highlighted for when looking through code written with Itcl/Snit/other
>> OO extensions. Many of these terms are pretty common across OO
>> extensions, although you might also want to include XOTcl's Class,
>> instproc, filter, mixin etc (and looking ahead check the syntax for TIP
>> 257), which are pretty much unique to XOTcl.
>>
>
> I will have to look at [incr] Tcl and XOTcl to see what I can clue off
> of. Snit was relatively easy. If it gets messy, I will pull all the OO
> stuff and push those out to extender scripts that extend the basic
> tcl.vim (i.e. xotcl.vim, itcl.vim, snit.vim).

It's all just some more keywords:

syn keyword tclStatement class method constructor destructor inherit
syn keyword tclStatement common public protected private body local
syn keyword tclStatement type pragma macro delegate component
...

would cover most of Itcl and Snit (and various others). Just check the
manpages and add the keywords that you think are worth adding. The more
the merrier, so long as there are no conflicting spellings.

>
> I could also make the user put a switch in their .vimrc that switches
> on the OO stuff:
>
> let g:tclOO=1 or let g:tclXOTCL=1 or let g:tclSNIT=1
>
> something like that. I am guessing that most people stick to one OO but
> all of them could be supported. I think I would liked the named
> "g:tclXOTCL" ones better as the user could add the ones that are being
> used.

I'd just put them all in - they often share common terminology, and
there are no conflicts that I know of. After all, a syntax highlighter
doesn't need to care whether "method" refers to an Itcl method or a Snit
method.

If you've already done Snit, then you probably have to only add a couple
of more keywords to get Itcl. A few more gets you XOTcl, ClassyTcl, OTcl
etc.

-- Neil

Robert Hicks

unread,
Jun 26, 2006, 6:49:19 PM6/26/06
to

Neil Madden wrote:
> Robert Hicks wrote:
> > Neil Madden wrote:
<snip>

> I'd just put them all in - they often share common terminology, and
> there are no conflicts that I know of. After all, a syntax highlighter
> doesn't need to care whether "method" refers to an Itcl method or a Snit
> method.
>
> If you've already done Snit, then you probably have to only add a couple
> of more keywords to get Itcl. A few more gets you XOTcl, ClassyTcl, OTcl
> etc.
>
> -- Neil

Yeah, I will look into just "doing" it as that is the easiest thing in
the long run. Then I can just look at coloring namespace (i.e. snit::,
oo:: and whatever XOTcl and itcl use).

Thanks for the input...

Robert

MH

unread,
Jun 26, 2006, 9:21:06 PM6/26/06
to
In article <1151350736.6...@u72g2000cwu.googlegroups.com>,

Robert Hicks <sig...@gmail.com> wrote:
>
>Neil Madden wrote:
>> Robert Hicks wrote:
>> > Robert Hicks wrote:
>> >> Another question would be for Tile support. Since Tile widgets are in
>> >> the format of ttk::widgetname, it shouldn't be too hard to incorporate
>> >> that.
>> >>
>> >> Yes? No?
>> >
>> > I did it anyway. It was easy to do. I added Snit as well since it uses
>> > the same construct.
>>
>> While you're adding stuff from common extensions, it would be useful to
>> have stuff like "class", "type", "self", "this", "method", "public" etc
>> highlighted for when looking through code written with Itcl/Snit/other
>> OO extensions. Many of these terms are pretty common across OO
>> extensions, although you might also want to include XOTcl's Class,
>> instproc, filter, mixin etc (and looking ahead check the syntax for TIP
>> 257), which are pretty much unique to XOTcl.
>>
>
>I will have to look at [incr] Tcl and XOTcl to see what I can clue off
>of. Snit was relatively easy. If it gets messy, I will pull all the OO
>stuff and push those out to extender scripts that extend the basic
>tcl.vim (i.e. xotcl.vim, itcl.vim, snit.vim).

Another vote for itcl (or is already 100% done)?

Also, what about highlighting the args part of:
proc abc { args } {

since args is a special construct?

Thanks for doing this.

MH

Robert Hicks

unread,
Jun 26, 2006, 9:54:57 PM6/26/06
to

I will probably finish this tomorrow. I will be deciding upon generic
OO support (common keywords) or somehow being specific and only
supporting itcl, XOTcl, Snit and oo:: in 8.5.

> Also, what about highlighting the args part of:
> proc abc { args } {
>
> since args is a special construct?
>

I am not sure I can do this cleanly. Since I am not sure how I would
distiguish between the args between { } and everything else between {
}. I will look at it though.

> Thanks for doing this.
>

You are welcome, but I have selfish motives. I use Tcl too! : )

Robert

Eckhard Lehmann

unread,
Jun 27, 2006, 2:47:14 AM6/27/06
to

Robert Hicks wrote:
> I am in the process of updating the "tcl.vim" syntax file. I have some
> things working already like options being colors (i.e. -text, -padx).

What always bothers me with Vim is the indentation mechanism for Tcl.
It works beautiful for C/C++, Java, Python etc... but for Tcl it's
crazy business. I don't know why, since the triggering operators are
almost the same (\(\), \{\} plus \[\] and \\).

Is this difficult to fix?


Eckhard

Victor Wagner

unread,
Jun 27, 2006, 3:26:58 AM6/27/06
to
Eckhard Lehmann <eck...@web.de> wrote:


Yes, it is quite difficult to fix. With all appearent simularity Tcl
have quite different parsing rules. I don't know whether it is
theoretically possible to highlinght Tcl syntax without using Tcl
interpreter (but it is easy to embed Tcl in vim).

: Eckhard


--

Robert Hicks

unread,
Jun 27, 2006, 8:14:50 AM6/27/06
to

It has indeed been a "challenge" looking at how to do some things
because Tcl only has "commands" and not "keywords". So far I think it
is okay. I am trying to stay away from the more esoteric stuff.

The indentation isn't controlled by the tcl.vim file though so I will
not be looking at that. Maybe someone else can and see if it is doable.

:Robert

Robert Hicks

unread,
Jun 27, 2006, 9:39:12 AM6/27/06
to

I did the "all" approach. I targeted itcl, snit, XOTcl and oo:: but the
keywords should help any OO framework. I also have syntax going for
itcl::, snit::, and oo::.

Robert

Robert Hicks

unread,
Jun 27, 2006, 10:10:02 AM6/27/06
to
I just look at the indent file for Tcl under Vim7 and it is current
(Apr 2006) so someone is looking at making it better.

:Robert

MH

unread,
Jun 27, 2006, 1:50:22 PM6/27/06
to
In article <1151390834.1...@i40g2000cwc.googlegroups.com>,

Hmm. Which part of identing don't you like? I think I have it working just
like C/C++..

Here's my (slightly cleaned up) .vimrc.. Maybe it gives you a few ideas?
(vim experts, please, go easy on me: I just hack with it when it doesn't do
what I want. I don't think I could explain half of the tcl settings anymore
without the documentation. :-)

version 6.0
map Q gq
set nowrapscan
set ic
set cindent
set tw=76
set ts=4
set sw=4
set tildeop
set ai
set expandtab
set vb

set indentkeys-=0#
set bs=0
map ^P <ESC>:set invpaste<NL>

autocmd BufRead,BufNewFile Makefile*,makefile*,.*,*.c,*.cc,*.cpp,*.h,*.hpp
set tw=0 cin noic ai
autocmd BufRead,BufNewFile *.c,*.cc,*.cpp,*.h,*.hpp syntax on
autocmd BufRead,BufNewFile Makefile*,makefile*, set noexpandtab
autocmd BufRead,BufNewFile *.tcl set tw=0 cin noic ai
autocmd BufRead,BufNewFile *.tcl set comments=:#
autocmd BufRead,BufNewFile *.tcl set formatoptions+=rq
autocmd BufRead,BufNewFile *.tcl set cinkeys-=0# cinoptions+=+0
autocmd BufRead,BufNewFile *.tcl set indentkeys-=0# bs=0
autocmd BufRead,BufNewFile *.tcl syntax on
autocmd BufRead,BufNewFile .letter*,.article* set tw=76 noic nocin
autocmd BufRead,BufNewFile * set isk-=.

Andreas Leitgeb

unread,
Jun 28, 2006, 9:58:42 AM6/28/06
to
MH <mghe...@harshrealm.uwaterloo.ca> wrote:
> Here's my (slightly cleaned up) .vimrc.. ...

[I'm just quoting/commenting some of the lines:]

> set cindent
> set ai

These are the magic behind indenting.
The latter has nothing to do with artificial intelligence :-)

Alternatively, the "set cindent" can be changed to "set si"
(for smartindent) (it needs ai set, but cindent unset)

Some further .vimrc lines, I like:

" These two give a new(better) meaning to paragraph
" rather than to empty lines, they jump to enclosing braces.
" If you often edit prose texts, rather not use these.
map { [{
map } [}

" For those who jump around a lot using "tags"-file
map <C-n> :tn<C-M>
map <C-p> :tp<C-M>

" Always know, where you are in a file:
set ruler

Glenn Jackman

unread,
Jun 28, 2006, 10:38:06 AM6/28/06
to
I haven't yet seen a pointer to
http://wiki.tcl.tk/vim
in this thread.

Robert Hicks

unread,
Jun 28, 2006, 10:58:27 AM6/28/06
to
Glenn Jackman wrote:
> I haven't yet seen a pointer to
> http://wiki.tcl.tk/vim
> in this thread.
>
Probably because it started out as something different and ended with
specific Vim questions.

Robert

Neil Madden

unread,
Jun 28, 2006, 10:52:10 PM6/28/06
to
Robert Hicks wrote:
>
> I did the "all" approach. I targeted itcl, snit, XOTcl and oo:: but the
> keywords should help any OO framework. I also have syntax going for
> itcl::, snit::, and oo::.

Great! Thanks for taking the time to do this.

-- Neil

Neil Madden

unread,
Jun 28, 2006, 11:05:50 PM6/28/06
to
Robert Hicks wrote:
> Yeah, I will look into just "doing" it as that is the easiest thing in
> the long run. Then I can just look at coloring namespace (i.e. snit::,
> oo:: and whatever XOTcl and itcl use).

I had a quick go with the latest script. It works quite nicely. The
colouring of snit:: etc is a little over-zealous though. For instance,
typing foo::bar will cause everything after the first 'f' to be
highlighted as it matches the oo:: regexp. I'm not sure what the Vim
regexp syntax is to anchor the match to the start of a word (but then
you'd also want to allow for a leading ::). The namespace colouring also
seems to override the keyword highlighting of "class" etc (perhaps that
was intended?).

Anyway, good work.

-- Neil

Robert Hicks

unread,
Jun 29, 2006, 8:15:35 AM6/29/06
to

Good catch...I need to use anchors! Doh.

"class" coloring...mmm I will have to look at that.

:Robert

Eckhard Lehmann

unread,
Jun 30, 2006, 2:35:50 AM6/30/06
to

MH wrote:
> In article <1151390834.1...@i40g2000cwc.googlegroups.com>,
> Eckhard Lehmann <eck...@web.de> wrote:
> >
> >Robert Hicks wrote:
> >> I am in the process of updating the "tcl.vim" syntax file. I have some
> >> things working already like options being colors (i.e. -text, -padx).
> >
> >What always bothers me with Vim is the indentation mechanism for Tcl.
> >It works beautiful for C/C++, Java, Python etc... but for Tcl it's
> >crazy business. I don't know why, since the triggering operators are
> >almost the same (\(\), \{\} plus \[\] and \\).
> >
> >Is this difficult to fix?
>
> Hmm. Which part of identing don't you like? I think I have it working just
> like C/C++..
>
> Here's my (slightly cleaned up) .vimrc.. Maybe it gives you a few ideas?
> (vim experts, please, go easy on me: I just hack with it when it doesn't do
> what I want. I don't think I could explain half of the tcl settings anymore
> without the documentation. :-)

Thank you - I will try this the next time I use Vim for Tcl editing.
Currently I use a different editor & IDE... ;-).


Eckhard

Floria...@siemens.com

unread,
Jul 5, 2006, 6:17:42 AM7/5/06
to
> Now that I look at that list, I am almost done. I am open to
> suggestions as well.


There is an other suggestion, that might go a bit beyond
syntax-highlighting:
When I edit a *.bat file and have a comment line like "@rem ..." and
add another line, I get automatically a "@rem " inserted at the
beginning of the line, so that I can easily write multi-line comments.
- Even the indentation of the comment line is preserved! -
It would be nice to have this feature with tcl-comments!

Alan Anderson

unread,
Jul 5, 2006, 7:29:36 AM7/5/06
to
Floria...@siemens.com wrote:

The pseudo-block-comment idiom
if {0} {
comments...
more comments
}
works for what you're asking.

Glenn Jackman

unread,
Jul 5, 2006, 11:13:04 AM7/5/06
to
At 2006-07-05 06:17AM, Floria...@siemens.com <Floria...@siemens.com> wrote:
> There is an other suggestion, that might go a bit beyond
> syntax-highlighting:
> When I edit a *.bat file and have a comment line like "@rem ..." and
> add another line, I get automatically a "@rem " inserted at the
> beginning of the line, so that I can easily write multi-line comments.
> - Even the indentation of the comment line is preserved! -
> It would be nice to have this feature with tcl-comments!

To do this in vim:
set formatoptions+=crq
set comments+=:#
set autoindent

See also http://wiki.tcl.tk/vim

Mark Smithfield

unread,
Jul 6, 2006, 6:27:42 PM7/6/06
to
I have posted a new tcl syntax file for vim to vim.org.

This file is not a reaction to Robert's recent syntax file, although I
am finally posting due to the interest on the group. This work comes
from much earlier this year, and I intended to release it eventually.

I think it is different enough to warrant posting and to see if it is
useful to anyone else. It does a number of things that the current
syntax coloring scheme does not do.

I see that Robert is the new maintainer of the syntax file. I am glad
of that. I don't have any fixed ideas on the subject, but if any of the
features of this coloring scheme appeal, I will be happy to collaborate
or share.

Mark.

Robert Hicks

unread,
Jul 6, 2006, 8:14:43 PM7/6/06
to

Cool. You should put 'maintainer' in quotes though as the last one just
didn't feel he was doing the thing justice. : )

Mine is just the old + new stuff but yours looks like a re-write. I
will try it out and see how it does.

Off hand, does yours have any namespace stuff or OO stuff?

The more the merrier...I started for the same reason you did to learn
Vim syntax stuff and Tcl as I go.

:Robert

0 new messages