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
Yes? No?
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
Do you know if it is a common thing to do that in Tcl?
Robert
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
I did it anyway. It was easy to do. I added Snit as well since it uses
the same construct.
Robert
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
>
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
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 "{}[];".
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
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
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
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
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
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
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
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
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
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
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
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
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
--
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
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
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-=.
[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
Robert
Great! Thanks for taking the time to do this.
-- Neil
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
Good catch...I need to use anchors! Doh.
"class" coloring...mmm I will have to look at that.
:Robert
Thank you - I will try this the next time I use Vim for Tcl editing.
Currently I use a different editor & IDE... ;-).
Eckhard
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!
The pseudo-block-comment idiom
if {0} {
comments...
more comments
}
works for what you're asking.
To do this in vim:
set formatoptions+=crq
set comments+=:#
set autoindent
See also http://wiki.tcl.tk/vim
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.
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