ELisp: cl-loop for “Symbol's value as variable is void”

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 14:37:02

问题


I'm trying to loop over a pair of lists using (cl-loop for ..) but I keep getting "Symbol's value as variable is void: mode" when the code executes at startup (and with eval-buffer), but not when evaluating it with eval-region.

;; clean up the modeline
(require 'diminish)
(defmacro diminish-after-load (file mode)
  "After loading FILE, execute `diminish' on MODE."
  `(eval-after-load ,file '(diminish ,mode)))
(require 'cl-lib)
(cl-loop for file in '("eldoc"     "rainbow-mode" "hideshow"    "flyspell"
                       "undo-tree" "whitespace"   "smartparens" "auto-complete")
         for mode in '(eldoc-mode       rainbow-mode    hs-minor-mode
                       flyspell-mode    undo-tree-mode  whitespace-mode
                       smartparens-mode auto-complete-mode)
         do (diminish-after-load file mode))

How do I fix this?


回答1:


Your data structures aren't optimal for the task, i.e. it's a bother to check which file corresponds to which mode. Use this instead:

(mapc
 (lambda (x)
   (diminish-after-load (car x) (cdr x)))
 '(("eldoc" . eldoc-mode) ("rainbow-mode" . rainbow-mode)
   ("hideshow" . hs-minor-mode) ("flyspell" . flyspell-mode)
   ("undo-tree" . undo-tree-mode) ("whitespace" . whitespace-mode)
   ("smartparens" . smartparens-mode) ("auto-complete" . auto-complete-mode))) 


来源:https://stackoverflow.com/questions/20871056/elisp-cl-loop-for-symbols-value-as-variable-is-void

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!