Hi, I started to customize the highlighting for Perl code with this code in my personal Bundle:
{ patterns = ( { name = 'comment.line.debug.perl'; match = '\bi ''.*'';|\bi ".*";|\bi q{.*};|\bi qq{.*};'; }, ); }
This works fine, so that all lines like `i '…';` are now formatted like a comment (`#`).
But it has some side-effects: E.g. the change from double-quotes to single-quotes by pressing `Ctrl+Shift+"` does not work any more. Plus I would like to change the formatting (color, ...) to something different.
What would be the the best way?
On 3 Apr 2014, at 13:45, Ingo Lantschner wrote:
[…] But it has some side-effects: E.g. the change from double-quotes to single-quotes by pressing `Ctrl+Shift+"` does not work any more. Plus I would like to change the formatting (color, ...) to something different.
What would be the the best way?
To make toggling quotes work, add proper scope to the string part, e.g.:
{ patterns = ( { name = 'comment.line.debug.perl'; match = '\bi ((''.*'')|(".*")|(q{.*})|(qq{.*}));'; }, captures = { 2 = { name = 'string.quoted.single'; }; 3 = { name = 'string.quoted.double'; }; 4 = { name = 'string.quoted.other.q.perl'; }; 5 = { name = 'string.quoted.other.qq.perl'; }; }; );
As for formatting, this would need to be added to the current theme (or possibly as global settings).
Here you would target `comment.line.debug.perl` in the theme.
On 3 Apr 2014, at 9:03, Allan Odgaard wrote:
On 3 Apr 2014, at 13:45, Ingo Lantschner wrote:
[…] But it has some side-effects: E.g. the change from double-quotes to single-quotes by pressing `Ctrl+Shift+"` does not work any more. Plus I would like to change the formatting (color, ...) to something different.
What would be the the best way?
To make toggling quotes work, add proper scope to the string part, e.g.:
{ patterns = ( { name = 'comment.line.debug.perl'; match = '\bi ((''.*'')|(".*")|(q{.*})|(qq{.*}));'; }, captures = { 2 = { name = 'string.quoted.single'; }; 3 = { name = 'string.quoted.double'; }; 4 = { name = 'string.quoted.other.q.perl'; }; 5 = { name = 'string.quoted.other.qq.perl'; }; }; );
hmh, the code above did not parse. I changed it to this one, which I could save:
{ patterns = ( { name = 'comment.line.debug.perl'; match = '\bi ''.*'';|\bi ".*";|\bi q{.*};|\bi qq{.*};'; captures = { 2 = { name = 'string.quoted.single'; }; 3 = { name = 'string.quoted.double'; }; 4 = { name = 'string.quoted.other.q.perl'; }; 5 = { name = 'string.quoted.other.qq.perl'; }; }; }, ); }
But it still has no effect on the toggling of quotes. Just to avoid miss-understandings: This is part of my personal bundle (Language Grammar, Grammar: source.untitled, Injection-Selector: source.perl)
As for formatting, this would need to be added to the current theme (or possibly as global settings).
Here you would target `comment.line.debug.perl` in the theme.
Ok, thanks! How could I create a new "target", completely unrelated to comments. The present solution, to treat lines starting with `i` as comments is more a workaround. In fact these lines are valid and executed Perl code. What I really would like to see, is that they are **presented** (but not treated) like comments.
Kind regards, Ingo
On 8 Apr 2014, at 13:37, Ingo Lantschner wrote:
To make toggling quotes work, add proper scope to the string part, e.g.: […]
hmh, the code above did not parse. I changed it to this one […]
That lost the changes I made to the match pattern (to collect the captures). Should have been:
{ patterns = ( { name = 'comment.line.debug.perl'; match = '\bi ((''.*'')|(".*")|(q{.*})|(qq{.*}));'; captures = { 2 = { name = 'string.quoted.single'; }; 3 = { name = 'string.quoted.double'; }; 4 = { name = 'string.quoted.other.q.perl'; }; 5 = { name = 'string.quoted.other.qq.perl'; }; }; } ); }
But it still has no effect on the toggling of quotes.
The above should use the proper syntax.
[…] How could I create a new "target", completely unrelated to comments. The present solution, to treat lines starting with `i` as comments is more a workaround. In fact these lines are valid and executed Perl code. What I really would like to see, is that they are **presented** (but not treated) like comments.
In your injected rule, change ‘comment.line.debug.perl’ to e.g. ‘meta.statement.debug.perl’.
After this, go to Themes → Themes → «the theme you are using» and locate the rule that styles comments.
Duplicate it and change the name/scope seletor, e.g. make it:
{ name = 'Debug Statements'; scope = 'meta.statement.debug'; settings = { fontStyle = 'italic'; foreground = '#5F5A60'; }; },
Thanks Allen - works exactly as it should - just perfect your help!
![](cid:429A9D49-DAEA-41F2-9413-D698864D7D8B@lantschner.name "PastedImage.png")