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.)

N.N.
  • 8,336
  • 12
  • 54
  • 94
AlexanderNajafi
  • 1,631
  • 2
  • 25
  • 39

2 Answers2

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)))
harpo
  • 41,820
  • 13
  • 96
  • 131
  • now it says "Symbol's function definition is void: dot-emacs" – AlexanderNajafi Oct 31 '12 at 20:23
  • @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. – harpo Oct 31 '12 at 22:10
  • Very nice answer (and thank you for the dot-emacs, as a noob it became a new addition of my .emacs ;-) )! – Rick77 Dec 11 '14 at 13:39
  • @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)`. – harpo Dec 11 '14 at 16:29
  • @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 ;-) )! – Rick77 Dec 11 '14 at 21:07
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

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
bcasiello
  • 41
  • 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. – Ubiquitous Mar 03 '13 at 11:38