【问题标题】:Emacs lisp: evaluating list of stringsEmacs lisp:评估字符串列表
【发布时间】:2012-08-17 10:54:59
【问题描述】:

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

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

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

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

这是工作代码:

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

【问题讨论】:

  • 您正在寻找的是使用两个变量构建一个新列表。正如@jpkotta 所述,这确实可以使用 list 函数来实现,尽管这不是对列表的评估,而是对列表的构造。不过,配置 sn-p 目录的更有效且推荐的方法是将带有目录的字符串列表分配给变量 yas-sn-p-dirs。 Elisp Cookbook contains some useful information on list structures.

标签: string emacs lisp elisp yasnippet


【解决方案1】:

如果您评估字符串列表,则结果取决于列表项的值。最好的测试方法是启动 ielm repl (M-x 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"

对于 yasn-p 目录配置,您应该只设置 yas-sn-p-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.

【讨论】:

    【解决方案2】:

    我想你想要

    (setq yas/root-directory (list my-snippets-path default-snippets-path))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-13
      • 1970-01-01
      • 2013-01-10
      • 2015-07-28
      • 1970-01-01
      相关资源
      最近更新 更多