2

Is there a way to easily insert a snippet when a certain keybinding is activated? AFAICT, official documentation suggests setting: #binding: directive, smth like this:

#name : <p>...</p>
#binding: C-c C-c C-m
# --
<p>`(when yas/prefix "\n")`$0`(when yas/prefix "\n")`</p>

It's not working for me, however. Any ideas on what may cause the problem?

EDIT
I'm using GNU Emacs 24.0.93.1 with Yasnippet grabbed from GitHub repo.

4
  • 2
    In what mode are you trying the binding? What version of Emacs and YASnippet are you using?
    – N.N.
    Feb 15, 2012 at 19:59
  • 2
    What does "C-h k C-c C-c C-m" print?
    – Thomas
    Feb 16, 2012 at 0:20
  • 1
    BTW C-c C-c is generally taken by major modes, IMO one better not use it as a prefix
    – kindahero
    Feb 16, 2012 at 0:31
  • @N.N. I was trying to use it in html-mode (actually nxhtml-mode). @Thomas, describe-key is interrupted after C-c C-c, but nothing happens if I change the binding. @kindahero, yes I'm aware of that, this stuff is from official Yasnippet page.
    – aL3xa
    Feb 16, 2012 at 10:33

1 Answer 1

3

Ensure you have a recent version of Yasnippet. The snippet you provide works (almost) perfectly with a recent version of Yasnippet.

The reason I said "almost" is that the yas/prefix technique was not working at all due to a bug which I fixed just now (referenced this StackOverflow link in the commit)

So using C-c C-c m will expand <p></p> and using C-u C-c C-c m will expand <p></p>

If you still have problems you can use the GitHub issue tracker for these issues

2
  • Nope, it's still not working for me. Will continue this rant on GitHub.
    – aL3xa
    Feb 16, 2012 at 11:36
  • 1
    Damn, it was as easy as putting the snippet in nxhtml-mode folder. Facepalm.
    – aL3xa
    May 5, 2012 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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