1

I created such a snippet

$ cat snippets/diary_template 
# -*- mode: snippet -*-
# name: diary template
# key: dt
# condition: t    
# --

**** Personal_Notes
**** Personal_Tasks
**** Project_Notes
**** Project_Tasks(base)

set yas-snippet-dirs as

;;yasnippet
(require 'yasnippet)
(setq yas-snippet-dirs
      '("~/.doom.d/snippets"                 ;; personal snippets
        ))

(yas-global-mode 1) ;; 

Reload the config file and activate the yas-minor mode

In the sdiary.org input dt and strike dt. nothing happened.

What's the problem with my operations?

  • 1
    Hmm, this may require some more debugging. Is the snippet listed in the tables if you run: yas-describe-tables? – Xaldew Aug 29 '19 at 7:51
  • No, it is not listed. @Xaldew – Calculus Aug 29 '19 at 7:56
  • 1
    Okay, then we know that yas hasn't indexed the snippet for some reason. Can you try to run yas-reload-all followed by yas-describe-tables? It may also be worth trying to use a canonicalized path in yas-snippet-dirs (i.e., remove the tilde). – Xaldew Aug 29 '19 at 8:37
  • ty, it working, amazing. @Xaldew – Calculus Aug 30 '19 at 1:54
2

You need to put the snippet into a folder with the name of the mode to use it in as follows:

snippets/org-mode/diary_template

Check out the documentation:

Organizing snippets > Basic structure:

.
|-- c-mode
|   `-- printf
|-- java-mode
|   `-- println
`-- text-mode
    |-- email
    `-- time

Expanding snippets > ... > Eligible snippets :

YASnippet does quite a bit of filtering to find out which snippets are eligible for expanding at the current cursor position.

In particular, the following things matter:

  • Currently loaded snippets tables

    These are loaded from a directory hierarchy in your file system. See Organizing Snippets. They are named after major modes like html-mode, ruby-mode, etc…

  • Major mode of the current buffer

    If the currrent major mode matches one of the loaded snippet tables, then all that table's snippets are considered for expansion. Use M-x describe-variable RET major-mode RET to find out which major mode you are in currently.

...

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.