Hi everyone,
I'm wondering if there was a mean to insert some kind of “informative text” in a snippet, i.e. text that informs you of what should be inserted where but disappears when it's not needed any longer.
Here's a short example (a method definition in some Lisp dialect) of a problem I currently face that should make the situation a bit clearer.
Here is what I'd want to appear with my defmethod snippet, with “normal” default text between [ ] and informative text between { } :
(defmethod [name] ({parameters}) ({code}))
The parameters are written as “(name type)”, so when I reach the {parameters}, the first thing I do is adding a parenthesis. Result: the default text (“parameters”) is still there, but now unselected and between parenthesis. I thus have to remove it by hand, which is quite annoying. Of course, a possibility is to let the default string empty, but you can easily get lost in your structure, then (especially in Lisp). So is there a way to have text reminding you what you should be typing, but disappearing after a while (ideally, when you hit tab in order to jump to the next snippet point or when you reach $0)?
Thank you very much, Édouard
On Aug 7, 2007, at 12:10 PM, Édouard Gilbert wrote:
Hi everyone,
I'm wondering if there was a mean to insert some kind of “informative text” in a snippet, i.e. text that informs you of what should be inserted where but disappears when it's not needed any longer.
Here's a short example (a method definition in some Lisp dialect) of a problem I currently face that should make the situation a bit clearer.
Here is what I'd want to appear with my defmethod snippet, with “normal” default text between [ ] and informative text between { } :
(defmethod [name] ({parameters}) ({code}))
The parameters are written as “(name type)”, so when I reach the {parameters}, the first thing I do is adding a parenthesis. Result: the default text (“parameters”) is still there, but now unselected and between parenthesis. I thus have to remove it by hand, which is quite annoying. Of course, a possibility is to let the default string empty, but you can easily get lost in your structure, then (especially in Lisp). So is there a way to have text reminding you what you should be typing, but disappearing after a while (ideally, when you hit tab in order to jump to the next snippet point or when you reach $0)?
Not sure if this helps, and you haven't provided the snippet text so that we could make changes there, but one way to go about it is to not expect someone to type the parentheses, instead having them as part of the snippet, as an extra tab trigger, like so:
${1:(${2:parameters})}
Thank you very much, Édouard
Haris Skiadas Department of Mathematics and Computer Science Hanover College
Le 7 août 07 à 20:14, Charilaos Skiadas a écrit :
On Aug 7, 2007, at 12:10 PM, Édouard Gilbert wrote:
Here is what I'd want to appear with my defmethod snippet, with “normal” default text between [ ] and informative text between { } :
(defmethod [name] ({parameters}) ({code}))
The parameters are written as “(name type)”, so when I reach the {parameters}, the first thing I do is adding a parenthesis. Result: the default text (“parameters”) is still there, but now unselected and between parenthesis. I thus have to remove it by hand, which is quite annoying. Of course, a possibility is to let the default string empty, but you can easily get lost in your structure, then (especially in Lisp). So is there a way to have text reminding you what you should be typing, but disappearing after a while (ideally, when you hit tab in order to jump to the next snippet point or when you reach $0)?
Not sure if this helps, and you haven't provided the snippet text so that we could make changes there, but one way to go about it is to not expect someone to type the parentheses, instead having them as part of the snippet, as an extra tab trigger, like so:
${1:(${2:parameters})}
Woups, sorry. Here it is. Please ignore the '!'.
(defmethod! ${1:name} (${2:parameters}) :initval '($3) :indoc '($4) :doc "${5:Documentation for $1.}" $0 )
I don't know if your suggestion would lead to:
(defmethod! ${1:name} ${2:(${3:parameters})} (...) $0 )
In that case, the problem is that the external parenthesis are compulsory. A method without argument (for which I can't think of a single use in CLOS) would be written as
(defmethod foo () [...] )
Thus having the parenthesis inside the $2 seems a bad idea, as it shouldn't be possible to remove them while typing.
If instead, you meant switching to
(defmethod! ${1:name} (${2:(${3:parameters})}) (...) $0 )
In that case, the situation is pretty much the same as before. It's just that, instead of hitting delete before actually typing code, one would have to hit tab. Ideally, the solution would be for the text to disappear when one hit '(', but only in this context (I can't get rid of the otherwise so useful auto-bracketing function, especially when coding in Lisp).
I was thinking about overriding the '(' key between the parenthesis in the right scope, i.e. between the parentheses around the parameters, but not in the parameters themselves, an replace it by a simple '($0)' snippet. Does it seems a feasible solution?
Édouard
On Aug 7, 2007, at 7:31 PM, Édouard Gilbert wrote:
Le 7 août 07 à 20:14, Charilaos Skiadas a écrit :
On Aug 7, 2007, at 12:10 PM, Édouard Gilbert wrote:
Woups, sorry. Here it is. Please ignore the '!'.
(defmethod! ${1:name} (${2:parameters}) :initval '($3) :indoc '($4) :doc "${5:Documentation for $1.}" $0 )
[snip]
Thus having the parenthesis inside the $2 seems a bad idea, as it shouldn't be possible to remove them while typing.
If instead, you meant switching to
(defmethod! ${1:name} (${2:(${3:parameters})}) (...) $0 )
In that case, the situation is pretty much the same as before. It's just that, instead of hitting delete before actually typing code, one would have to hit tab. Ideally, the solution would be for the text to disappear when one hit '(', but only in this context (I can't get rid of the otherwise so useful auto-bracketing function, especially when coding in Lisp).
I was thinking about overriding the '(' key between the parenthesis in the right scope, i.e. between the parentheses around the parameters, but not in the parameters themselves, an replace it by a simple '($0)' snippet. Does it seems a feasible solution?
I think that trying to override '(' in the right scope will not be easy to do. I think your problem really arises from the fact that you want the word "parameters" to be there. Why not simply use $2 instead of ${2:parameters}, like you have $3 with no default value? It seems that would solve your problems, at the small cost of having to remember what you are supposed to place at the second tab stop. I think that any other solution would be too cumbersome compared to this simple change.
Édouard
Haris Skiadas Department of Mathematics and Computer Science Hanover College
Le 8 août 07 à 01:48, Charilaos Skiadas a écrit :
I was thinking about overriding the '(' key between the parenthesis in the right scope, i.e. between the parentheses around the parameters, but not in the parameters themselves, an replace it by a simple '($0)' snippet. Does it seems a feasible solution?
I think that trying to override '(' in the right scope will not be easy to do. I think your problem really arises from the fact that you want the word "parameters" to be there. Why not simply use $2 instead of ${2:parameters}, like you have $3 with no default value? It seems that would solve your problems, at the small cost of having to remember what you are supposed to place at the second tab stop. I think that any other solution would be too cumbersome compared to this simple change.
Well, of course, it would be easy in that case. But even for a quite simple macro, that I use from time to time, which computes
{ f(x, y) | x \in A, y \in B when test(x,y) } — eventually with more variables, of course
and whose structure is
(make-comprehension (f x y) ((x A) (y B)) ((test x y)))
which would give a snippet such as
(make-comprehension $1 ($2) ($3))
I always spend some time searching through my code to spot an example to get the order right, forget one or two brackets and loose some time before spotting the misused structure until I get it right. In practice, I don't even use a snippet, copy-paste is more efficient. I could probably if it was written as, let's say
(make-comprehension ${1:expression} (${2:list of variables' spans}) ($ {3:list of tests}))
In the end, it's not a major problem, but it's quite annoying. And Lisp already make me loose my temper easily.
Édouard
On Aug 7, 2007, at 8:32 PM, Édouard Gilbert wrote:
Le 8 août 07 à 01:48, Charilaos Skiadas a écrit :
I was thinking about overriding the '(' key between the parenthesis in the right scope, i.e. between the parentheses around the parameters, but not in the parameters themselves, an replace it by a simple '($0)' snippet. Does it seems a feasible solution?
[...]
[...] In the end, it's not a major problem, but it's quite annoying. And Lisp already make me loose my temper easily.
I’ve commented in the past on this; basically nothing to do about it, but I hope to introduce a system to disable smart-typing for fully selected snippet placeholders.