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 に答える