[feature request] snippet aliasing

Bug #889217 reported by Aldis Berjoza
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UltiSnips
Invalid
Undecided
Unassigned

Bug Description

It would be very useful if you could make aliases for snippets

This would help avoiding snippets that have same body, but different name.

For example I have eachpair snippet, which I use in ruby end perl
However I'd like to define each_pair snippet for ruby, which would be absolutely the same as eachpair.

Revision history for this message
SirVer (sirver) wrote :

Are the eachpair snippet the exakt same in both languges? Because it seems like what you want to do is already supported with regular expression snippets:

snippet "each_?pair" "each pair" br
blaaah
endsnippet

this one will trigger on "eachpair" and on "each_pair".

Changed in ultisnips:
status: New → Incomplete
Revision history for this message
Aldis Berjoza (graudeejs) wrote : Re: [Bug 889217] Re: [feature request] snippet aliasing

On Fri, 11 Nov 2011 20:33:40 -0000
SirVer <email address hidden> wrote:

> Are the eachpair snippet the exakt same in both languges? Because it
> seems like what you want to do is already supported with regular
> expression snippets:
>
> snippet "each_?pair" "each pair" br
> blaaah
> endsnippet
>
> this one will trigger on "eachpair" and on "each_pair".

Oh, I didn't know that

No, snippet expands to different content in different languages.
I just generalise common things.
However your suggestion does exactly what I want.

--
Aldis Berjoza
  http://www.bsdroot.lv/

Revision history for this message
SirVer (sirver) wrote :

I set this bug report to invalid than. Glad to be of service.

Changed in ultisnips:
status: Incomplete → Invalid
Revision history for this message
Aldis Berjoza (graudeejs) wrote :

On Fri, 11 Nov 2011 22:39:55 -0000
SirVer <email address hidden> wrote:

> I set this bug report to invalid than. Glad to be of service.
>
> ** Changed in: ultisnips
> Status: Incomplete => Invalid
>

Ok, there is problem with this

snippet "\.Each_?key" "each_key" bri
.each_key { |${1:key}| ${2:# TODO} }${3:$0}
endsnippet

This snippet doesn't work for
  hash.Eachkey
as well as for
  hash.Each_key

However it works for
  .Eachkey
and
  .Eachkey

--
Aldis Berjoza
  http://www.bsdroot.lv/

Revision history for this message
SirVer (sirver) wrote :

The problem is that the full WORD before your cursor is matched for the trigger. Inword and regular expression bite each other. What you want to do can be done like this:

snippet "(.*).Each_?key" "each_key" bri
`!p snip.rv=match.group(1)`.each_key { |${1:key}| ${2:# TODO} }${3:$0}
endsnippet

It essentially looks at the WORD, checks if it matches your regular expression, than takes everything before .Eachkey and prepends it in the python block in your expansion.

Revision history for this message
Aldis Berjoza (graudeejs) wrote :

On Sat, 12 Nov 2011 11:22:46 -0000
SirVer <email address hidden> wrote:

> The problem is that the full WORD before your cursor is matched for
> the trigger. Inword and regular expression bite each other. What you
> want to do can be done like this:
>
> snippet "(.*).Each_?key" "each_key" bri
> `!p snip.rv=match.group(1)`.each_key { |${1:key}| ${2:# TODO} }${3:$0}
> endsnippet
>
> It essentially looks at the WORD, checks if it matches your regular
> expression, than takes everything before .Eachkey and prepends it in
> the python block in your expansion.
>

Awesome. This is exactly what I need... Now I'll be able to write more
advanced snippets.

Huge thanks :D

--
Aldis Berjoza
  http://www.bsdroot.lv/

Revision history for this message
Aldis Berjoza (graudeejs) wrote :

Ok, I discovered flaw with regular expressions

For example:

snippet "(each_?key|for_?in)" "for (<key> in <object>) { ..." r
for (${1:key} in ${2:object}) {
 ${3:document.write($2[$1] + "\n");}
}${4:$0}
endsnippet

would trigger for
SomeBadKeyWordeachkey

So snippet aliasing would be nice to have

Revision history for this message
SirVer (sirver) wrote :

I do not agree. The feature you are looking for is \b Check for word boundary. See the reference for regular expressions http://docs.python.org/library/re.html

snippet "\b(each_?key|for_?in)" "for (<key> in <object>) { ..." r

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.