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.

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
aL3xa
  • 35,415
  • 18
  • 79
  • 112
  • 2
    In what mode are you trying the binding? What version of Emacs and YASnippet are you using? – N.N. Feb 15 '12 at 19:59
  • 2
    What does "C-h k C-c C-c C-m" print? – Thomas Feb 16 '12 at 00: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 '12 at 00: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 '12 at 10:33

1 Answers1

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

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
joao
  • 3,517
  • 1
  • 31
  • 43