I wanted to test yasnippet for editing Emacs Lisp files. After installing it from the package manager, the problem is that it works fine from the *scratch* buffer but not when editing a Lisp file using emacs-lisp-mode.

To debug, I reduced my Emacs init file to one line:

(setq debug-on-error t)

Then I started Emacs from command line with:

$ emacs test.el

and run M-x yas-minor-mode and then M-x yas-reload-all, then I typed defun and pressed the TAB key, but nothing happend.

However, if I first switch to the *scratch* buffer and run the same commands it works fine and inserts the defun template when I press TAB..

1 Answer 1


The problem is that yasnippet doesn't define a "defun" snippet for emacs-lisp-mode. Instead, use the "def" snippet.

The reason you could use the "defun" snippet in the *scratch* buffer is because lisp-interaction-mode does have a "defun" snippet.
Look in the menu bar, under "YASnippet", you can find which snippets you can use.

To summarize: type def and press TAB.


Your Answer

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

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