Hi all,
I'm looking to extend the definition of a comment in the textmate syntax highlighting, but I'm not quite sure how to achieve the effect I'm after.
I frequently comment out snippets of code by sticking `if (false) { ... }` around the code. The other variation I use is to convert an existing condition into a comment: `if (false && previous condition) { ... }`. You don't want to over-use this idiom, but it is useful in its place.
At the moment TextMate treats this just like normal code (which is exactly what you'd expect). I was wondering if there was a way to make TextMate see these patterns as comments. It isn't easy as you really want to pick the right brace to close the comment. There could be further blocks of code nested inside the 'comment block'.
This isn't a huge priority for me, but I thought I'd raise it and see if anyone had any obvious solutions.
Be well,
Will :-}
William Uther wrote:
I frequently comment out snippets of code by sticking `if (false) { ... }` around the code. The other variation I use is to convert an existing condition into a comment: `if (false && previous condition) { ... }`. You don't want to over-use this idiom, but it is useful in its place.
At the moment TextMate treats this just like normal code (which is exactly what you'd expect). I was wondering if there was a way to make TextMate see these patterns as comments. It isn't easy as you
I'm not an expert on TM grammars, but it seems to me that preprocessor-rule-disabled is probably a good start, using the handy predefined block pattern to get the right scope.
(BTW: The C language definition includes a couple of things I can't remember seeing before: iterate? riterate? Can someone explain these? And I thought new was a C++ keyword, not C?)
really want to pick the right brace to close the comment. There could be further blocks of code nested inside the 'comment block'.
Also, don't forget about the else block at the end and about the 'if (true || whatever)' things. And while I believe VC 2005 doesn't accept them, the C standard also allows 'if (false and whatever)'. :-)
Christopher
On 26 May 2009, at 08:10, Christopher Creutzig wrote:
(BTW: The C language definition includes a couple of things I can't remember seeing before: iterate? riterate? Can someone explain these? And I thought new was a C++ keyword, not C?)
The iterate/riterate keywords are not standard but some macros I often use (they do beginof/endof on the container argument to obtain STL- conforming iterators, and I then have begin/endof overloads for practically everything, including primitive arrays, Cocoa containers, etc.).
They are in the grammar only to avoid having them be mistaken for a function prototype. As for ‘new’ it probably needed to be in the C grammar due to how it takes over parsing certain constructs even when included from C++.
On Mon, May 25, 2009 at 6:47 PM, William Uther willu.mailingLists@cse.unsw.edu.au wrote:
I was wondering if there was a way to make TextMate see these patterns as comments.
Comments are defined per-language, so you'd have to edit the language grammar of whatever code you're writing in. Edit either the language itself or, if the bundle has it, the comment preference item. It would look something like this:
{name = 'comment'; begin = '\bif (flase) {'; end = '}'; },
It isn't easy as you really want to pick the right brace to close the comment.
That would be up to the regex you define.
There could be further blocks of code nested inside the 'comment block'.
In theory it would work. Search for "code repositories" for more info.