]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow font-spec in 'face-font-rescale-alist' set at startup
authorEli Zaretskii <eliz@gnu.org>
Thu, 15 Feb 2024 10:04:07 +0000 (12:04 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 15 Feb 2024 10:08:46 +0000 (11:08 +0100)
* lisp/startup.el (startup--rescale-elt-match-p): New function.
(normal-top-level): Use it, instead of the naive 'string-match-p',
to match the default font against the elements of
'face-font-rescale-alist'.  Reported by Rahguzar
<rahguzar@zohomail.eu>.

(cherry picked from commit 3d6137116f6be8ee38f9f49c9811b97ef92e0e58)

lisp/startup.el

index 773765a4b974c96c01ac4ec38c48746a83bae6c3..1c21b5de857a3bff17d2096bfcf60ddbf5cbdec5 100644 (file)
@@ -556,6 +556,17 @@ the updated value."
     (setq startup--original-eln-load-path
           (copy-sequence native-comp-eln-load-path))))
 
+(defun startup--rescale-elt-match-p (font-pattern font-object)
+  "Test whether FONT-OBJECT matches an element of `face-font-rescale-alist'.
+FONT-OBJECT is a font-object that specifies a font to test.
+FONT-PATTERN is the car of an element of `face-font-rescale-alist',
+which can be either a regexp matching a font name or a font-spec."
+  (if (stringp font-pattern)
+      ;; FONT-PATTERN is a regexp, we need the name of FONT-OBJECT to match.
+      (string-match-p font-pattern (font-xlfd-name font-object))
+    ;; FONT-PATTERN is a font-spec.
+    (font-match-p font-pattern font-object)))
+
 (defvar android-fonts-enumerated nil
   "Whether or not fonts have been enumerated already.
 On Android, Emacs uses this variable internally at startup.")
@@ -816,8 +827,9 @@ It is the default value of the variable `top-level'."
          (when (and (display-multi-font-p)
                      (not (eq face-font-rescale-alist
                              old-face-font-rescale-alist))
-                     (assoc (font-xlfd-name (face-attribute 'default :font))
-                            face-font-rescale-alist #'string-match-p))
+                     (assoc (face-attribute 'default :font)
+                            face-font-rescale-alist
+                            #'startup--rescale-elt-match-p))
            (set-face-attribute 'default nil :font (font-spec)))
 
          ;; Modify the initial frame based on what .emacs puts into