New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG? Transformation upon yas-moving-away-p doesn't update the field #381
Comments
Hi, This is possibly intentional. Unfortunately, I don't know anymore and the documentation is, as you say, outdated. In general, mirror transforms are designed to return strings that replace the current mirror or field content. This is not to discourage you. If you can:
Then I will probably merge it. I'm changing the title of this issue and marking it a feature request. |
Thanks for a prompt reply. If I'm not mistaken, it was actually a primary field, not a mirror one. I'm now away from the code but I'll try to see to it later today and come up with a simple example. |
I assumed it was a mirror field since the syntax for primary field transformations (if I myself am not mistaken) is
notice the double |
Oh, ok, I reproduced the example in original post by heart and missed the initial field value that has been there. Here's an example to reproduce the behavior. This snippet works as expected upcasing entered text and printing the message after each keystroke: # -*- mode: snippet -*-
# name: foobar
# key: foobar
# --
${1:foobar$(progn (message "exiting foobar") (upcase text))} This does print a message once, but the field contents remain the same: # -*- mode: snippet -*-
# name: foobar
# key: foobar
# --
${1:foobar$(when yas-moving-away-p (progn (message "exiting foobar") (upcase text)))} |
PS. There's also
in
Sorry, I'm too lazy right now to make a full-fledged pull request. |
I can confirm that this doesn't work during primary or mirrored transformations. I'm trying to make a quote bbcode that only leaves the
But the
It seems that, while the Edit: I tried using this workaround:
but, even though start and end are correct, delete-region doesn't seem to have any effect! Very puzzling! |
@lalopmak you most definitely shouldn't be using I'll have a deeper look at your example when I find the time, but from the looks of it it sounds much simpler. You seem to want a mirror of the author field that either returns a "=" or an empty string. You don't need a primary field transformation at all for that. just something like |
Something like that was indeed my secondary solution, the problem being that the = doesn't appear unless they type something in. To improve upon that, I tried (without much success) to only make the equal disappear only when moving away from that field. Though a missing = may not be the biggest deal in this case, a good usecase for this is when you have many initially-visible optional fields for the user to "tab through" quickly. In this case, he could just tab-tab-tab and type when appropriate, any fields in which he did not type automatically disappearing. Another, more general, usecase is if the user's final value just needs to be transformed into something else when he leaves. Is it possible to add a "leaving hook" to a field, code to modify the text one last time? |
@lalopmak isn't your objective that the field shows |
Aha, I've got it from that hint!
Basically copied the |
I still don't understand why this is better than the suggestion I gave you But it's OK.:-D, its a free world! You are aware that none of this is guaranteed to work in the future though, |
Our two examples have almost the same behavior. The only difference is that, with mine, the user still sees the I would be very sad to learn that this has broken. A possible feature that could do the same thing (without exposing any additional internals) would be "leaving hooks". They could work in almost the same way as the mirror code, except that leaving code is only triggered when the user actually leaves the field. For example, let's say a mirror syntax was
That is, the mirror text is a constant
Similarly to the quote's So far, this could've been done with C-d (as long as the user did not type anything beforehand). But C-d only has the capacity to delete fields upon leaving, not necessarily to transform them. Here's an example of a powerful snippet with "leaving transformation":
So I guess this has turned into a proposal/feature request. I've tried looking at the code to see how I might put it in, but I admit I haven't been able to understand it well enough. |
Lally Oppenheimer notifications@github.com writes:
OK, I understand now. Maybe you don't know that the historical root of I don't know what language you're using, but I suspect that [quote=DummyAuthor] And And this is the use case that yasnippet was designed to support, just You are right it is a question of opinion. However, by design, I have read your proposal and it will be registered here, but it has |
Just a last comment. In your last "License" example, have you noticed that you're proposing a new syntax for expanding abbreviations based on a few characters? Sounds familiar? Yes, you're reinventing yasnippet all over again! But yasnippet already provides that with no additional syntax. You can enable |
FTR here's what seems an another mention of this issue on stack overflow. The intention was to wrap
And the observed behaviour was the same as in my request: the code was executed, but field value was not replaced. |
@immerrr this seems to be a bug, albeit one I'm not keen on tacking in the near future, at least not with the current yasnippet engine, which is being reworked on the |
Rewrite is good news, count me in for waiting on its results :) PS. looked into the code, especially tests, I like the |
@immerrr would you be interested in writing a translator of textmate/yasnippet syntax into the new snippet.el syntax? I need a function that takes the string
And outputs a lisp list
This is a relatively simple example, but if you're interested I can provide more examples/tips. |
I'll try seeing to it over weekend, but I'm not sure I get where did the open-paren go in the example. (UPD: and all the non-field characters, for that matter) |
Sorry, I made a mess of it. Should work now. |
I'm trying to follow the doc here, but I can't see how would you like constructs like |
immerrr notifications@github.com writes:
Hi. Please assume that this behaviour (unimplemented for now) will be As to the contents of FIELD-TRANSFORM itself, it must be a lisp form João |
Ok, how about |
immerrr notifications@github.com writes:
Reasonable enough (but should refer to the fields). It's not the most important thing right now, don't worry about it. I I just want to get some "yas--parse-snippet (TEXTMATE-SNIPPET)" |
Sort of... Where do you want me to put it? |
immerrr notifications@github.com writes:
Use github to fork yasnippet, then make it a commit to the immerrr/yasnippet/snippet-engine I'm pretty sure github allows this, otherwise send it via mail to J |
Oh, thanks. I'm aware of git branching model, I was rather wondering which file would you like to see it in :) |
I've been wrestling with this for a while before finding this issue report, and I'm somewhat confused by the outcome. Is it currently at possible to have fields that automatically delete themselves when skipped without being edited? I also want placeholders and decorations on them. Specifically, I want a Ruby snippet which starts out as this(where >< denotes fields with placeholders):
If I now press TABTAB, I should end up with this:
This is pretty much the question asked in the referenced stackoverflow post, and I'm aware of that. The reason I'm restating it is because there's no clear answer in here. I'd like an unambiguous explanation of whether it's possible to do in the current yasnippet engine, and if so, how to achieve it. There's related functionality useful in writing code where it'd be nice to be able to generate a repeating placeholder list as long as the user edits them. Think of |
Maciej Katafiasz notifications@github.com writes:
I advise against using primary field transformations for this sort of See the (admittedly outdated) documentation for the use cases they are However, its possible to achieve something very close. The solution Use this snippet
And instead of pressing TAB twice, press TAB and C-d to delete the second You can also write and use TAB TAB. If you start typing arguments they
The reason that there is no direct answer sometimes is that the Your formulation was very good, though. Fell free to add this answer to Also, for all practical matters regarding yasnippet directly, the
This is not supported. You might have some success with Maybe the new snippet engine will support this kind of thing, but What yasnippet syntax would you propose for this? |
I found a fix for this posted to the newsgroup years ago here: https://groups.google.com/forum/#!topic/smart-snippet/HEJ5JLIXhp8 Had to update it to use the newer namespaces but it mostly works. I'll toss a patch up on github when I've made sure it updates other mirrors correctly and have access to my github box again. |
@Skrylar, just a heads up, you can of course propose such a thing in a pull request, but I doubt I'll merge it without some thorough reviewing of its implications. I've only very briefly skimmed the patch you make mention to, and I would rather prefer to revive the effort that is connecting yasnippet to the new |
Looks like a simple bug to me, will be fixed in #689. The rest of this thread started to branch out a lot and got kind of confusing, if anyone wants to follow up on something here, I suggest opening a new issue. |
I'm getting weird results trying to do something like
Basically, nothing is replaced, but I see
ensure-is-quoted
is being executed.It appears that in
yas-next-field
the transform is evaluated withyas--eval-lisp
, but the field is never updated. Is this intentional? The doc -- slightly outdated -- mentionsyas/moving-away-p
, but doesn't say anything specific about its use.The text was updated successfully, but these errors were encountered: