Issue 31 in yasnippet: Executing lisp code after TAB

914 views
Skip to first unread message

codesite...@google.com

unread,
Sep 5, 2009, 8:07:03 AM9/5/09
to smart-...@googlegroups.com
Updates:
Status: WontFix
Labels: -Type-Defect Type-Enhancement

Comment #5 on issue 31 by joaotavora: Executing lisp code after TAB
http://code.google.com/p/yasnippet/issues/detail?id=31

Won't take action on this enhancement issue until further feedback.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

Peter Straka

unread,
Sep 11, 2009, 5:39:51 AM9/11/09
to smart-snippet and YASnippet
Hello,

In issue 100 nearly the same task is discussed. Mine is different to
this because I want to call the function after i filled out a field
and reftex-label uses this filed as input. #100 calls the function
immediately after expansion.

I tried to combine your answer and the answer to #100, but it does not
work yet:

I try:

\section{${1:Titel der Tour?}}%
\index{${1:$(if (eq yas/moving-away-p t) (reftex-label nil 'dont-
insert))}}%

$1 is mirrored but reftex is not called. it jumpes directly to next
field.


Secondly I tried:

\section{${1:Titel der Tour?}}%
\index{$1}%
\index{${2:$$(if (eq yas/moving-away-p t) (reftex-label nil 'dont-
insert))}}%
%
$2 is only a dummy, I press TAB. reftex-label is called indeed,
suggests the label. I press enter to accept, but noting is inserted
and yas jumps to the next input field


Maybe you have another idea?

Thanks, Peter



On 5 Sep., 14:07, codesite-nore...@google.com wrote:
> Updates:
>         Status: WontFix
>         Labels: -Type-Defect Type-Enhancement
>
> Comment #5 on issue31by joaotavora: Executing lisp code after TABhttp://code.google.com/p/yasnippet/issues/detail?id=31

João Távora

unread,
Sep 12, 2009, 7:54:11 AM9/12/09
to smart-...@googlegroups.com
OK, some feedback finally...

Mirror transformations are basically functions of the text (text or
yas/text variable) that is present on the field they mirror. YASnippet
wasn't designed to handle stuff such as side effects, which is one of
the things that might make your intention work.

Consider the following *workaround*, check if it works

`(progn (setq my-reftex-cache nil) "")`
\section{${1:"Titel der Tour"$(if yas/moving-away-p
(progn (setq my-reftex-cache (reftex-label nil
'dont-insert))
(yas/update-mirrors snippet))
(setq my-reftex-cache nil))}}%
\index{${1:$(or my-reftex-cache
"waiting...")}}%

The my-reftex-cache variable implements the side-effect communication
between the field and the mirror. Then you need the first progn line
to initialize the variable. Then you need a **really** dirty hack
where you force a mirror update. This is not guaranteed to work in the
future (or in the present, for that matter), since it uses internal
yasnippet workings which might change in the future.

But I ask you if you'd rather not use this:

\section{${1:"Titel der Tour"}}%
\index{${2:"waiting..."$(unless yas/modified-p (reftex-label nil 'dont-
insert))}}%

The only *inconvenient * here is that you get a chance to change the
value inserted by reftex-label. Other than that, it's much cleaner,
and is the "recommended" way.

Naturally, I didn't think of your scenario when I designed this
feature. Its possible to make the first alternative cleaner in the
future, I'll leave the issue open, maybe retitle it.

Bye,
J

codesite...@google.com

unread,
Sep 13, 2009, 11:01:30 AM9/13/09
to smart-...@googlegroups.com
Updates:
Status: KnownIssue

Comment #6 on issue 31 by joaotavora: Executing lisp code after TAB
http://code.google.com/p/yasnippet/issues/detail?id=31

See thread
http://groups.google.com/group/smart-snippet/browse_thread/thread/282a90a118e1b662.

Additionally, the following snippet can help the drawback of the second
alternative:

\section{${1:"Titel der Tour"}}%

\index{${2:"waiting..."$(unless yas/modified-p (prog1 (reftex-label
nil 'dont-insert)

(yas/schedule-field-skip)))}}%
$0

and some supporting elisp code...

(defun yas/schedule-field-skip ()
(add-hook 'post-command-hook 'yas/field-skip-once 'append 'local))

(defun yas/field-skip-once ()
(condition-case err
(yas/next-field)
(error nil))
(remove-hook 'post-command-hook 'yas/field-skip-once 'local))

Peter Straka

unread,
Sep 14, 2009, 6:01:31 AM9/14/09
to smart-snippet and YASnippet
Hello,

thank you very much! I can now completely substitute msf abbrev with
yasnippet.

The version 2 works, and with the additional code it is perfect, the
same behaviour as in msf.

For the record: The snippet has to be slightly modified, because
reftex-label with parameter dont-insert does not write the \label{}.
So the complete snippet is:

\section{${1:Title}}%
\index{$1}%
\label{${2:"waiting..."$(unless yas/modified-p (prog1 (reftex-label
nil 'dont-insert)
(yas/schedule-field-skip)))}}%





On 13 Sep., 17:01, codesite-nore...@google.com wrote:
> Updates:
>         Status: KnownIssue
>
> Comment #6 on issue 31 by joaotavora: Executing lisp code after TABhttp://code.google.com/p/yasnippet/issues/detail?id=31
>
> See thread  http://groups.google.com/group/smart-snippet/browse_thread/thread/282....
Reply all
Reply to author
Forward
0 new messages