1

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?

Ron
  • 1,989
  • 2
  • 17
  • 33

1 Answers1

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))) 
abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • Now I get "Symbol's value as variable is void: x". – Ron Jan 01 '14 at 17:27
  • Try to rewrite your macro as a function – abo-abo Jan 01 '14 at 17:30
  • Oddly enough, that worked. `(defun diminish-after-load (file mode) "..." (eval-after-load file \`(diminish ',mode)))` – Ron Jan 01 '14 at 17:38
  • It's not odd, macros get their args unevaluated, e.g. actual `(car x)` instead of what `(car x)` evals to in this context. – abo-abo Jan 01 '14 at 17:41
  • The (cdr x) was throwing the error, or the mode in this case. Although using defun makes more sense than using a macro in this case, if you wanted to fix yours, you'd have to construct the diminish list as such `\`(diminish ,,mode)` – nymo Jan 02 '14 at 23:22