Installing YASnippet
Asked Answered
C

2

5

I have installed YASnippet and configured it with this:

(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet-0.6.1c")
(require 'yasnippet) ;; not yasnippet-bundle

(yas--initialize)
(yas/load-directory "~/.emacs.d/packages/yasnippet-0.6.1c/snippets")

However, when I launch Emacs it gives me an error:

Warning (initialization): An error occurred while loading `/home/alexander/.emacs':

Symbol's function definition is void: yas--initialize

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.
(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet-0.6.1c")
(require 'yasnippet) ;; not yasnippet-bundle

(yas--initialize)
(yas/load-directory "~/.emacs.d/packages/yasnippet-0.6.1c/snippets")

What am I doing wrong? I have tried to find the answer but with no success. (I have also tried with another version of yasnippet yasnippet-0.6.1b but it was the same.)

Christcrossrow answered 31/10, 2012 at 19:13 Comment(0)
S
5

Just at a glance, that

(yas--initialise)

should be

(yas/initialize)

I'm running 0.6.1 and there's no such function as yas--initialize in the package.

My init code looks like

(require 'yasnippet)
(yas/initialize)
(yas/load-directory
 (dot-emacs "elpa/yasnippet-0.6.1/snippets"))

I think you just got some garbled init code somewhere.

EDIT

I should have omitted the load-directory call in my sample since it's beside the point. But for what it's worth, dot-emacs is just a config-agnostic function I use to reference files relative to my init:

(defun dot-emacs (relative-path)
  "Return the full path of a file in the user's emacs directory."
  (expand-file-name (concat user-emacs-directory relative-path)))
Simmonds answered 31/10, 2012 at 19:53 Comment(5)
now it says "Symbol's function definition is void: dot-emacs"Christcrossrow
@mr.axelander, I neglected to mention that dot-emacs is a custom function of mine. The yas/load-directory code that you had should be fine. Sorry about the confusion.Simmonds
Very nice answer (and thank you for the dot-emacs, as a noob it became a new addition of my .emacs ;-) )!Bron
@Rick77, glad to hear that :) Although things are even simpler now. If you get yasnippet through the package manager (M-x list-packages) and keep your snippets under ~/.emacs.d/snippets (which it includes by default), no special configuration is necessary. The only thing I do in init is (yas-global-mode).Simmonds
@harpo: thank you for the tip! I actually use the package manager already (found about it weeks ago, right because I had problem with yasnippet and autocomplete. I actually still do ;D), but for some reason unknown to myself I wanted to install my snippets in .emacs.d/my-snippets and I came here (for the records, the only thing that worked was to use (yas/compile-directory (dot-emacs "my-snippets")) before including the directory...). Thank you for the help anyway (the more I get to know emacs, the more it rocks ;-) )!Bron
L
4

FYI in case you ever upgrade: the information you got is correct for version 0.8, but for 0.7 and below yas/initialize is correct. See this commit

Lorilee answered 31/10, 2012 at 20:28 Comment(1)
Yes, this had me confised for a while. I obtained the init.el code from the YAS site which said that I should use (yas/initialize) but that didn't work and produced the error Symbol's function definition is void: yas/initialize. I decided to give (yas--initialize) a try in init.el and that works for me.Lamented

© 2022 - 2024 — McMap. All rights reserved.