custom snippet newbie

Skip to first unread message

Steven Arntson

Apr 29, 2014, 6:46:59 PM4/29/14
I'm just getting started with YAsnippet, and everything seems to be
working well, but I haven't had good luck with making new snippets, and
am hoping someone could critique my approach.

I invoke M-x yas-new-snippet, and name it "piano" (it will load an
org-babel-lilypond template for a piano score). I set the group to
org-mode, and save the file as "piano" or "piano.yasnippet" in
~/.emacs.d/plugins/yasnippet/ (which is defined in my init.el). Under
the yasnippet menu I select load snippets, and click on the directory,
but the "piano" snippet is grayed out. So I try "reload everything," and
am told everything loaded.

However, I can't seem to get "piano" to function. All the
org-mode snippets that came with YAsnippet, such as "blog" &c, work
perfectly. What am I doing wrong?

Thank you!
steven arntson

João Távora

Apr 29, 2014, 8:39:09 PM4/29/14
> However, I can't seem to get "piano" to function. All the
> org-mode snippets that came with YAsnippet, such as "blog" &c, work
> perfectly. What am I doing wrong?

You should not be saving the file in that directory, you should be
saving to "~/.emacs.d/snippets/org-mode" or to some subdirectory of a
directories in your `yas-snippet-dirs' variable. Saving to
"~/.emacs.d/plugins/yasnippet/snippets" would probably also work, but
then you'd be mixing in your custom snippets with the ones bundled
with yasnippet.

Also what do you mean by "setting it in init.el"?

However, when you invoke M-x yas-new-snippet, what does C-c C-c do for
you? It's supposed to suggest a good place to save your custom
snippet, so you shouldn't have to worry about these details.

Have you read the documentation? If you did, where did you think it
was misleading, or incomplete?


Steven Arntson

Apr 29, 2014, 9:58:36 PM4/29/14
Hi João,

Thanks so much for looking into this. I wonder if I'm stumped by
something incredibly basic here that an experienced user wouldn't ever
think would stump anybody.

I used elpa/melpa to get the YAsnippet package, so all of the bundled
snippets are in ~/.emacs.d/elpa/yasnippet-20140427.1224/snippets,
whereas my "piano" snippet is all alone in ~/emacs.d/plugins/yasnippet.

Below is a recap of what just happened when I created a new snippet
following some of what you just laid out.

<<M-x yas-new-snippet>>

# -*- mode: snippet; require-final-newline: nil -*-
# name: new
# key: new
# binding: direct-keybinding
# expand-env: ((some-var some-value))
# type: command
# --

a new test snippet

<<I hit "C-c C-c">>

[yas] Looks like a library or new snippet. Save to new file? (y or n)

<<I hit "y">>

Guessed directory (~/.emacs.d/plugins/yasnippet/snippet-mode) for table
"snippet-mode" does not exist! Create? (y or n)

<<I hit "y">>

Saving file /home/steven/.emacs.d/plugins/yasnippet/snippet-mode/new...
Wrote /home/steven/.emacs.d/plugins/yasnippet/snippet-mode/new

<<I request to reload everything>>

Some buffers editing live snippets, close them and proceed with reload?

<<I hit "y">>

[yas] Loading compiled snippets ...

<<it loads all the expected stuff, including the various directories
I've been creating:>>

[yas] Loading compiled snippets from /home/steven/.emacs.d/plugins/yasnippet/snippet-mode
[yas] Loading compiled snippets from /home/steven/.emacs.d/plugins/yasnippet/snippets
[yas] Loaded ~/.emacs.d/plugins/yasnippet
[yas] Reloaded everything....

So that's that. Now I wonder if my trouble might be in how I try to call
the snippet?

In a buffer running org-mode, if I type blog[TAB] the snippet expands
immediately. However, if I try piano[TAB] or new[TAB] nothing happens.

So ... that's where I'm at! Maybe this is too long ... sorry!

Thanks again.
Reply all
Reply to author
0 new messages