Subject: Re: [emacs-bug] bug#25228: 25.1; GNU emacs 25.1: custom-set-faces from init file ~/.emacs ignored

From: "Dr. Werner Fink" <[email-masked]>
Date: Tue, 20 Dec 2016 17:56:48 +0100

On Tue, Dec 20, 2016 at 05:41:39PM +0100, Werner Fink wrote:
> > why I asked to describe which code triggers this and how it started
> > affecting us after commit e65c307.
> 
> The only guess I have is that the correction had now enabled the :user-spec
> key/attribute.  For a workaround I've change some lines of code in
> lisp/dynamic-setting.el ... compare with the attached patch.
> 
> With this patch both the custom font if enabled in ~/.emacs as well as
> the system font works here for GNU Emacs with GTK as well as with X11.

Wrong version of the patch, this one seems to be better one ;)

-- 
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
Work around openSUSE bug #1016172
 
--
 lisp/dynamic-setting.el |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

--- lisp/dynamic-setting.el
+++ lisp/dynamic-setting.el	2016-12-20 16:51:49.533433283 +0000
@@ -33,6 +33,7 @@
 ;;; Customizable variables
 
 (declare-function font-get-system-font "xsettings.c" ())
+(declare-function font-face-attributes "font.c" (font &optional frame))
 
 (defvar font-use-system-font)
 
@@ -42,28 +43,28 @@ If DISPLAY-OR-FRAME is a frame, the disp
 
 If SET-FONT is non-nil, change the font for frames.  Otherwise re-apply the
 current form for the frame (i.e. hinting or somesuch changed)."
-  (let ((new-font (and (fboundp 'font-get-system-font)
-		       (font-get-system-font)))
-	(frame-list (frames-on-display-list display-or-frame)))
-    (when (and new-font (display-graphic-p display-or-frame))
+  (let ((system-font (and (fboundp 'font-get-system-font)
+                       (font-get-system-font)))
+        (frame-list (frames-on-display-list display-or-frame))
+	(user-font (face-attribute 'default :font)))
+    (when (and system-font (display-graphic-p display-or-frame))
       (clear-font-cache)
       (if set-font
 	  ;; Set the font on all current and future frames, as though
 	  ;; the `default' face had been "set for this session":
-	  (set-frame-font new-font nil frame-list)
+	  (if (not user-font)
+	      (set-frame-font system-font nil frame-list)
+	     (set-frame-font user-font nil frame-list))
 	;; Just redraw the existing fonts on all frames:
 	(dolist (f frame-list)
-	  (let ((frame-font
-		 (or (font-get (face-attribute 'default :font f 'default)
-			       :user-spec)
-		     (frame-parameter f 'font-parameter))))
+	  ;; (apply 'font-spec (font-face-attributes (font-get-system-font)))
+	  (let* ((frame-font
+		  (or (face-attribute 'default :font f 'default)
+		      (frame-parameter f 'font-parameter)))
+		 (font-attr (font-face-attributes frame-font)))
 	    (when frame-font
 	      (set-frame-parameter f 'font-parameter frame-font)
-	      (set-face-attribute 'default f
-				  :width 'normal
-				  :weight 'normal
-				  :slant 'normal
-				  :font frame-font))))))))
+	      (apply #'set-face-attribute 'default f font-attr))))))))
 
 (defun dynamic-setting-handle-config-changed-event (event)
   "Handle config-changed-event on the display in EVENT.