annotate lisp/font-setting.el @ 111939:bb8b0f23abc5

Fix bug #7563 with docs of split-string-and-unquote. processes.texi (Shell Arguments): Fix documentation of `split-string-and-unquote'. Add indexing.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 11 Dec 2010 11:41:45 +0200
parents 1359517bb5ef
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109259
e76d2bc9dbbe * dnd.el, font-setting.el, x-dnd.el: Use utf-8 coding (for author name).
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
1 ;;; font-setting.el --- Support dynamic font changes -*- coding: utf-8 -*-
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106750
diff changeset
3 ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
4
109260
1359517bb5ef * lisp/font-setting.el: Fix previous change.
Glenn Morris <rgm@gnu.org>
parents: 109259
diff changeset
5 ;; Author: Jan Djärv <jan.h.d@swipnet.se>
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
6 ;; Maintainer: FSF
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
7 ;; Keywords: font, system-font
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
8
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
10
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
14 ;; (at your option) any later version.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
15
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
19 ;; GNU General Public License for more details.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
20
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
23
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
24 ;;; Commentary:
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
25
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
26 ;; This file provides the lisp part of the GConf and XSetting code in
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
27 ;; xsetting.c. But it is nothing that prevents it from being used by
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
28 ;; other configuration schemes.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
29
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
30 ;;; Code:
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
31
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
32 ;;; Customizable variables
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
33
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
34 (declare-function font-get-system-font "xsettings.c" ())
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
35
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
36 (defvar font-use-system-font)
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
37
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
38 (defun font-setting-change-default-font (display-or-frame set-font)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
39 "Change font and/or font settings for frames on display DISPLAY-OR-FRAME.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
40 If DISPLAY-OR-FRAME is a frame, the display is the one for that frame.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
41
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
42 If SET-FONT is non-nil, change the font for frames. Otherwise re-apply the
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
43 current form for the frame (i.e. hinting or somesuch changed)."
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
44
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
45 (let ((new-font (and (fboundp 'font-get-system-font)
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
46 (font-get-system-font))))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
47 (when new-font
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
48 ;; Be careful here: when set-face-attribute is called for the
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
49 ;; :font attribute, Emacs tries to guess the best matching font
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
50 ;; by examining the other face attributes (Bug#2476).
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
51
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
52 (clear-font-cache)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
53 ;; Set for current frames. Only change font for those that have
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
54 ;; the old font now. If they don't have the old font, the user
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
55 ;; probably changed it.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
56 (dolist (f (frames-on-display-list display-or-frame))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
57 (if (display-graphic-p f)
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
58 (let* ((frame-font
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
59 (or (font-get (face-attribute 'default :font f
106750
10b9609fb6b7 Fixing user-spec for fonts instead of using name.
Jan D. <jan.h.d@swipnet.se>
parents: 106352
diff changeset
60 'default) :user-spec)
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
61 (frame-parameter f 'font-parameter)))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
62 (font-to-set
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
63 (if set-font new-font
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
64 ;; else set font again, hinting etc. may have changed.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
65 frame-font)))
106097
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
66 (if font-to-set
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
67 (progn
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
68 (message "setting %s" font-to-set)
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
69 (set-frame-parameter f 'font-parameter font-to-set)
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
70 (set-face-attribute 'default f
106097
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
71 :width 'normal
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
72 :weight 'normal
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
73 :slant 'normal
5fa329215a93 xsettings.c didn't check font-use-system-font, fix that.
Jan Djärv <jan.h.d@swipnet.se>
parents: 106085
diff changeset
74 :font font-to-set))))))
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
75
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
76 ;; Set for future frames.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
77 (set-face-attribute 'default t :font new-font)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
78 (let ((spec (list (list t (face-attr-construct 'default)))))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
79 (progn
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
80 (put 'default 'customized-face spec)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
81 (custom-push-theme 'theme-face 'default 'user 'set spec)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
82 (put 'default 'face-modified nil))))))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
83
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
84 (defun font-setting-handle-config-changed-event (event)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
85 "Handle config-changed-event to change fonts on the display in EVENT.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
86 If `font-use-system-font' is nil, the font is not changed."
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
87 (interactive "e")
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
88 (let ((type (nth 1 event)) ;; font-name or font-render
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
89 (display-name (nth 2 event)))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
90 (if (or (not (eq type 'font-name))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
91 font-use-system-font)
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
92 (font-setting-change-default-font display-name
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
93 (eq type 'font-name)))))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
94
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
95 (if (or (featurep 'system-font-setting) (featurep 'font-render-setting))
106102
0cdf7c60b414 * font-setting.el (font-use-system-font): Declare for byte-compiler.
Juanma Barranquero <lekktu@gmail.com>
parents: 106097
diff changeset
96 (define-key special-event-map [config-changed-event]
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
97 'font-setting-handle-config-changed-event))
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
98
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
99 (provide 'font-setting)
106352
3b90f039f42b Add arch tagline
Miles Bader <miles@gnu.org>
parents: 106102
diff changeset
100
3b90f039f42b Add arch tagline
Miles Bader <miles@gnu.org>
parents: 106102
diff changeset
101 ;; arch-tag: 3a57e78f-1cd6-48b6-ab75-98f160dcc017