emacs - Emacs Lisp 的有趣错误

标签 emacs lisp elisp

在尝试简化我的 init.el 时,我决定将一些功能从丑陋的 cond 树中移出。为了从中移出一些决定,我构建了两个辅助函数:

(defun abstract-screen-width ()
  (cond ((eq 'x window-system) (x-display-pixel-width))
        ((eq 'ns window-system) (display-pixel-width))
        ))

(defun perfect-font-size (pixels)
  (cond ((eq 'x window-system) (cond ((<= pixels 1024) 100)
                                     ((<= pixels 1366) 110)
                                     ((> pixels 1366) 120)))
        ((eq 'ns window-system) (cond ((<= pixels 1024) 110)
                                      ((<= pixels 1280) 120)
                                      ((> pixels 1280) 140)))))

而且它们很好地结合在一起,并按照预期的方式调用它们,效果很好。

(perfect-font-size (abstract-screen-width))
130

custom-set-faces 调用是有效的

(custom-set-faces
        '(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
                                :strike-through nil :overline nil
                                :underline nil :slant normal :weight normal
                                :height 130 :width normal
                                :family "IBM 3270"))))
        '(linum ((t (:inherit default :foreground "#777" :height 130)))))

但我的“更好”版本

(custom-set-faces
        '(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
                                :strike-through nil :overline nil
                                :underline nil :slant normal :weight normal
                                :height (perfect-font-size (abstract-screen-width)) :width normal
                                :family "IBM 3270"))))
        '(linum ((t (:inherit default :foreground "#777" :height 120)))))

没有。它给出了“默认面高不是绝对的和正的”错误。 faces.el 和 cus-face.el 中的来源并没有多大帮助。有什么提示吗?

最佳答案

表达式

'(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
                            :strike-through nil :overline nil
                            :underline nil :slant normal :weight normal
                            :height (perfect-font-size (abstract-screen-width)) :width normal
                            :family "IBM 3270"))))

被完整引用,即 (perfect-font-size (abstract-screen-width)) 不会被评估。试试反引号:

`(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
                            :strike-through nil :overline nil
                            :underline nil :slant normal :weight normal
                            :height ,(perfect-font-size (abstract-screen-width)) :width normal
                            :family "IBM 3270"))))

(注意反引号和逗号)。这个错误只是 emacs 告诉你的方式,它更喜欢它得到列表的数字 (perfect-font-size (abstract-screen-width))

关于emacs - Emacs Lisp 的有趣错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10573219/

相关文章:

dictionary - 通过应用给定的操作将矩阵转换为向量的函数

emacs - (elisp) 向量的向量元素

haskell - 在 Emacs Lisp 中使用 foldr 实现 map

emacs - emacs 内每次更改后重新加载次要模式

list - 一切都是计划中的 list 吗?

scheme - call/cc 如何处理从 "Lisp in Small Pieces"开始的 CPS 转换?

emacs - 如何在 Emacs 中以文档 View 模式向下滚动页面?

javascript - 如何在 emacs javascript 模式下更改缩进宽度

emacs - 使用 slime 时如何跳转到 emacs 中的函数定义?

emacs - 在 Emacs 中获取光标下的字体