annotate lisp/dynamic-setting.el @ 109785:de5d6a3f1493

* lisp/progmodes/etags.el (tags-file-name): Mark safe if stringp (Bug#6733).
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 14 Aug 2010 19:01:42 -0400
parents be18c3b67d66
children fe9b13a5f44f 3226ac2da7f7 280c8ae2476d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
1 ;;; dynamic-setting.el --- Support dynamic changes
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
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
5 ;; Author: Jan Djärv <jan.h.d@swipnet.se>
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
6 ;; Maintainer: FSF
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
7 ;; Keywords: font, system-font, tool-bar-style
106085
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 (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
69 (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
70 :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
71 :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
72 :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
73 :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
74
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
75 ;; Set for future frames.
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
76 (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
77 (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
78 (progn
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
79 (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
80 (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
81 (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
82
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
83 (defun dynamic-setting-handle-config-changed-event (event)
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
84 "Handle config-changed-event on the display in EVENT.
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
85 Changes can be
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
86 The monospace font. If `font-use-system-font' is nil, the font
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
87 is not changed.
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
88 Xft parameters, like DPI and hinting.
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
89 The tool bar style."
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
90 (interactive "e")
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
91 (let ((type (nth 1 event))
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
92 (display-name (nth 2 event)))
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
93 (cond ((and (eq type 'monospace-font-name) font-use-system-font)
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
94 (font-setting-change-default-font display-name t))
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
95
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
96 ((eq type 'font-render)
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
97 (font-setting-change-default-font display-name nil))
106085
cd4cbab8bb21 Handle system default font and changing font parameters.
Jan Djärv <jan.h.d@swipnet.se>
parents:
diff changeset
98
109749
be18c3b67d66 Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents: 109070
diff changeset
99 ;; This is a bit heavy, ideally we would just clear faces
be18c3b67d66 Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents: 109070
diff changeset
100 ;; on the affected display, and perhaps only the relevant
be18c3b67d66 Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents: 109070
diff changeset
101 ;; faces. Oh well.
be18c3b67d66 Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents: 109070
diff changeset
102 ((eq type 'theme-name) (clear-face-cache))
be18c3b67d66 Take colors for region face (selected text) from the Gtk+ theme.
Jan D <jan.h.d@swipnet.se>
parents: 109070
diff changeset
103
108024
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
104 ((eq type 'tool-bar-style) (force-mode-line-update t)))))
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
105
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
106 (define-key special-event-map [config-changed-event]
4d8277a44bb4 Gtk tool bars can be text, icons with text or just icons.
Jan D. <jan.h.d@swipnet.se>
parents: 106815
diff changeset
107 'dynamic-setting-handle-config-changed-event)
106352
3b90f039f42b Add arch tagline
Miles Bader <miles@gnu.org>
parents: 106102
diff changeset
108
3b90f039f42b Add arch tagline
Miles Bader <miles@gnu.org>
parents: 106102
diff changeset
109 ;; arch-tag: 3a57e78f-1cd6-48b6-ab75-98f160dcc017