Putting the following code in my early-init.el causes my emacs not to startup.

(require 'cl-lib)

(defvar void-initial-frame-font
  (cl-find-if (lambda (font) (find-font (font-spec :name font)))
          (list "Victor Mono-19" "Anonymous-Pro-19"))
  "Font for initial frame.")

(push (cons 'font void-initial-frame-font) default-frame-alist)

The form (cl-find-if ...) evaluates to "Victor Mono-19". Thus void-initial-frame-font is "Victor Mono-19".

When I replace the variable void-initial-frame-font in the push form with what it should evaluate to, my emacs config starts up successfully with the frame font being "Victor Mono-19" as I would expect.

(require 'cl-lib)

(defvar void-initial-frame-font
  (cl-find-if (lambda (font) (find-font (font-spec :name font)))
          (list "Victor Mono-19" "Anonymous-Pro-19"))
  "Font for initial frame.")

;; replaced `void-initial-frame-font` with what it should evaluate to
(push (cons 'font "Victor Mono-19") default-frame-alist)

For fun, I tried to see if let binding the variable font would work, but it did not. The following form also causes my emacs to fail to start.

(require 'cl-lib)

(let ((font (cl-find-if (lambda (font) (find-font (font-spec :name font)))
            (list "Victor Mono-19" "Anonymous-Pro-19"))))
  (push (cons 'font font) default-frame-alist))

Why can't I store the result of evaluating the (cl-find-if ...) form early-init.el?

find-font is a built-in function in ‘C source code’.

(find-font FONT-SPEC &optional FRAME)

  Probably introduced at or before Emacs version 23.1.

Return a font-entity matching with FONT-SPEC on the current frame.
Optional 2nd argument FRAME, if non-nil, specifies the target frame.

I think you'll find that either there is no "current frame" during early init, or else that it's not a frame which is useful for this purpose.

  • But why then does it not generate an error in my second example? I still call find-font. The only difference is I don't set it to the variable. Does it just return something that's not read correctly by default-frame-alist before the frame is created? – Aquaactress Dec 17 '20 at 3:40
  • find-font will be returning nil. If you don't use the return value, there's no issue. I suspect you were creating an invalid entry for default-frame-alist when you used the nil value. – phils Dec 17 '20 at 4:20
  • You can easily test what's happening by using something other than default-frame-alist (e.g. defvar a custom alist with default value nil and substitute that), and then inspect that after starting Emacs. – phils Dec 17 '20 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.