Moving one char backward when expanding the snippet

114 views
Skip to first unread message

Dror Atariah

unread,
Jul 12, 2012, 10:10:13 AM7/12/12
to smart-...@googlegroups.com
I'm trying to write a snippet which will expand to "\footnote{}" in LaTeX. The problem is the final code should look like:
Hello World\footnote{The footnote}

The goal is to be able to type the following:
w o r d SPC f o o t TAB
which will expand to:
word\footnote{}
I manage to get the following result:
word \footnote{}
Note the space after 'word' which must not be there.

I'm trying to use the backward-char function in the following way:
`(backward-char 1)`\footnote{$1}$2
but this doesn't work... I keep getting the space after the last word.

How can I avoid this? What is the right way to go?

Joao

unread,
Jul 12, 2012, 2:23:51 PM7/12/12
to smart-...@googlegroups.com
This is interesting and *might* be a use for the issue described in https://github.com/capitaomorte/yasnippet/issues/28. I've added your email to the issue and you can track it's implementation there/solution there.

Thanks,
João

Dror Atariah

unread,
Jul 12, 2012, 3:27:05 PM7/12/12
to smart-...@googlegroups.com
So you're saying that my code is correct but there's some feature/bug which doesn't make it happen as expected? I have to say I didn't understand much from the link you added, as I am a newbie to lisp...

João Távora

unread,
Jul 12, 2012, 6:48:05 PM7/12/12
to smart-...@googlegroups.com
Hi,

On Thu, Jul 12, 2012 at 8:27 PM, Dror Atariah <dro...@gmail.com> wrote:
> So you're saying that my code is correct but there's some feature/bug which
> doesn't make it happen as expected? I have to say I didn't understand much
> from the link you added, as I am a newbie to lisp...

More or less, but you're right I didn't make myself very clear. I
*was* saying that the behaviour you request might not be currently
supported by yasnippet in its current state and that the feature
requested in https://github.com/capitaomorte/yasnippet/issues/28
would, in principle, allow you to write a little addition to your
snippet that makes it work like you intend it to.

But I have analysed this a bit more and remembered that yasnippet
*can* already solve your problem if you write your snippet as a
snippet-command. Try this

# -*- mode: snippet -*-
# name: latex footnote
# key: foot
# type: command
# --
(skip-syntax-backward " ")
(yas/expand-snippet "\\footnote{${1:the footnote test}}")






>
>
> On Thursday, July 12, 2012 8:23:51 PM UTC+2, Joao wrote:
>>
>> This is interesting and *might* be a use for the issue described in
>> https://github.com/capitaomorte/yasnippet/issues/28. I've added your email
>> to the issue and you can track it's implementation there/solution there.
>>
>> Thanks,
>> João
>>
>> On Thursday, July 12, 2012 3:10:13 PM UTC+1, Dror Atariah wrote:
>>>
>>> I'm trying to write a snippet which will expand to "\footnote{}" in
>>> LaTeX. The problem is the final code should look like:
>>> Hello World\footnote{The footnote}
>>>
>>> The goal is to be able to type the following:
>>> w o r d SPC f o o t TAB
>>> which will expand to:
>>> word\footnote{}
>>> I manage to get the following result:
>>> word \footnote{}
>>> Note the space after 'word' which must not be there.
>>>
>>> I'm trying to use the backward-char function in the following way:
>>> `(backward-char 1)`\footnote{$1}$2
>>> but this doesn't work... I keep getting the space after the last word.
>>>
>>> How can I avoid this? What is the right way to go?
>
> --
> 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/-/e_AkB9gwbpkJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to
> smart-snippe...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/smart-snippet?hl=en.



--
João Távora

Dror Atariah

unread,
Jul 13, 2012, 2:49:36 AM7/13/12
to smart-...@googlegroups.com
Good morning,
 
But I have analysed this a bit more and remembered that yasnippet
*can* already solve your problem if you write your snippet as a
snippet-command. Try this

# -*- mode: snippet -*-
# name: latex footnote
# key: foot
# type: command
# --
(skip-syntax-backward " ")
(yas/expand-snippet "\\footnote{${1:the footnote test}}")
This doesn't work - it just expands to the plain text in the code above and seems like it doesn't evaluate the lisp code. 

João Távora

unread,
Jul 13, 2012, 3:26:49 AM7/13/12
to smart-...@googlegroups.com
You have to have a relatively recent version of yasnippet, i.e. 0.6
will *no* work. Which are you using?

If you're using a recent version, how exactly did you install the
snippet and attempt to expand the I provided?
> --
> 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/-/tdgwyv0Mn34J.

Dror Atariah

unread,
Jul 13, 2012, 4:26:20 AM7/13/12
to smart-...@googlegroups.com
I'm using Aquamacs, and clicking YASnippet->About yields: "yasnippet (version 0.6.1b). If I understand correctly, the next version is 0.6.1c? would it make a difference?
> 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
> 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
> smart-snippet+unsubscribe@googlegroups.com.

João Távora

unread,
Jul 13, 2012, 5:43:22 AM7/13/12
to smart-...@googlegroups.com
No, it wouldn't. You need to either wait for the official 0.7 or visit
http://github.com/capitaomorte/yasnippet and follow instructions there
to install the most recent version.
>> > smart-snippe...@googlegroups.com.
>> > smart-snippe...@googlegroups.com.
>> > smart-snippe...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/smart-snippet?hl=en.
>>
>>
>>
>> --
>> João Távora
>
> --
> 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/-/1xOxTPFDJFcJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to
> smart-snippe...@googlegroups.com.

Dror Atariah

unread,
Jul 13, 2012, 8:36:29 AM7/13/12
to smart-...@googlegroups.com
I installed the newest version and your snippet doesn't work at all... "foot[TAB]" does nothing.

João Távora

unread,
Jul 13, 2012, 9:53:49 AM7/13/12
to smart-...@googlegroups.com
I can't help you with such a poor description. Please provide a
complete description of your problem, detailing all the steps you
performed. Use a "reproduction recipe", if possible, starting with a
clean "emacs -Q" run.

Thanks!
João



On Fri, Jul 13, 2012 at 1:36 PM, Dror Atariah <dro...@gmail.com> wrote:
> I installed the newest version and your snippet doesn't work at all...
> "foot[TAB]" does nothing.
>
> --
> 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/-/WorU5zW6RRcJ.

Dror Atariah

unread,
Jul 13, 2012, 10:49:21 AM7/13/12
to smart-...@googlegroups.com
Sorry, I'll try to describe what I did, although I think it is rather the straightest you get.
  1. First, I'll mention this again, I'm using 'Aquamacs' on Mac OS X.
  2. I downloaded the latest version from the repository into my '~/Library/elisp' directory.
  3. Copied my snippets to the new version (I know I can probably somehow leave the snippets somewhere else, I tried to do it quickly).
  4. Closed and opened 'Aquamacs' and tested YASNIPPET. Everything OK so far.
  5. Tried to run the snippet in question (after copy pasting your code to a new snippet. Saving it along with the other snippets and 'yas/reload-all'. Nothing happen. That is 'foo foot[TAB]' yields 'foo foot'. 

On Friday, July 13, 2012 3:53:49 PM UTC+2, Joao wrote:
I can't help you with such a poor description. Please provide a
complete description of your problem, detailing all the steps you
performed. Use a "reproduction recipe", if possible, starting with a
clean "emacs -Q" run.
I don't know what 'emacs -Q' does, and I couldn't find 'Aquamacs' equivalent. Sorry...

Is it better now?

Thanks a lot!
Dror
 

Thanks!
João



On Fri, Jul 13, 2012 at 1:36 PM, Dror Atariah <dro...@gmail.com> wrote:
> I installed the newest version and your snippet doesn't work at all...
> "foot[TAB]" does nothing.
>
> --
> 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/-/WorU5zW6RRcJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to

João Távora

unread,
Jul 13, 2012, 12:28:34 PM7/13/12
to smart-...@googlegroups.com
I still can't be sure from your description that you're using the new
yasnippet. I need something i can reproduce **without** Aquamacs,
which I don't support and have little idea how it works.

I would need something like

1. Downloaded yasnippet from <url> using <git, wget, browser>
2. Unzipped the <file> onto <location> (or "git cloned onto <location>")
3. Started a very light Emacs (the -Q parameter is used to remove any
customizations you have) and typed into the *scratch* buffer
(add-to-list 'load-path "<location>")
(require 'yasnippet)
(yas/global-mode 1)
4. Placed a new snippet with "# key: <some-key>" from file <file> in
~/.emacs.d/snippets/<some-mode> or <location2>/<some-mode>
5. Opened a <some-mode> buffer
6. Typed the snippet key <some-key>
7. Typed TAB

Anyway

1. Use "M-x yas/version" and tell me what version it outputs
2. Whichever way you were using to define new snippets, use it, but
instead of writing your old snippet, write the one I gave you. Don't
modify the snippet directives, just make sure they iclude the new "#
type: command" directive.
3. Try using "M-x yas/new-snippet" to write the snippet when you're
done just type "C-c C-c", follow instructions in the minibuffer. No
need to use `yas/reload-all` at all.

Hope this helps,
João
>> > smart-snippe...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/smart-snippet?hl=en.
>>
>>
>>
>> --
>> João Távora
>
> --
> 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/-/-VRd4ht1_JAJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to
> smart-snippe...@googlegroups.com.

Dror Atariah

unread,
Jul 13, 2012, 3:40:39 PM7/13/12
to smart-...@googlegroups.com
Good evening,
 
I would need something like
I'll try again 

1. Downloaded yasnippet from <url> using <git, wget, browser>
I used the git option.  
2. Unzipped the <file> onto <location> (or "git cloned onto <location>")
I checked it out into "~/Library/elisp/yasnippet"
3. Started a very light Emacs (the -Q parameter is used to remove any
customizations you have) and typed into the *scratch* buffer
   (add-to-list 'load-path "<location>")
   (require 'yasnippet)
   (yas/global-mode 1)
In *scratch* I ran:
---
 (add-to-list 'load-path "~/Library/elisp/yasnippet") 
   (require 'yasnippet) 
   (yas/global-mode 1)
---
after removing my .emacs file - I hope this is as good as -Q... And evaluated using "M-x eval-buffer" 
4. Placed a new snippet with "# key: <some-key>" from file <file> in
~/.emacs.d/snippets/<some-mode> or <location2>/<some-mode>
I didn't understand this part... Sorry - I used the already defined snippets that I manually copied from the old location to ~/Library/elisp/yasnippet/snippets/
5. Opened a <some-mode> buffer
Open a new buffer, and "M-x latex-mode" it.
6. Typed the snippet key <some-key>
Tested one of the old snippets which worked fine. Then, trying the new one, i.e. "f foot[TAB]" => "f foot"... 
7. Typed TAB

Anyway

1. Use "M-x yas/version" and tell me what version it outputs
This doesn't work for me... In the YASnippet menu I have "About" which returns "version 0.7.0 beta" 
2. Whichever way you were using to define new snippets, use it, but
instead of writing your old snippet, write the one I gave you. Don't
modify the snippet directives, just make sure they iclude the new "#
type: command" directive.
I copied and passed your code, so the "# type: command" is there... 
3. Try using "M-x yas/new-snippet" to write the snippet when you're
done just type "C-c C-c", follow instructions in the minibuffer. No
need to use `yas/reload-all` at all.
I never used it before, so I don't know what to do here....

I hope this clears the situation a bit....

Thanks for you efforts!
Dror

João Távora

unread,
Jul 13, 2012, 5:00:09 PM7/13/12
to smart-...@googlegroups.com
Hi again,

Thank you for following my advice, I now have a much better view
(and you're right it was `yas/about` not `yas/version`)

But I still can't explain it. I need this info:

* What files live in your
~/Library/elisp/yasnippet/snippets/latex-mode directory?

* Do other snippets in this directory work correctly? Do they work
after you modify them?

* What are the first few lines of output of `M-x describe-variable RET
yas/snippet-dirs`?

* What yas-related messages (the ones that start with "[yas]") popup
in the "*Messages*" buffer when you (1) use (yas/global-mdoe 1) (2)
use `yas/reload-all`?

* What is the output of `M-x describe-snippet-tables` in the
`latex-mode` buffer?

* Also: can you send me the exact file where you stored my snippet in?
Did you create it with emacs? It might have some kind of CRLF line
endings or other artifacts that are preventing the snippet from loading.

* Are you doing "M-x yas/reload-all" or evaluating "(yas/reload-all)"?

To use `M-x yas/new-snippet` just try it out. It is used to help you
create and load new snippets. What exactly don't you understand about
it? This feedback is valuable to me.

Thank you,
João
> --
> 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/-/EMTTlimXUQMJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to
> smart-snippe...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/smart-snippet?hl=en.



--
João Távora

Dror Atariah

unread,
Jul 13, 2012, 5:22:47 PM7/13/12
to smart-...@googlegroups.com
Thank you for following my advice, I now have a much better view
(and you're right it was `yas/about` not `yas/version`)
Thank you for your time! 
 
* What files live in your
~/Library/elisp/yasnippet/snippets/latex-mode directory?
My LaTeX snippets:
COPYING                  block.yasnippet          fig.yasnippet            lim.yasnippet            sub.yasnippet
README                   case.yasnippet           footnote.yasnippet       math.yasnippet           subfig.yasnippet
align.yasnippet          cha.yasnippet            formalFUletter.yasnippet matrix.yasnippet         substar.yasnippet
align_star.yasnippet     chastar.yasnippet        frac.yasnippet           minipage.yasnippet       sum.yasnippet
article.yasnippet        coord.yasnippet          frame.yasnippet          par.yasnippet            table.yasnippet
beamer.yasnippet         coprod.yasnippet         graphics.yasnippet       para.yasnippet           tikzalone.yasnippet
begin                    desc.yasnippet           href.yasnippet           prod.yasnippet           url.yasnippet
begin.yasnippet          doc.yasnippet            inlinemath.yasnippet     sec.yasnippet            use.yasnippet
bib.yasnippet            emp.yasinppet            int.yasnippet            secstar.yasnippet        verb.yasnippet
big.yasnippet            enum.yasnippet           it.yasnippet             set.yasnippet
bigop.yasnippet          eq.yasnippet             item.yasnippet           ssub.yasnippet
binom.yasnippet          eqs.yasnippet            letter.yasnippet         ssubstar.yasnippet

* Do other snippets in this directory work correctly? Do they work
  after you modify them?
Yes X2 :) 

* What are the first few lines of output of `M-x describe-variable RET
  yas/snippet-dirs`?
---
yas/snippet-dirs is a variable defined in `yasnippet.el'.
Its value is ("~/Library/elisp/yasnippet/snippets") 
---

* What yas-related messages (the ones that start with "[yas]") popup
  in the "*Messages*" buffer when you (1) use (yas/global-mdoe 1) (2)
  use `yas/reload-all`?
Here's the output of the reload:
---
[yas] Loaded ~/Library/elisp/yasnippet/snippets
[yas] Reloaded everything....
---
and here's the message after (yas/glocal-mode 1) evaluation:
---
eval-buffer: Symbol's function definition is void: yas/global-mdoe
---

* What is the output of `M-x describe-snippet-tables` in the
  `latex-mode` buffer?
I don't have this option... 

* Also: can you send me the exact file where you stored my snippet in?
  Did you create it with emacs? It might have some kind of CRLF line
  endings or other artifacts that are preventing the snippet from loading.
 You asked it - you got it

* Are you doing "M-x yas/reload-all" or evaluating "(yas/reload-all)"?
The M-x option 

To use `M-x yas/new-snippet` just try it out. It is used to help you
create and load new snippets. What exactly don't you understand about
it? This feedback is valuable to me.
I'd like to have it one thing at a time :) 

Good night!
footnote.yasnippet

João Távora

unread,
Jul 13, 2012, 6:19:49 PM7/13/12
to smart-...@googlegroups.com
The snippet file you sent me had DOS file endings. Try again with the
one I am sending you.

If that doesn't help, navigate to the snippet file with emacs and
press "C-c C-c".

Also, I meant `yas/describe-snippet-tables` and `yas/global-mode`
**not** `describe-snippet-tables` and `yas/global-mdoe`. It's late and
I'm quite tired.

Hope it works if not we'll have to resume on monday.
João
> --
> 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/-/CAXHZm3WYqYJ.
>
> To post to this group, send email to smart-...@googlegroups.com.
> To unsubscribe from this group, send email to
> smart-snippe...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/smart-snippet?hl=en.



--
João Távora
footnote.yasnippet

Dror Atariah

unread,
Jul 14, 2012, 2:09:59 PM7/14/12
to smart-...@googlegroups.com
Dear João,

The snippet file you sent me had DOS file endings. Try again with the
one I am sending you.
Solved the problem!!!! :) Can you explain what went wrong? How did you troubleshoot it?

If that doesn't help, navigate to the snippet file with emacs and
press "C-c C-c".
Didn't try this one 

Also, I meant `yas/describe-snippet-tables` and `yas/global-mode`
**not** `describe-snippet-tables` and `yas/global-mdoe`. It's late and
I'm quite tired.
 I couldn't find "yas/describe-snippet-tables", only "yas/describe-tables". But any way, as I wrote it works!!!

Thank you so much and have a nice Sunday
Dror

João Távora

unread,
Jul 14, 2012, 2:27:02 PM7/14/12
to smart-...@googlegroups.com
Great!

I also thought DOS file endings were supported, I've had some trouble
with it in the past, will investigate again, though...

João
> --
> 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/-/w3vmlu7b-EMJ.
Reply all
Reply to author
Forward
0 new messages