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
How to insert conditionnal text
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
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 22 2012, 5:42 am
From: Paul Pichaureau <paul.pichaur...@gmail.com>
Date: Sun, 22 Jul 2012 02:42:24 -0700 (PDT)
Local: Sun, Jul 22 2012 5:42 am
Subject: How to insert conditionnal text

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 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.
OMF  
View profile  
 More options Jul 22 2012, 12:55 pm
From: OMF <obsessivemathsfr...@gmail.com>
Date: Sun, 22 Jul 2012 09:55:25 -0700 (PDT)
Local: Sun, Jul 22 2012 12:55 pm
Subject: Re: How to insert conditionnal text

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.


 
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.
João Távora  
View profile  
 More options Jul 22 2012, 2:33 pm
From: João Távora <joaotav...@gmail.com>
Date: Sun, 22 Jul 2012 19:33:27 +0100
Local: Sun, Jul 22 2012 2:33 pm
Subject: Re: How to insert conditionnal text
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

--
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.
OMF  
View profile  
 More options Jul 22 2012, 4:05 pm
From: OMF <obsessivemathsfr...@gmail.com>
Date: Sun, 22 Jul 2012 13:05:26 -0700 (PDT)
Local: Sun, Jul 22 2012 4:05 pm
Subject: Re: How to insert conditionnal text

Sorry, but I am not signed up to github at the moment.

After some checking, I believe it is the case that yas does not in fact
execute any lisp code at all while in a nested snippet. But I cannot
confirm this with certainty.


 
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.
Paul Pichaureau  
View profile  
 More options Jul 23 2012, 3:57 am
From: Paul Pichaureau <paul.pichaur...@gmail.com>
Date: Mon, 23 Jul 2012 00:57:22 -0700 (PDT)
Local: Mon, Jul 23 2012 3:57 am
Subject: Re: How to insert conditionnal text

It works fine! Thank you!

This is the shortest version:

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

 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

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

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


 
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.
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 !


 
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.
Dror Atariah  
View profile  
 More options Jul 25 2012, 1:25 am
From: Dror Atariah <dror...@gmail.com>
Date: Tue, 24 Jul 2012 22:25:26 -0700 (PDT)
Local: Wed, Jul 25 2012 1:25 am
Subject: Re: How to insert conditionnal text

Very nice idea!

I'm trying out this code:
# -*- mode: snippet -*-
# key: sqrt
# group: Math
# name: Sq. Root
# --
\sqrt${1:$(if (yas/text) "[" "")}${1:}${1:$(if (yas/text) "]" "")}{$2}$0

But it doesn't work. If I enter the text into the optional "[_]" field then
everything is fine. Otherwise, if I hit: "sqrt [TAB] [TAB]" in order to
leave the optional field empty, the result is: \sqrt{} and the courser is
located on the "s". What am I doing wrong?


 
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.
Anders Eurenius  
View profile  
 More options Jul 25 2012, 4:15 am
From: Anders Eurenius <c96...@gmail.com>
Date: Wed, 25 Jul 2012 10:15:18 +0200
Local: Wed, Jul 25 2012 4:15 am
Subject: Re: How to insert conditionnal text
I tried this by making a new snippet for text mode, reload-all:ed and
tried it, but it just ate the sqrt word, without any error message or
anything. (Is this a known bug?) Then I tried changing it around some,
and it started working.. Lastly, I noticed I was back to the exact
same original snippet, so no, it wasn't anything in the snippet.

This feels like an annoyingly common problem. Is there any way to make
yasnippet more talkative?

aes

---
I'm on the debian stable GNU Emacs 23.2.1 (x86_64-pc-linux-gnu, GTK+
Version 2.20.1) and 0.7.0 (d3fc5cd) of yasnippet.


 
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.
End of messages
« Back to Discussions « Newer topic     Older topic »