Interesting bug with Emacs Lisp

While trying to arrange my init.el, I decided to port some functions from the ugly tree. To port some solutions from this, I built two helper functions:

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

And they combine perfectly and cause them the way they were designed to work, work great.

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

Call custom faces when it worked

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

but my "best" version

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

no. He gives the error "By default, the height of the face is not absolute and positive." The source in faces.el and cus-face.el did little to help. Any clues?

+3
source share
1 answer

Expression

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

cited in full, i.e. (perfect-font-size (abstract-screen-width))will not be evaluated. Try backquote instead:

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

(pay attention to the return line and comma). The error is just an emacs way to tell you that he preferred the number where he got the list(perfect-font-size (abstract-screen-width))

+9
source

All Articles