Fist Example:
{ name = 'meta.line.screenplay'; match = '^(\t{4})([^\t].*)(\s*)'; captures = { 1 = { name = 'whitespace'; }; 2 = { name = 'element.character'; }; 3 = { name = 'element.character.eol'; }; }; },
This works great unless the line I'm working on is the last line of the document, in which case the 3rd capture fails. Which makes a certain amount of sense to me because on the last character of the last line of the document there wouldn't be anything to match, not even a newline.
But the following works...
{ name = 'element.action.screenplay'; match = '^[^\t].*((.|-|?|:|;|,)\s*)'; captures = { 1 = { name = 'element.action.eol'; }; }; },
Which is totally nuts, because it's not all that different than the first example.
My question is this: How can I get the 3rd capture of the first example to work when I'm working on the last line of a document?
On 21/5/2006, at 21:50, Oliver Taylor wrote:
[...] My question is this: How can I get the 3rd capture of the first example to work when I'm working on the last line of a document?
When at the last position of the document, the scope becomes that of the character to the left of the caret (since there is nothing to the right).
What you can do is detect this case and use a slightly different pattern.
For example something like this rule:
{ name = 'meta.end-of-file'; match = '.(?!\n)$'; },
Will make the caret, when at the end of the file, give a scope of `meta.end-of-file`, although since it actually assigns the scope name to the character to the left of the caret, there a) needs to be such character (so if the last line is empty, it won’t work), and b) the second-last position in the document will also get this scope name.