在尝试简化我的 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/