From: Chong Yidong Date: Wed, 1 Feb 2012 08:13:02 +0000 (+0800) Subject: Fix dynamic font settings interaction with Custom Themes. X-Git-Tag: emacs-pretest-24.0.94~362^2~11 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9f5626684300af96cca5c2f86c377d93173e4cab;p=emacs.git Fix dynamic font settings interaction with Custom Themes. * lisp/dynamic-setting.el (font-setting-change-default-font): Use set-frame-font. * lisp/frame.el (set-frame-font): Tweak meaning of third argument. Fixes: debbugs:9982 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1187505be67..152acc03f14 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-02-01 Chong Yidong + + * frame.el (set-frame-font): Tweak meaning of third argument. + + * dynamic-setting.el (font-setting-change-default-font): Use + set-frame-font (Bug#9982). + 2012-02-01 Glenn Morris * progmodes/compile.el (compilation-internal-error-properties): diff --git a/lisp/dynamic-setting.el b/lisp/dynamic-setting.el index e04af7800fc..e967ddce332 100644 --- a/lisp/dynamic-setting.el +++ b/lisp/dynamic-setting.el @@ -42,45 +42,28 @@ If DISPLAY-OR-FRAME is a frame, the display is the one for that frame. 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)))) - (when new-font - ;; Be careful here: when set-face-attribute is called for the - ;; :font attribute, Emacs tries to guess the best matching font - ;; by examining the other face attributes (Bug#2476). - + (font-get-system-font))) + (frame-list (frames-on-display-list display-or-frame))) + (when (and new-font (display-graphic-p display-or-frame)) (clear-font-cache) - ;; Set for current frames. Only change font for those that have - ;; the old font now. If they don't have the old font, the user - ;; probably changed it. - (dolist (f (frames-on-display-list display-or-frame)) - (if (display-graphic-p f) - (let* ((frame-font - (or (font-get (face-attribute 'default :font f - 'default) :user-spec) - (frame-parameter f 'font-parameter))) - (font-to-set - (if set-font new-font - ;; else set font again, hinting etc. may have changed. - frame-font))) - (if font-to-set - (progn - (set-frame-parameter f 'font-parameter font-to-set) - (set-face-attribute 'default f - :width 'normal - :weight 'normal - :slant 'normal - :font font-to-set)))))) - - ;; Set for future frames. - (when set-font - ;; FIXME: this is not going to play well with Custom themes. - (set-face-attribute 'default t :font new-font) - (let ((spec (list (list t (face-attr-construct 'default))))) - (put 'default 'customized-face spec) - (custom-push-theme 'theme-face 'default 'user 'set spec) - (put 'default 'face-modified nil)))))) + (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) + ;; 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)))) + (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)))))))) (defun dynamic-setting-handle-config-changed-event (event) "Handle config-changed-event on the display in EVENT. diff --git a/lisp/frame.el b/lisp/frame.el index cf9c09b24ae..1cd6c0cf181 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1053,7 +1053,7 @@ If FRAME is omitted, describe the currently selected frame." (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1") -(defun set-frame-font (font-name &optional keep-size all-frames) +(defun set-frame-font (font-name &optional keep-size frames) "Set the default font to FONT-NAME. When called interactively, prompt for the name of a font, and use that font on the selected frame. @@ -1063,9 +1063,10 @@ fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try to keep the current frame size fixed (in pixels) by adjusting the number of lines and columns. -If ALL-FRAMES is nil, apply the font to the selected frame only. -If ALL-FRAMES is non-nil, apply the font to all frames; in -addition, alter the user's Customization settings as though the +If FRAMES is nil, apply the font to the selected frame only. +If FRAMES is non-nil, it should be a list of frames to act upon, +or t meaning all graphical frames. Also, if FRAME is non-nil, +alter the user's Customization settings as though the font-related attributes of the `default' face had been \"set in this session\", so that the font is applied to future frames." (interactive @@ -1079,9 +1080,14 @@ this session\", so that the font is applied to future frames." (list font current-prefix-arg nil))) (when (stringp font-name) (let* ((this-frame (selected-frame)) - (frames (if all-frames (frame-list) (list this-frame))) + ;; FRAMES nil means affect the selected frame. + (frame-list (cond ((null frames) + (list this-frame)) + ((eq frames t) + (frame-list)) + (t frames))) height width) - (dolist (f frames) + (dolist (f frame-list) (when (display-multi-font-p f) (if keep-size (setq height (* (frame-parameter f 'height) @@ -1099,7 +1105,7 @@ this session\", so that the font is applied to future frames." f (list (cons 'height (round height (frame-char-height f))) (cons 'width (round width (frame-char-width f)))))))) - (when all-frames + (when frames ;; Alter the user's Custom setting of the `default' face, but ;; only for font-related attributes. (let ((specs (cadr (assq 'user (get 'default 'theme-face))))