hi,
i wonder if it's possible to "exclude" scopes using the "scope selector" setting for a snippet. for example:
the PHP bundle defines a tab-trigger for "array" that expands to $... = array ... thats fine as long as i am really in the scope "source.php". but when i am writing documentation (phpdoc -- which is in fact "source.php", too) it's really annoying when the 'array' keyword and such get's expanded.
i wonder what's the best solution to solve this ... would i have to define a scope "phpdoc" and overwrite the tab-triggers in there or is there any other solution?
thanks in advance,
harald
Yes your example really hits home with me. I've often been hit by this very case. Hope the community has some good answers as unfortunately I have not solved this.
Ken
On 26 November 2013 10:23, Harald Lapp harald.lapp@gmail.com wrote:
hi,
i wonder if it's possible to "exclude" scopes using the "scope selector" setting for a snippet. for example:
the PHP bundle defines a tab-trigger for "array" that expands to $... = array ... thats fine as long as i am really in the scope "source.php". but when i am writing documentation (phpdoc -- which is in fact "source.php", too) it's really annoying when the 'array' keyword and such get's expanded.
i wonder what's the best solution to solve this ... would i have to define a scope "phpdoc" and overwrite the tab-triggers in there or is there any other solution?
thanks in advance,
harald
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 26 Nov 2013, at 5:23, Harald Lapp wrote:
the PHP bundle defines a tab-trigger for "array" that expands to $... = array ... thats fine as long as i am really in the scope "source.php". but when i am writing documentation (phpdoc -- which is in fact "source.php", too) it's really annoying when the 'array' keyword and such get's expanded.
The most obvious answer is “Don’t hit ⇥ if you don’t want the expansion”.
If that’s not an option for some reason, you can exclude certain parts of the document (assuming you’re in a different scope, like a comment).
See http://manual.macromates.com/en/scope_selectors#excluding_elements
2013/11/26 Rob McBroom mailinglist0@skurfer.com:
On 26 Nov 2013, at 5:23, Harald Lapp wrote:
the PHP bundle defines a tab-trigger for "array" that expands to $... = array ... thats fine as long as i am really in the scope "source.php". but when i am writing documentation (phpdoc -- which is in fact "source.php", too) it's really annoying when the 'array' keyword and such get's expanded.
The most obvious answer is “Don’t hit ⇥ if you don’t want the expansion”.
If that’s not an option for some reason, you can exclude certain parts of the document (assuming you’re in a different scope, like a comment).
it's not an option, because this is (imo) what snippets are for: pressing "tab" to move to the next field in the snippet (template). pressing a "space" before the "tab" is what i currently do, but i often forget it and it is not how it should work, imo.
See http://manual.macromates.com/en/scope_selectors#excluding_elements
thanks, that seems to be what i am looking for. so i would have to define a scope "phpdoc" (for example) and use this to get the desired effect?
harald
2013/11/27 Harald Lapp harald.lapp@gmail.com:
2013/11/26 Rob McBroom mailinglist0@skurfer.com:
On 26 Nov 2013, at 5:23, Harald Lapp wrote:
See http://manual.macromates.com/en/scope_selectors#excluding_elements
yes, it seems to work:
for PHP i've modified the tab trigger for "array" with:
source.php - comment.block.documentation.phpdoc.php
the phpdoc scope is already defined, and so this seems to have the exact effect.
thanks very much again!
harald
Nice. Very happy. Now is there a way to suggest this change to the author of the PHP bundle? ... I think it's a pretty clear improvement; hard to imagine someone not wanting this behaviour.
On 27 November 2013 21:27, Harald Lapp harald.lapp@gmail.com wrote:
2013/11/27 Harald Lapp harald.lapp@gmail.com:
2013/11/26 Rob McBroom mailinglist0@skurfer.com:
On 26 Nov 2013, at 5:23, Harald Lapp wrote:
See http://manual.macromates.com/en/scope_selectors#excluding_elements
yes, it seems to work:
for PHP i've modified the tab trigger for "array" with:
source.php - comment.block.documentation.phpdoc.php
the phpdoc scope is already defined, and so this seems to have the exact effect.
thanks very much again!
harald
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 28 Nov 2013, at 4:56, Ken Snyder wrote:
Nice. Very happy. Now is there a way to suggest this change to the author of the PHP bundle? […]
The preferred way is to click the arrow to the right of PHP in Preferences → Bundles, this will take you to the bundle’s GitHub page.
Then fork the bundle, clone it to ~/Library/Application Support/TextMate/Bundles, make the change(s), git commit and push to your fork on GitHub.
Then submit a pull request (via GitHub).
2013/11/28 Allan Odgaard mailinglist@textmate.org:
On 28 Nov 2013, at 4:56, Ken Snyder wrote:
Nice. Very happy. Now is there a way to suggest this change to the author of the PHP bundle? […]
The preferred way is to click the arrow to the right of PHP in Preferences → Bundles, this will take you to the bundle’s GitHub page.
Then fork the bundle, clone it to ~/Library/Application Support/TextMate/Bundles, make the change(s), git commit and push to your fork on GitHub.
Then submit a pull request (via GitHub).
ok, i am working on it :)
mmm i am little bit unhappy with the solution to change the snippets' tab trigger to "source.php - comment.block.documentation.phpdoc.php", because other tab triggers of scopes source.php inherits from, are of course still active.
i wonder if there is no way to tell a "sub-scope" to not inherit things like tab-triggers? apparently there is not, because i just noticed, that it's the same with for example javascript in html. as somebody wo is used to align assignments like:
var blubber = ''; var base = '';
if have a real problem, because pressing 'tab' behind 'base' will expand to:
var <base href="" target="">
i don't want to annoy anybody with these things, but shouldn't there be a possibility to "reset" all tab-triggers in a sub-scope?
thanks!
harald
2013/11/28 Harald Lapp harald.lapp@gmail.com:
2013/11/28 Allan Odgaard mailinglist@textmate.org:
On 28 Nov 2013, at 4:56, Ken Snyder wrote:
Nice. Very happy. Now is there a way to suggest this change to the author of the PHP bundle? […]
The preferred way is to click the arrow to the right of PHP in Preferences → Bundles, this will take you to the bundle’s GitHub page.
Then fork the bundle, clone it to ~/Library/Application Support/TextMate/Bundles, make the change(s), git commit and push to your fork on GitHub.
Then submit a pull request (via GitHub).
ok, i am working on it :)
On 5 Dec 2013, at 4:45, Harald Lapp wrote:
[…] i wonder if there is no way to tell a "sub-scope" to not inherit things like tab-triggers?
Not per se, but what you can do is create a new macro, the process is a little cumbersome:
Start recording: Edit → Macros → Toggle Macro Recording (⌥⌘M) Press tab in a document (this should not expand a tab trigger) Stop recording: Edit → Macros → Toggle Macro Recording (⌥⌘M) Save macro: Edit → Macros → Save Macro… (⌃⌘M)
This should give you a macro with the following content:
( { command = 'insertTab:'; } )
Now give the macro the tab key as key equivalent and a scope of comment.block.documentation.phpdoc.php.
This will effectively make tab always be a “real” tab in PHP documentation comments.
This is not ideal because it disables all snippets for the above scope, so if you have PHPDoc snippets or other general snippets (inserting current date, author name, etc.) then these will also be disabled.
i don't want to annoy anybody with these things, but shouldn't there be a possibility to "reset" all tab-triggers in a sub-scope?
So far we’ve considered it the responsibility of the bundle item, to limit itself to the proper scope.
I see how this can get tedious, because effectively all code snippets should have “- (string | comment)”, although for strings, some languages can have embedded code in strings, so we need a more complex scope selector there, and likewise for HTML (ensuring that they only fire when in a “proper” HTML scope, not embedded code or commments).
I don’t see an obvious way to specify a “reset” because I don’t think you want to reset everything, e.g. we have an isoD⇥ snippet that I would still want in documentation comments.
So I think what is needed is to declare that certain scopes are “context switches” (source, text, comment, string) and then allow a scope selector to “anchor” the match against the “current” context.
Though having to specify an anchor marker in the scope selector does not fix the issue gracefully, as we’d need to add it to pretty much all scope selectors, so perhaps this should actually be implicit (if the scope selector starts with one of the scopes that is considered a “context switch”), but with a way to not anchor the snippet.
2013/12/5 Allan Odgaard mailinglist@textmate.org:
On 5 Dec 2013, at 4:45, Harald Lapp wrote:
[...]
So far we’ve considered it the responsibility of the bundle item, to limit itself to the proper scope.
I see how this can get tedious, because effectively all code snippets should have “- (string | comment)”, although for strings, some languages can have embedded code in strings, so we need a more complex scope selector there, and likewise for HTML (ensuring that they only fire when in a “proper” HTML scope, not embedded code or commments).
I don’t see an obvious way to specify a “reset” because I don’t think you want to reset everything, e.g. we have an isoD⇥ snippet that I would still want in documentation comments.
So I think what is needed is to declare that certain scopes are “context switches” (source, text, comment, string) and then allow a scope selector to “anchor” the match against the “current” context.
Though having to specify an anchor marker in the scope selector does not fix the issue gracefully, as we’d need to add it to pretty much all scope selectors, so perhaps this should actually be implicit (if the scope selector starts with one of the scopes that is considered a “context switch”), but with a way to not anchor the snippet.
thanks very much for your detailed answer. i now see myself, that things aren't as easy as i thought. the "context switch" thing sounds very good, in the meantime i'll maybe use the macro-workaround.
thanks again for your help, harald