Hello!
I try to develop my first bundle for Jess, a rule base language. For that I defined a snippet
(defrule ${1:rulename} "${2:description}" ${3:patterns} => ${4:actions} ) Now I want to invoke an other snippets
(MAIN::$1) invoked by main->tab at ${3:patterns}. But when I hit the tab, the cursor jumps to ${4:actions}. So, can you recommend something? I think I could simply use key bindings. But I like much more the tab trigger.
Helge
Helge Hartmann Antwort an: helge.hartmann@gmx.de
On 13/11/06, Helge Hartmann helge.hartmann@gmx.de wrote:
I try to develop my first bundle for Jess, a rule base language. For that I defined a snippet
(defrule ${1:rulename} "${2:description}" ${3:patterns} => ${4:actions} )
Now I want to invoke an other snippets
(MAIN::$1) invoked by main->tab at ${3:patterns}. But when I hit the tab, the cursor jumps to ${4:actions}. So, can you recommend something? I think I could simply use key bindings. But I like much more the tab trigger.
I wanted to do exactly the same thing, but as far as I can tell you can't. I'd also really like for the snippets to be properly nested, such that when you finish the second one, it carries on with the rest of the first.
I'd also really like to be able to reference tab-stops from the first snippet in the second snippet.
However I don't think any of these things are currently possible.
Ed
I wanted to do exactly the same thing, but as far as I can tell you can't. I'd also really like for the snippets to be properly nested, such that when you finish the second one, it carries on with the rest of the first.
Right this is not possible right now. You can only envoke another snippet after you reach $0 (which is reached after you tab past the last placeholder), or you break out of the snippet mode by moving outside the snippet, etc.
On 14/11/06, Allan Odgaard throw-away-1@macromates.com wrote:
On 13. Nov 2006, at 15:04, Ed Singleton wrote:
I'd also really like to be able to reference tab-stops from the first snippet in the second snippet.
How would that work?
Well, using a (grossly oversimplified) use case of a html form. Let's say you have a form snippet and lots of field snippets.
Sometimes you want to prepend the id of the form to the id of the fields:
<form id="my_form"> <input id="my_form_field_1"> ...
You would activate the form snippet, fill various tab stops then come to put in a field. Activate that snippet, which would automatically prepend the id of the form to the id of the field. When you reach tabstop $0 of the field snippet, it then carries on with the tabstops from the form snippet.
I was assuming you would have to use named tab stops rather than numbered ones (${foo} rather than $1) or maybe there would be a syntax for saying something like ${parent.1}.
I guess really, as python is my main language, I'm thinking in terms of python's scoping and namespaces, so that you can use variables with the same name as those in a higher scope without any problems, but if you haven't named one in the current scope, it access the one from a higher scope.
A way to 'fake' it would be just to allow tabstops to create temporary variables that existed for the length of the snippet (and were accessible to sub-snippets). Something like ${1>$MY_FORM_ID}
Hope this makes at least some sense.
Ed
On 14. Nov 2006, at 14:55, Ed Singleton wrote:
I'd also really like to be able to reference tab-stops from the
first
snippet in the second snippet.
How would that work?
Well, using a (grossly oversimplified) use case of a html form. Let's say you have a form snippet and lots of field snippets.
Sometimes you want to prepend the id of the form to the id of the fields:
<form id="my_form"> <input id="my_form_field_1"> [...]
Ah, okay -- well, I think the best way to solve this is to instead let the snippet be generated by a command, which takes the form as input, and extracts the ID. Then the “child snippet” will also work as expected, even when not invoked inside the parent one.
But I do like the idea, though would need more use cases for me to really be behind it -- but now that you’ve planted a seed, maybe I’ll start to see them :)
On 14/11/06, Allan Odgaard throw-away-1@macromates.com wrote:
On 14. Nov 2006, at 14:55, Ed Singleton wrote:
I'd also really like to be able to reference tab-stops from the
first
snippet in the second snippet.
How would that work?
Well, using a (grossly oversimplified) use case of a html form. Let's say you have a form snippet and lots of field snippets.
Sometimes you want to prepend the id of the form to the id of the fields:
<form id="my_form"> <input id="my_form_field_1"> [...]
Ah, okay -- well, I think the best way to solve this is to instead let the snippet be generated by a command, which takes the form as input, and extracts the ID. Then the "child snippet" will also work as expected, even when not invoked inside the parent one.
But I do like the idea, though would need more use cases for me to really be behind it -- but now that you've planted a seed, maybe I'll start to see them :)
I've been working quite heavily on Jonathan LaCour's TurboGears bundle, and I have some snippets that end up three levels deep (a form snippet which you fill with field snippets which you fill with validator snippets). There's quite a few times I'd like to have referred back to a form name or field name that the user entered, to use it as a default value in the error messages in the validator. (I'm hoping to clean up the bundle and release it next week, so you'll see better what I mean then).
The idea of creating snippets dynamically through a command seems quite powerful, but a lot more difficult (maybe just to me as I'm always reluctant to do parsing or regexs).
The other idea I had was some sort of data grammar, like language grammars, that presented the user with options at various points. That's obviously a very long term kind of idea, but one that could be powerful for entering highly structured data (like forms and database models). There are a limited set of options at every stage, so if you could define what those options are, an easy way of choosing them (such as drop down lists) could be presented to the user.
Ed
On 15. Nov 2006, at 09:58, Ed Singleton wrote:
I've been working quite heavily on Jonathan LaCour's TurboGears bundle, and I have some snippets that end up three levels deep (a form snippet which you fill with field snippets which you fill with validator snippets). There's quite a few times I'd like to have referred back to a form name or field name that the user entered, to use it as a default value in the error messages in the validator.
I wonder if not a better solution would be to better support this in TG.
[...] The idea of creating snippets dynamically through a command seems quite powerful, but a lot more difficult (maybe just to me as I'm always reluctant to do parsing or regexs).
Harder, yes -- but something to be said for that thing about making common things easy, and uncommon things possible.
The other idea I had was some sort of data grammar, like language grammars, that presented the user with options at various points. [...]
There will be pop-ups to select between options in snippets sometime in the future.