【问题标题】:ELisp: cl-loop for "Symbol's value as variable is void"ELisp:cl-loop 用于“符号作为变量的值是无效的”
【发布时间】:2014-01-01 17:10:56
【问题描述】:

我正在尝试使用(cl-loop for ..) 循环遍历一对列表,但是当代码在启动时执行(以及使用eval-buffer)时,我不断得到“符号的值作为变量是无效的:模式”,但在评估时却没有它与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))

我该如何解决这个问题?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    您的数据结构不是最适合该任务的,也就是说,它很麻烦 检查哪个文件对应于哪个模式。改用这个:

    (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))) 
    

    【讨论】:

    • 现在我得到“符号的变量值是无效的:x”。
    • 尝试将你的宏重写为函数
    • 奇怪的是,这行得通。 (defun diminish-after-load (file mode) "..." (eval-after-load file `(diminish ',mode)))
    • 这并不奇怪,宏的参数未计算,例如实际的 (car x) 而不是 (car x) 在这种情况下的 evals。
    • 嗯,有道理...谢谢。
    猜你喜欢
    • 2014-10-20
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    相关资源
    最近更新 更多