4

我是 elisp 的新手,但我正在尝试为我的 .emacs 增添一些趣味。

我正在尝试定义一些路径,但是在创建路径列表(以及更具体地为 YaSnippet 设置列表)时遇到问题。

当我评估列表时,我得到一个符号名称列表(而不是 yassnippet 想要的符号值)。

我得到了代码,但感觉有更好的方法来做到这一点?

这是工作代码:

;; 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)
4

2 回答 2

6

如果您评估字符串列表,则结果取决于列表项的值。最好的测试方法是启动 ielm repl (Mx ielm),然后输入:

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

带引号的字符串列表计算为列表值。如果将列表的值存储在一个变量中,然后对变量求值,ELisp 会抱怨函数abc是未知的。

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

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

对于 yasnippet 目录配置,您应该只设置yas-snippet-dir,例如

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

编辑:yas/root-directory
的使用已被弃用。来自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.
于 2012-08-17T11:26:49.013 回答
4

我想你想要

(setq yas/root-directory (list my-snippets-path default-snippets-path))
于 2012-08-17T15:59:28.477 回答