0

The instructions for installing yasnippet globally are set forth in the Github README.mdown -- https://github.com/capitaomorte/yasnippet -- and also in the comments at the top of yasnippet.el library.

I prefer not to to use yasnippet globally, and would rather enable it on a buffer-local basis or only for specific major modes.

How can I install/setup yasnippet for buffer-local usage?

1

Download the latest stable public release of Emacs. In my case, I downloaded Emacs for OSX (version 24.5.1) from: http://emacsformacosx.com/

Start Emacs.

M-x package-install RET yasnippet RET

Add the following lines to the .emacs file, save, restart Emacs:

(package-initialize)
;; or, instead of using `package-initialize`, use the following:
;; (add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0/")

(require 'yasnippet)

;; This is the default location as of September 18, 2015.  Add more as needed.
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))

(yas-reload-all)

In any buffer containing the following major-modes that are supported out-of-the-box, type M-x yas-minor-mode RET

c-mode
c++-mode
cc-mode
;; There are no sample snippets in the folder out-of-the-box
;; cperl-mode
csharp-mode
css-mode
emacs-lisp-mode
erlang-mode
f90-mode
html-mode
latex-mode
markdown-mode
nxml-mode
objc-mode
perl-mode
python-mode
rst-mode
ruby-mode
scala-mode
snippet-mode
sql-mode
text-mode

If so desired, verify that everything went well by typing: M-x yas-describe-tables RET

To enable yas-minor-mode automatically for only certain major-modes, use hooks like the following example in the .emacs file:

(add-hook 'text-mode-hook 'yas-minor-mode)

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.