4

I am new to elisp but I am trying to spice up my .emacs a little.

I am trying to define some paths, but having problems with creating a list of paths (and setting the list for YaSnippet more specifically).

When I evaluate the list I get a list of the symbol name (and not the symbol values as yassnippet want).

I got the code working but have feeling that there is a better way to do this?

Here is the working code:

;; some paths
(setq my-snippets-path "~/.emacs.d/snippets")
(setq default-snippets-path "~/.emacs.d/site-lisp/yasnippet/snippets")

;; set the yas/root-directory to a list of the paths
(setq yas/root-directory `(,my-snippets-path ,default-snippets-path))

;; load the directories
(mapc 'yas/load-directory yas/root-directory)
BobuSumisu
  • 118
  • 1
  • 5
  • 1
    What you are looking for is the construction of a new list using two variables. That indeed can be achieved using the list function, as described by @jpkotta, although that's not the evaluation of a list, but the constructions of a list. The more efficient - and recommended way - to configure the snippet directories is to assign a list of strings with directories to the variable yas-snippet-dirs, though. The [Elisp Cookbook contains some useful information on list structures](http://emacswiki.org/emacs/ElispCookbook#toc38). – raju-bitter Aug 17 '12 at 16:57

2 Answers2

6

If you evaluate a list of strings, the result depends on the value of the list items. The best way to test that is to launch the ielm repl (M-x ielm), and enter:

ELISP> '("abc" "def" "ghi")
("abc" "def" "ghi")

The quoted list of string evaluates to the list value. If you store the value of the list in a variable, and then evaluate the variable, ELisp will complain that the function abc is unknown.

ELISP> (setq my-list '("abc" "def" "ghi"))
("abc" "def" "ghi")

ELISP> (eval my-list)
*** Eval error ***  Invalid function: "abc"

For the yasnippet directory configuration, you should just set yas-snippet-dir instead, e.g.

(add-to-list 'load-path
              "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)

(setq yas-snippet-dirs
      '("~/.emacs.d/snippets"            ;; personal snippets
        "/path/to/yasnippet/snippets"    ;; the default collection
        "/path/to/other/snippets"        ;; add any other folder with a snippet collection
        ))

(yas-global-mode 1)

Edit:
The use of yas/root-directory has been deprecated. From the documentation of yasnippet.el

`yas-snippet-dirs'

The directory where user-created snippets are to be
stored. Can also be a list of directories. In that case,
when used for bulk (re)loading of snippets (at startup or
via `yas-reload-all'), directories appearing earlier in
the list shadow other dir's snippets. Also, the first
directory is taken as the default for storing the user's
new snippets.

The deprecated `yas/root-directory' aliases this variable
for backward-compatibility.
raju-bitter
  • 8,906
  • 4
  • 42
  • 53
4

I think you want

(setq yas/root-directory (list my-snippets-path default-snippets-path))
jpkotta
  • 9,237
  • 3
  • 29
  • 34