5

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.

itsjeyd
  • 14,666
  • 3
  • 59
  • 87

2 Answers2

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.

Stefan
  • 26,404
  • 3
  • 48
  • 85
  • 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.

Vaibhav
  • 583
  • 3
  • 16