如何将一系列添加到列表的调用重构为let?

时间:2015-03-09 20:20:26

标签: elisp

我基本上想要重构以下内容:

(eval-after-load 'find-file-in-project
  '(progn
     (add-to-list 'ffip-patterns "*.clj")
     (add-to-list 'ffip-patterns "*.erb")
     (add-to-list 'ffip-patterns "*.haml")
     (add-to-list 'ffip-patterns "Gemfile*")
     (add-to-list 'ffip-patterns "*.css")
     (add-to-list 'ffip-patterns "*.scss")
     (add-to-list 'ffip-patterns "*.sass")
     (add-to-list 'ffip-patterns "*.rake")
     (add-to-list 'ffip-patterns "*.thor")
     (add-to-list 'ffip-patterns "Capfile")
     (add-to-list 'ffip-patterns "*.gemspec")
     (add-to-list 'ffip-patterns "*.yml")
     ))

在我定义文件扩展名列表的地方,然后将它们归入ffip-patterns变量。

1 个答案:

答案 0 :(得分:3)

如果您不担心列表中的重复项(add-to-list检查),您可以使用append添加元素:

(eval-after-load 'find-file-in-project
  '(setq ffip-patterns (append (list "*.clj" "*.erb") ffip-patterns)))

否则,您可以使用dolist

遍历扩展程序
(eval-after-load 'find-file-in-project
  '(dolist (pattern (list "*.clj" "*.erb"))
     (add-to-list 'ffip-patterns pattern)))