首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emacs Lisp中的有趣错误

Emacs Lisp中的有趣错误
EN

Stack Overflow用户
提问于 2012-05-14 00:13:55
回答 1查看 338关注 0票数 3

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

代码语言:javascript
复制
(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)))))

它们很好地结合在一起,并且按照它们被调用的方式调用它们工作得很好。

代码语言:javascript
复制
(perfect-font-size (abstract-screen-width))
130

custom-set-faces调用的原样

代码语言:javascript
复制
(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)))))

但我的“更好”版本

代码语言:javascript
复制
(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中的源代码并没有多大帮助。有什么提示吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-14 00:25:50

表达式

代码语言:javascript
复制
'(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))不会被计算。请尝试反引号:

代码语言:javascript
复制
`(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))的位置

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10573219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档