2012-08-17 90 views
1

我是elisp的新手,但我正在努力爲我的.emacs一點點。Emacs lisp:評估字符串列表

我想定義一些路徑,但有創建路徑列表(並更具體地設置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) 
+1

你所尋找的是使用兩個變量的新名單的建設。這確實可以通過使用列表函數來實現,如@jpkotta所述,儘管這不是對列表的評估,而是列表的結構。 配置snippet目錄的更有效的方法是將具有目錄的字符串列表分配給變量yas-snippet-dirs。 [Elisp Cookbook包含有關列表結構的一些有用信息](http://emacswiki.org/emacs/ElispCookbook#toc38)。 – 2012-08-17 16:57:20

回答

4

如果你評估一個字符串列表,結果取決於列表項的值。測試,最好的辦法是啓動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" 

對於yasnippet目錄配置,你應該只設置亞斯 - 摘錄-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) 

編輯:
採用亞斯/根目錄已被棄用。從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. 
1

文檔我想你想

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