Emacs lisp:评估字符串列表

Bob*_*isu 1 lisp string emacs elisp yasnippet

我是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)
Run Code Online (Sandbox Code Playgroud)

raj*_*ter 5

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

ELISP> '("abc" "def" "ghi")
("abc" "def" "ghi")
Run Code Online (Sandbox Code Playgroud)

引用的字符串列表评估为列表值.如果将列表的值存储在变量中,然后计算变量,ELisp将抱怨函数abc未知.

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

ELISP> (eval my-list)
*** Eval error ***  Invalid function: "abc"
Run Code Online (Sandbox Code Playgroud)

对于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)
Run Code Online (Sandbox Code Playgroud)

编辑:不推荐
使用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.
Run Code Online (Sandbox Code Playgroud)