12

I have the following snippet:

# -*- mode: snippet -*-
# contributor: Song Qiang <tsiangsung@gmail.com>
# key: m
# group: Math
# name: Inline math \( ... \)
# --
\\($1\\)$0

and I want it to be available for both latex-mode and org-mode. How can this be achieved? I could symlink, but I'm trying to find a smarter way.

17

The Yasnippet documentation explains that you will need to include a .yas-parents file with the parent modes:

It's very useful to have certain modes share snippets between themselves. To do this, choose a mode subdirectory and place a .yas-parents containing a whitespace-separated list of other mode names. When you reload those modes become parents of the original mode.

.
|-- c-mode
|   |-- .yas-parents    # contains "cc-mode text-mode"
|   `-- printf
|-- cc-mode
|   |-- for
|   `-- while
|-- java-mode
|   |-- .yas-parents    # contains "cc-mode text-mode"
|   `-- println
`-- text-mode
    |-- email
    `-- time

Hence, you could, for example, put your snippet in a text-mode directory, and then, in the latex-mode and org-mode directories, include a .yas-parents file that include the text text-mode.

  • However, if I have well understood, you can only share entire modes, but not individual snippets across several modes? – Picaud Vincent Jan 16 '18 at 12:02

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.