diff options
| author | Chong Yidong | 2012-01-31 16:38:58 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-01-31 16:38:58 +0800 |
| commit | fce3fdeb947e51656675129592c8514be32b46bf (patch) | |
| tree | 513a00667048d111fd309b587cebcdd5749fa376 | |
| parent | a037c17168419db7f5054a3ba080b94b9298c1a9 (diff) | |
| download | emacs-fce3fdeb947e51656675129592c8514be32b46bf.tar.gz emacs-fce3fdeb947e51656675129592c8514be32b46bf.zip | |
Fix menu-set-font interaction with Custom themes.
In particular, prevent it from setting non-font-related attributes
like the foreground and background color. This requires a bugfix to
face-spec-reset-face to make "resetting" the default face work.
* lisp/faces.el (face-spec-reset-face): Don't apply unspecified
attribute values to the default face.
* lisp/frame.el (set-frame-font): New arg ALL-FRAMES.
* lisp/menu-bar.el (menu-set-font): Use set-frame-font.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/faces.el | 11 | ||||
| -rw-r--r-- | lisp/frame.el | 84 | ||||
| -rw-r--r-- | lisp/menu-bar.el | 27 |
4 files changed, 81 insertions, 50 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9ba62b56449..ad25d537f2b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2012-01-31 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * frame.el (set-frame-font): New arg ALL-FRAMES. | ||
| 4 | |||
| 5 | * menu-bar.el (menu-set-font): Use set-frame-font. | ||
| 6 | |||
| 7 | * faces.el (face-spec-reset-face): Don't apply unspecified | ||
| 8 | attribute values to the default face. | ||
| 9 | |||
| 1 | 2012-01-31 Juanma Barranquero <lekktu@gmail.com> | 10 | 2012-01-31 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 11 | ||
| 3 | * progmodes/cwarn.el (cwarn): Remove dead link. | 12 | * progmodes/cwarn.el (cwarn): Remove dead link. |
diff --git a/lisp/faces.el b/lisp/faces.el index 5d406ad7c0b..cd7f92bfad4 100644 --- a/lisp/faces.el +++ b/lisp/faces.el | |||
| @@ -1513,11 +1513,12 @@ If SPEC is nil, return nil." | |||
| 1513 | 1513 | ||
| 1514 | (defun face-spec-reset-face (face &optional frame) | 1514 | (defun face-spec-reset-face (face &optional frame) |
| 1515 | "Reset all attributes of FACE on FRAME to unspecified." | 1515 | "Reset all attributes of FACE on FRAME to unspecified." |
| 1516 | (let (reset-args) | 1516 | (unless (eq face 'default) |
| 1517 | (dolist (attr-and-name face-attribute-name-alist) | 1517 | (let (reset-args) |
| 1518 | (push 'unspecified reset-args) | 1518 | (dolist (attr-and-name face-attribute-name-alist) |
| 1519 | (push (car attr-and-name) reset-args)) | 1519 | (push 'unspecified reset-args) |
| 1520 | (apply 'set-face-attribute face frame reset-args))) | 1520 | (push (car attr-and-name) reset-args)) |
| 1521 | (apply 'set-face-attribute face frame reset-args)))) | ||
| 1521 | 1522 | ||
| 1522 | (defun face-spec-set (face spec &optional for-defface) | 1523 | (defun face-spec-set (face spec &optional for-defface) |
| 1523 | "Set FACE's face spec, which controls its appearance, to SPEC. | 1524 | "Set FACE's face spec, which controls its appearance, to SPEC. |
diff --git a/lisp/frame.el b/lisp/frame.el index 392613defd6..cf9c09b24ae 100644 --- a/lisp/frame.el +++ b/lisp/frame.el | |||
| @@ -1052,15 +1052,22 @@ If FRAME is omitted, describe the currently selected frame." | |||
| 1052 | (pattern &optional face frame maximum width)) | 1052 | (pattern &optional face frame maximum width)) |
| 1053 | 1053 | ||
| 1054 | (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1") | 1054 | (define-obsolete-function-alias 'set-default-font 'set-frame-font "23.1") |
| 1055 | (defun set-frame-font (font-name &optional keep-size) | 1055 | |
| 1056 | "Set the font of the selected frame to FONT-NAME. | 1056 | (defun set-frame-font (font-name &optional keep-size all-frames) |
| 1057 | When called interactively, prompt for the name of the font to use. | 1057 | "Set the default font to FONT-NAME. |
| 1058 | To get the frame's current default font, use `frame-parameters'. | 1058 | When called interactively, prompt for the name of a font, and use |
| 1059 | 1059 | that font on the selected frame. | |
| 1060 | The default behavior is to keep the numbers of lines and columns in | 1060 | |
| 1061 | the frame, thus may change its pixel size. If optional KEEP-SIZE is | 1061 | If KEEP-SIZE is nil, keep the number of frame lines and columns |
| 1062 | non-nil (interactively, prefix argument) the current frame size (in | 1062 | fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try |
| 1063 | pixels) is kept by adjusting the numbers of the lines and columns." | 1063 | to keep the current frame size fixed (in pixels) by adjusting the |
| 1064 | number of lines and columns. | ||
| 1065 | |||
| 1066 | If ALL-FRAMES is nil, apply the font to the selected frame only. | ||
| 1067 | If ALL-FRAMES is non-nil, apply the font to all frames; in | ||
| 1068 | addition, alter the user's Customization settings as though the | ||
| 1069 | font-related attributes of the `default' face had been \"set in | ||
| 1070 | this session\", so that the font is applied to future frames." | ||
| 1064 | (interactive | 1071 | (interactive |
| 1065 | (let* ((completion-ignore-case t) | 1072 | (let* ((completion-ignore-case t) |
| 1066 | (font (completing-read "Font name: " | 1073 | (font (completing-read "Font name: " |
| @@ -1069,19 +1076,52 @@ pixels) is kept by adjusting the numbers of the lines and columns." | |||
| 1069 | (x-list-fonts "*" nil (selected-frame)) | 1076 | (x-list-fonts "*" nil (selected-frame)) |
| 1070 | nil nil nil nil | 1077 | nil nil nil nil |
| 1071 | (frame-parameter nil 'font)))) | 1078 | (frame-parameter nil 'font)))) |
| 1072 | (list font current-prefix-arg))) | 1079 | (list font current-prefix-arg nil))) |
| 1073 | (let (fht fwd) | 1080 | (when (stringp font-name) |
| 1074 | (if keep-size | 1081 | (let* ((this-frame (selected-frame)) |
| 1075 | (setq fht (* (frame-parameter nil 'height) (frame-char-height)) | 1082 | (frames (if all-frames (frame-list) (list this-frame))) |
| 1076 | fwd (* (frame-parameter nil 'width) (frame-char-width)))) | 1083 | height width) |
| 1077 | (modify-frame-parameters (selected-frame) | 1084 | (dolist (f frames) |
| 1078 | (list (cons 'font font-name))) | 1085 | (when (display-multi-font-p f) |
| 1079 | (if keep-size | 1086 | (if keep-size |
| 1080 | (modify-frame-parameters | 1087 | (setq height (* (frame-parameter f 'height) |
| 1081 | (selected-frame) | 1088 | (frame-char-height f)) |
| 1082 | (list (cons 'height (round fht (frame-char-height))) | 1089 | width (* (frame-parameter f 'width) |
| 1083 | (cons 'width (round fwd (frame-char-width))))))) | 1090 | (frame-char-width f)))) |
| 1084 | (run-hooks 'after-setting-font-hook 'after-setting-font-hooks)) | 1091 | ;; When set-face-attribute is called for :font, Emacs |
| 1092 | ;; guesses the best font according to other face attributes | ||
| 1093 | ;; (:width, :weight, etc.) so reset them too (Bug#2476). | ||
| 1094 | (set-face-attribute 'default f | ||
| 1095 | :width 'normal :weight 'normal | ||
| 1096 | :slant 'normal :font font-name) | ||
| 1097 | (if keep-size | ||
| 1098 | (modify-frame-parameters | ||
| 1099 | f | ||
| 1100 | (list (cons 'height (round height (frame-char-height f))) | ||
| 1101 | (cons 'width (round width (frame-char-width f)))))))) | ||
| 1102 | (when all-frames | ||
| 1103 | ;; Alter the user's Custom setting of the `default' face, but | ||
| 1104 | ;; only for font-related attributes. | ||
| 1105 | (let ((specs (cadr (assq 'user (get 'default 'theme-face)))) | ||
| 1106 | (attrs '(:family :foundry :slant :weight :height :width)) | ||
| 1107 | (new-specs nil)) | ||
| 1108 | (if (null specs) (setq specs '((t nil)))) | ||
| 1109 | (dolist (spec specs) | ||
| 1110 | ;; Each SPEC has the form (DISPLAY ATTRIBUTE-PLIST) | ||
| 1111 | (let ((display (nth 0 spec)) | ||
| 1112 | (plist (copy-tree (nth 1 spec)))) | ||
| 1113 | ;; Alter only DISPLAY conditions matching this frame. | ||
| 1114 | (when (or (memq display '(t default)) | ||
| 1115 | (face-spec-set-match-display display this-frame)) | ||
| 1116 | (dolist (attr attrs) | ||
| 1117 | (setq plist (plist-put plist attr | ||
| 1118 | (face-attribute 'default attr))))) | ||
| 1119 | (push (list display plist) new-specs))) | ||
| 1120 | (setq new-specs (nreverse new-specs)) | ||
| 1121 | (put 'default 'customized-face new-specs) | ||
| 1122 | (custom-push-theme 'theme-face 'default 'user 'set new-specs) | ||
| 1123 | (put 'default 'face-modified nil)))) | ||
| 1124 | (run-hooks 'after-setting-font-hook 'after-setting-font-hooks))) | ||
| 1085 | 1125 | ||
| 1086 | (defun set-frame-parameter (frame parameter value) | 1126 | (defun set-frame-parameter (frame parameter value) |
| 1087 | "Set frame parameter PARAMETER to VALUE on FRAME. | 1127 | "Set frame parameter PARAMETER to VALUE on FRAME. |
diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 7e54a9762ec..1f57601a711 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el | |||
| @@ -683,29 +683,10 @@ by \"Save Options\" in Custom buffers.") | |||
| 683 | (defun menu-set-font () | 683 | (defun menu-set-font () |
| 684 | "Interactively select a font and make it the default." | 684 | "Interactively select a font and make it the default." |
| 685 | (interactive) | 685 | (interactive) |
| 686 | (let ((font (if (fboundp 'x-select-font) | 686 | (set-frame-font (if (fboundp 'x-select-font) |
| 687 | (x-select-font) | 687 | (x-select-font) |
| 688 | (mouse-select-font))) | 688 | (mouse-select-font)) |
| 689 | spec) | 689 | nil t)) |
| 690 | (when font | ||
| 691 | ;; Be careful here: when set-face-attribute is called for the | ||
| 692 | ;; :font attribute, Emacs tries to guess the best matching font | ||
| 693 | ;; by examining the other face attributes (Bug#2476). | ||
| 694 | (set-face-attribute 'default (selected-frame) | ||
| 695 | :width 'normal | ||
| 696 | :weight 'normal | ||
| 697 | :slant 'normal | ||
| 698 | :font font) | ||
| 699 | (let ((font-object (face-attribute 'default :font))) | ||
| 700 | (dolist (f (frame-list)) | ||
| 701 | (and (not (eq f (selected-frame))) | ||
| 702 | (display-graphic-p f) | ||
| 703 | (set-face-attribute 'default f :font font-object))) | ||
| 704 | (set-face-attribute 'default t :font font-object)) | ||
| 705 | (setq spec (list (list t (face-attr-construct 'default)))) | ||
| 706 | (put 'default 'customized-face spec) | ||
| 707 | (custom-push-theme 'theme-face 'default 'user 'set spec) | ||
| 708 | (put 'default 'face-modified nil)))) | ||
| 709 | 690 | ||
| 710 | (defun menu-bar-options-save () | 691 | (defun menu-bar-options-save () |
| 711 | "Save current values of Options menu items using Custom." | 692 | "Save current values of Options menu items using Custom." |