3

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.

Dan
  • 32,584
  • 6
  • 98
  • 168
  • 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
  • @lawlist I don't think this is a reportable bug unless it can be reproduced on an official Emacs build. Not sure what exactly is in the linked PPA – Tyler Dec 14 '16 at 19:39
  • To answer your question to @lawlist: Yes, you can set `default-frame-alist` with conditionally determined values computed at startup time. (Likewise, `initial-frame-alist`, but I doubt that you need to fiddle with that.) – Drew Dec 14 '16 at 20:50
  • @Tyler - I'm seeing this in the stock emacs supplied with Ubuntu 17.10. When I set the default face using customize-face, it works until I restart. Then, when I restart, it initially starts with the font I set up, but after about 1/4 of a second the font switches to the system default (DejaVu Mono 11.3pt). Going back in the customize faces menu, the settings there have been changed to that. I think it's something that ubuntu's startup scripts do. – Jules Apr 18 '18 at 08:21
  • ... which it turns out is because it's pulling information out of gnome config and changing the font there. See: https://emacs.stackexchange.com/a/32664/19074 – Jules Apr 18 '18 at 10:29
  • 2
    Possible duplicate of [something changes the default face in my .emacs](https://emacs.stackexchange.com/questions/32641/something-changes-the-default-face-in-my-emacs) – Tyler Apr 18 '18 at 14:02

1 Answers1

2

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.

nispio
  • 8,175
  • 2
  • 35
  • 73