2013-03-31 46 views
0

我不太打倒語法動態符號等,我想我大概可以做一些與dolist和這裏的顏色列表,但不知道是什麼:如何重構這個Emacs lisp?

(custom-set-faces 
    `(term-color-black ((t (:inherit term-color-black :background ,(face-attribute 'term-color-black :foreground))))) 
    `(term-color-red ((t (:inherit term-color-red :background ,(face-attribute 'term-color-red :foreground))))) 
    `(term-color-green ((t (:inherit term-color-green :background ,(face-attribute 'term-color-green :foreground))))) 
    `(term-color-yellow ((t (:inherit term-color-yellow :background ,(face-attribute 'term-color-yellow :foreground))))) 
    `(term-color-blue ((t (:inherit term-color-blue :background ,(face-attribute 'term-color-blue :foreground))))) 
    `(term-color-magenta ((t (:inherit term-color-magenta :background ,(face-attribute 'term-color-magenta :foreground))))) 
    `(term-color-cyan ((t (:inherit term-color-cyan :background ,(face-attribute 'term-color-cyan :foreground))))) 
    `(term-color-white ((t (:inherit term-color-white :background ,(face-attribute 'term-color-white :foreground)))))) 

回答

1

這不是100%相同,但在大多數情況下,將相當於:

(defmacro set-term-faces (names) 
    `(custom-set-faces 
    ,@(loop for color in names 
     for sym = (intern (concat "term-color-" (symbol-name color))) 
     collect (list 'quote 
         `(,sym ((t (:inherit ,sym 
            :background 
            ,(face-attribute sym :foreground))))))))) 

(set-term-faces (black red green yellow blue magenta cyan white)) 

的差異是在當,(face-attribute ...)評價發生的點。即這個宏不會產生相同的源代碼,它已經在逗號後評估表達式,所以如果你的代碼是在一個宏裏面的話,那會有所作爲。

1

可以重構那個代碼,但你可能不應該。所有(custom-set-...)代碼由Emacs的「easy customization」系統自動生成。因此,如果你重構它,還有就是

  1. 你打破與定製系統兼容性好的機會
  2. 您的重構代碼將原來的代碼下一次被覆蓋您自定義的臉

但是,如果您發現.emacs文件過於混亂,則可以配置Emacs將自定義代碼寫入單獨的文件。查看this answer相關的問題,以及Emacs的documentation

+0

該代碼不是由'customize'寫的 - 我自己寫的。我只是用'custom-set-faces'來覆蓋一些東西。 –

+0

在這種情況下,您可以直接使用'set-face-attribute'。 – Thomas

+0

......或者「defface」。 – Thomas