Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to insert conditionnal text
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul Pichaureau  
View profile  
 More options Jul 23 2012, 4:57 am
From: Paul Pichaureau <paul.pichaur...@gmail.com>
Date: Mon, 23 Jul 2012 01:57:27 -0700 (PDT)
Local: Mon, Jul 23 2012 4:57 am
Subject: Re: How to insert conditionnal text

>  I've polished a little the snippet, since I prefer to have some
> description. This is my result:

> # -*- mode: snippet -*-
> # key: rt
> # group: math
> # name : \sqrt[n]{x} or \sqrt{x}  if n is the null string
> # --
> \sqrt${1:$(if (string-equal "<power>" yas/text) ""
> "[")}${1:<power>}${1:$(if (string-equal "<power>" yas/text) "" "]")}{$2}$0

Unfortunately, this doesn't work, as I can't have an empty argument here
(if i press <del>, the yas/text is empty but the [] are typeset..)

Not very important, but if you have an advice, it will be welcomed !

> Thank you very much, it will help me a lot !

> Le dimanche 22 juillet 2012 20:33:27 UTC+2, Joao a écrit :

>> This is the answer I was going to recommend, but I believe you can
>> replace the (string-equal "" yas/text) call with just a call to the
>> (yas/text) function, which returns nil if yas/text is the empty
>> string.

>> I'll test the recursive case when I find the time. Meanwhile maybe you
>> could open an issue at
>> https://github.com/capitaomorte/yasnippet/issues.

>> João

>> On Sun, Jul 22, 2012 at 5:55 PM, OMF <obsessivemathsfr...@gmail.com>
>> wrote:
>> > I managed to solve this problem by using embedded elisp. For example,
>> here
>> > is a latex mode sqrt snippet that will include left and right square
>> > brackets if the field $1 is non empty

>> > # -*- mode: snippet -*-
>> > # key: rt
>> > # group: math
>> > # name : \sqrt[n]{x} or \sqrt{x}  if n is the null string
>> > # --
>> > \sqrt${1:$(if (string-equal "" yas/text) "" "[")}${1:}${1:$(if
>> (string-equal
>> > "" yas/text) "" "]")}{$2}$0

>> > However, there is a problem with calling this recursively, but that is
>> for
>> > another thread.

>> > On Sunday, July 22, 2012 10:42:24 AM UTC+1, Paul Pichaureau wrote:

>> >> Hi,

>> >> I'm a new user of yasnippet, and I really enjoy it! It helps me *a
>> lot* !

>> >> I use a lot of command on LaTeX with key syntax. I would like to make
>> some
>> >> part of snippet disappear if the I don't enter a string. For example

>> >> test<Tab>

>> >> will produce

>> >> \test[title={_}]

>> >> (the underscore is the cursor)

>> >> Now if I type <Tab>, the resulting text in the buffer should be

>> >> \test

>> >> But if i type 'doo', I would like to see

>> >> \test[title={doo}]

>> >> Do you know if it's possible ?

>> >> Thank you very much !

>> >> --
>> >>   Paul Pichaureau

>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "smart-snippet and YASnippet" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/smart-snippet/-/rL_MZIEVR_sJ.

>> > To post to this group, send email to smart-snippet@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > smart-snippet+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/smart-snippet?hl=en.

>> --
>> João Távora


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.