4

I'm trying to load the yasnippets for the LaTeX mode every time I open an org file.

Is it possible? How can this be achieved?

1
  • Only one major mode is active at a time. Check to see if either of those major modes has a corresponding minor mode that you can use at the same time as the other major mode.
    – Drew
    Jan 29, 2018 at 14:57

2 Answers 2

9

You can load an additional modes via yas-activate-extra-mode in the hook of the major mode (it also works with yas-global-mode turned on).

Just copy-paste following elisp snippet into your init file:

(defun my-org-latex-yas ()
  "Activate org and LaTeX yas expansion in org-mode buffers."
  (yas-minor-mode)
  (yas-activate-extra-mode 'latex-mode))

(add-hook 'org-mode-hook #'my-org-latex-yas)

Tested with:

  • GNU Emacs 25.3.1 (x86_64-unknown-cygwin, GTK+ Version 3.22.20) of 2017-09-11
  • yasnippet-20180124.1445
  • yasnippet-snippets-20180122.521
1

You can see what the yasnippet repo has to say about this.

Basically, if you put a .yas-parents file (yes, a hidden file) inside your snippets/org-mode/ directory and as the content of said file you put latex-mode the latex snippets will also be available in org-mode. This approach does not require any lisp and it is very simple to share many snippets across many different modes (by simply listing more modes in the .yas-parents file).

Your Answer

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

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