Subject: bug#58912: 29.0.50; set-face-attribute call in init.el has no lasting effect

From: Matt Armstrong <[email-masked]>
Date: Wed, 02 Nov 2022 14:55:18 -0700

Po Lu <[email-masked]> writes:

> Matt Armstrong <[email-masked]> writes:
>
>> I see the same symptoms as Dmitry.  I'm running a current Debian Testing
>> system, Gnome, Wayland.

[...]

>> ...I wonder if setting the 'default face attribute in 'early-init.el'
>> would be enough, too.
>
> Doesn't it only do that if font-use-system-font is t?

I am running these tests with emacs -Q, so `font-use-system-font' is
nil.

It looks like `font-use-system-font' variable has an effect only when
`event` is 'monospace-font-name.  What I see is a 'font-render event
happening after `init.el`.  I never see a 'monospace-font-name event
(even if I change the system monospace font with Gnome Tweaks).

I just did another run, placing the below into `test.el' and running
"emacs -Q -l test.el".

    ----------------------------------------------------------------------
    (trace-function #'dynamic-setting-handle-config-changed-event)
    (trace-function #'font-setting-change-default-font)
    (trace-function #'set-face-attribute)
    (trace-function #'face-attribute)
    (trace-function #'font-get)

    (set-face-attribute
     'default nil :height 110 :weight 'semi-light :family
     "Cascadia Mono")
    ----------------------------------------------------------------------

And this is what I see in "*trace-output*" after startup.  So, it looks
like `font-setting-change-default-font' is getting "IBM Plex Mono 11"
from the :user-spec of a Cascadia Mono font object, which seems strange.
In this case "IBM Plex Mono 11" is what I have set as my system's
default monospace font (in Gnome settings).

    ======================================================================
    1 -> (set-face-attribute default nil :height 110 :weight semi-light :family "Cascadia Mono")
    1 <- set-face-attribute: nil
    ======================================================================
    1 -> (dynamic-setting-handle-config-changed-event (config-changed-event font-render ":0"))
    | 2 -> (font-setting-change-default-font ":0" nil)
    | | 3 -> (face-attribute default :font #<frame *scratch* - GNU Emacs at naz 0x5598c59e4a70> default)
    | | 3 <- face-attribute: #<font-object "-SAJA-Cascadia Mono-semilight-normal-normal-*-15-*-*-*-m-0-iso10646-1">
    | | 3 -> (font-get #<font-object "-SAJA-Cascadia Mono-semilight-normal-normal-*-15-*-*-*-m-0-iso10646-1"> :user-spec)
    | | 3 <- font-get: "IBM Plex Mono 11"
    | | 3 -> (set-face-attribute default #<frame *scratch* - GNU Emacs at naz 0x5598c59e4a70> :width normal :weight normal :slant normal :font "IBM Plex Mono 11")
    | | 3 <- set-face-attribute: nil
    | 2 <- font-setting-change-default-font: nil
    1 <- dynamic-setting-handle-config-changed-event: nil
    ======================================================================

Also, I confirmed that moving the "test.el" code into early-init.el is
enough to "fix" the problem.  It looks like that runs even before the
default face is configured for the first time.

For completeness, here is how I'm running Emacs:

In GNU Emacs 29.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.16.0) of 2022-11-02 built on naz
Repository revision: 05f5d978ae70c4849a5c47865d62301d27317a8a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12201003
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure 'CFLAGS=-O2 -g3''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Message[Notmuch]

Minor modes in effect:
  company-mode: t
  msb-mode: t
  display-time-mode: t
  flyspell-mode: t
  mml-mode: t
  global-tab-line-mode: t
  tab-line-mode: t
  envrc-global-mode: t
  envrc-mode: t
  shell-dirtrack-mode: t
  auto-insert-mode: t
  keyfreq-autosave-mode: t
  keyfreq-mode: t
  savehist-mode: t
  icomplete-vertical-mode: t
  icomplete-mode: t
  editorconfig-mode: t
  which-key-mode: t
  electric-pair-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: message-do-auto-fill
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  temp-buffer-resize-mode: t
  abbrev-mode: t

Load-path shadows:
~/env/elisp/ol-notmuch hides /home/matt/.config/emacs/elpa/ol-notmuch-20220428.1337/ol-notmuch
/home/matt/.config/emacs/elpa/transient-20221028.1430/transient hides /home/matt/git/e/daily-driver/lisp/transient

Features:
(shadow emacsbug descr-text magit-base flymake-proc flymake compile
copyright shortdoc tabify imenu man eudc-capf eudc cus-edit pp cus-start
cus-load eudc-vars vc-git vc-dispatcher bug-reference help-fns
radix-tree misearch multi-isearch textsec uni-scripts idna-mapping
ucs-normalize uni-confusable textsec-check sort company-oddmuse
company-keywords company-etags etags fileloop xref company-gtags
company-dabbrev-code company-dabbrev company-files company-clang
company-capf company-cmake company-semantic company-template
company-bbdb company mail-extr smerge-mode diff mm-archive protbuf msb
time mule-util notmuch notmuch-tree notmuch-jump notmuch-hello
notmuch-show notmuch-print notmuch-crypto notmuch-mua notmuch-message
notmuch-draft notmuch-maildir-fcc notmuch-address notmuch-company
notmuch-parser notmuch-wash diff-mode coolj goto-addr icalendar
diary-lib diary-loaddefs notmuch-tag crm notmuch-lib notmuch-compat
pcase hl-line flyspell ispell org-element avl-tree generator ol-w3m
ol-rmail ol-mhe ol-irc ol-info org-habit org-agenda org-refile ol-gnus
nnselect gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls dig
gnus-sum gnus-group gnus-undo gnus-start gnus-dbus dbus gnus-cloud
nnimap nnmail mail-source utf7 nnoo parse-time gnus-spec gnus-int
gnus-range message sendmail yank-media rfc822 mml mml-sec epa derived
epg rfc6068 epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231
rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win
ol-eww eww xdg url-queue shr pixel-fill kinsoku url-file svg xml dom
puny mm-url gnus nnheader gnus-util text-property-search mail-utils
range wid-edit mm-util mail-prsvr ol-doi org-link-doi ol-docview
doc-view filenotify jka-compr image-mode exif dired dired-loaddefs
ol-bibtex ol-bbdb tab-line server envrc inheritenv web-mode disp-table
nix-mode ffap thingatpt smie nix-repl nix-shell nix-store magit-section
dash compat-27 compat-26 nix-log nix-instantiate nix-shebang nix-format
nix dirtrack ob-shell shell ob-ruby ob-python python compat compat-macs
ob-dot org-protocol org ob ob-tangle ob-ref ob-lob ob-table ob-exp
org-macro org-footnote org-src ob-comint org-pcomplete pcomplete comint
ansi-osc ansi-color ring org-list org-faces org-entities noutline
outline org-version ob-emacs-lisp ob-core ob-eval org-table oc-basic
bibtex iso8601 time-date org-keys oc org-loaddefs find-func cal-menu
calendar cal-loaddefs finder-inf ol-notmuch ol rx org-compat org-macs
format-spec skeleton autoinsert advice keyfreq project edmacro kmacro
warnings icons savehist icomplete editorconfig editorconfig-core
editorconfig-core-handle editorconfig-fnmatch which-key package
browse-url url url-proxy url-privacy url-expand url-methods url-history
url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers
url-parse auth-source eieio eieio-core password-cache json subr-x map
byte-opt url-vars cl-extra help-mode cl-macs gv cl-seq elec-pair
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core cl-loaddefs
cl-lib bytecomp byte-compile info bazel-autoloads
clang-format+-autoloads clang-format-autoloads cmake-mode-autoloads
d-mode-autoloads debbugs-autoloads editorconfig-autoloads elpy-autoloads
company-autoloads envrc-autoloads exec-path-from-shell-autoloads
flymake-ruby-autoloads flymake-easy-autoloads flymake-yamllint-autoloads
go-mode-autoloads google-c-style-autoloads graphviz-dot-mode-autoloads
highlight-indentation-autoloads inheritenv-autoloads magit-autoloads
git-commit-autoloads markdown-mode-autoloads meson-mode-autoloads
nix-mode-autoloads magit-section-autoloads dash-autoloads
nixpkgs-fmt-autoloads ol-notmuch-autoloads notmuch-autoloads
orderless-autoloads org-drill-autoloads ox-hugo-autoloads
persist-autoloads pylint-autoloads pyvenv-autoloads s-autoloads
shfmt-autoloads reformatter-autoloads tomelr-autoloads
transient-autoloads use-package-autoloads bind-key-autoloads
vertico-autoloads web-mode-autoloads which-key-autoloads
with-editor-autoloads compat-autoloads yaml-mode-autoloads
yasnippet-autoloads rmc iso-transl tooltip cconv eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 712036 95075)
 (symbols 48 49974 129)
 (strings 32 270832 9811)
 (string-bytes 1 6789117)
 (vectors 16 94289)
 (vector-slots 8 1982956 191956)
 (floats 8 457 689)
 (intervals 56 5349 1679)
 (buffers 984 31))