When I start Emacs with emacs -Q --eval '(set-face-attribute (quote default) nil :height 180), the font changes for a split-second, but then returns to its default. Same thing if I put the code in my init file.

If I deliberately cause an error with emacs -Q --eval '(progn (set-face-attribute (quote default) nil :height 180) (bing)), the change sticks. But this doesn't work if I put the code in my init file—I guess that whatever mechanism Emacs uses to recover from init-file errors doesn't prevent the font-size-revert code from running.

How do I get Emacs to accept my default font size?

I'm running Emacs 25.1.2 (from kelleyk's PPA) on Ubuntu 16.10.

  • Is there a font that you can use in your default-frame-alist or initial-frame-alist that will serve to set the default to your liking such that you can forego using set-face-attribute? For example, on OSX --with-x my applicable frame parameter is (font . "-Adobe-Courier-normal-normal-normal-*-20-*-*-*-m-110-iso10646-1"). – lawlist Dec 14 '16 at 19:18
  • @lawlist I want to be able to set the default size conditionally (specifically, one size for when I'm using an external monitor and another for when I'm using my laptop's screen). I was able to do this by manually setting face attributes in Emacs 24. Will I still be able to do this with default-frame-alist or initial-frame-alist? – Kodiologist Dec 14 '16 at 19:22
  • What you are experiencing is likely a bug worthy of a bug report to the Emacs team. My idea is meant to be a potential workaround until your bug gets fixed. When I make frames during my Emacs session after startup, I rely upon the default-frame-alist and I also pass along additional frame parameters programmatically based on a situation -- e.g., (make-frame (list '(name . "ZTREE"))) You can have a function that determines your situation and passes the appropriate parameter based thereon. See also modify-frame-parameters and set-frame-parameter. – lawlist Dec 14 '16 at 19:34
  • This works fine for me on Emacs 25.1.50.3. Maybe one of the patches applied by kelleyk has interacted with something? – Tyler Dec 14 '16 at 19:37
  • 2
    Possible duplicate of something changes the default face in my .emacs – Tyler Apr 18 at 14:02
up vote 2 down vote accepted

One option is to add your own command-line switch, and deal with it in your init file, like this:

(setq big-font-p (member "--big-font" command-line-args))
(setq command-line-args (delete "--big-font" command-line-args))
(add-to-list 'default-frame-alist
             (if big-font-p
                 '(font . "DejaVu Sans Mono-18") ;; Big font
               '(font . "DejaVu Sans Mono-12"))) ;; Default font

In this case, if the option --big-font is not specified on the command-line, then your default font will be used.

  • Setting default-frame-alist, as originally suggested by lawlist, seems to work fine. Thanks, everyone. – Kodiologist Dec 14 '16 at 21:54

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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