4

After exiting yasnippet snippets that contain one or more tab stops, I often find myself wanting to go back and modify content that I entered at the tab stops. Of course, I can do this using standard movement and editing commands, but it would be much easier if I could simply reactivate, say, the last snippet I inserted and TAB through the fields again.

Another frequent use case is exiting snippets prematurely. I sometimes do this on purpose, but more often than not this happens because I accidentally hit C-g (or some other command that cancels the snippet).

Q: Is there a way to resume or reactivate a snippet after exiting it?

I ran M-x apropos for various combinations of yas/yasnippet and resume/reactivate, but that didn't turn up anything useful.


UPDATE

As @Stefan helpfully points out in the comments, it is possible to call undo to reactivate a snippet. However, this is only useful as long as the current buffer stays unmodified: If I exit a snippet, make some unrelated modifications in other parts of the buffer, and then hit C-/ (undo), Emacs first reverts the most recent changes instead of resuming the snippet, which (in most cases) is not what I want.

  • 1
    Have you tried to just undo? – Stefan Nov 9 '14 at 23:12
  • @Stefan I tried it just now, thanks! It addresses some of my use cases, but unfortunately not all of them (see recent updates to my question). – itsjeyd Nov 10 '14 at 8:24
  • We can wait and see. But I think undo is the best you're gonna get. – Malabarba Nov 10 '14 at 9:51
1

As mentioned in my comment, you can undo to reactive a snippet. And if you want to reactivate a yasnippet without first undoing your subsequent changes, you can use undo-in-region, i.e. select a region of text that contains the snippet and do undo.

  • Thanks for upgrading your comment to an answer. Unfortunately, using undo-in-region to reactivate a snippet doesn't work for me. If I (1) expand a snippet, (2) cancel it, (3) insert some text in another part of the buffer, (4) select text containing the snippet, (5) hit C-/, I get "No further undo information for region". Assuming you tested this, could you add a working example to your answer? – itsjeyd Nov 10 '14 at 14:49
  • Hmm... no, I didn't actually test it, I looked at the code instead and it has what is needed for it to work, AFAICT. You should probably report it as a bug. – Stefan Nov 10 '14 at 16:10
0

You can use shift tab to go backward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.