[TxMt] Informative text for snippets

Édouard Gilbert edouard.gilbert at eleves.bretagne.ens-cachan.fr
Tue Aug 7 23:31:38 UTC 2007


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




More information about the textmate mailing list