aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2008-06-03 11:05:52 +0000
committerMiles Bader2008-06-03 11:05:52 +0000
commit9d3d42fb740e4921418e5ccabd71519b1c468292 (patch)
tree4b54dfacd9e3da53f4389f651a2ab44609929f48
parentf474904ea7091484dafee9d9e4e48cd5b812a9d4 (diff)
downloademacs-9d3d42fb740e4921418e5ccabd71519b1c468292.tar.gz
emacs-9d3d42fb740e4921418e5ccabd71519b1c468292.zip
Add lisp/face-remap.el and associated documentation
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1200
-rw-r--r--doc/emacs/ChangeLog4
-rw-r--r--doc/emacs/display.texi36
-rw-r--r--doc/lispref/ChangeLog6
-rw-r--r--doc/lispref/display.texi72
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/Makefile.in1
-rw-r--r--lisp/face-remap.el242
7 files changed, 366 insertions, 0 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index 1520c26f1e8..314c42d4dff 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,7 @@
12008-06-03 Miles Bader <miles@gnu.org>
2
3 * display.texi (Temporary Face Changes): New node.
4
12008-05-31 Eli Zaretskii <eliz@gnu.org> 52008-05-31 Eli Zaretskii <eliz@gnu.org>
2 6
3 * msdog.texi (Windows Keyboard): Fix text added on 2008-05-29. 7 * msdog.texi (Windows Keyboard): Fix text added on 2008-05-29.
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index b48d6bbab7d..9cf8c986d4a 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -31,6 +31,7 @@ their values only make a difference at the time of redisplay.
31* Cursor Display:: Features for displaying the cursor. 31* Cursor Display:: Features for displaying the cursor.
32* Line Truncation:: Truncating lines to fit the screen width instead 32* Line Truncation:: Truncating lines to fit the screen width instead
33 of continuing them to multiple screen lines. 33 of continuing them to multiple screen lines.
34* Temporary Face Changes:: Commands to temporarily modify the default text face
34* Display Custom:: Information on variables for customizing display. 35* Display Custom:: Information on variables for customizing display.
35@end menu 36@end menu
36 37
@@ -1171,6 +1172,41 @@ truncate a line which is exactly as wide as the window. Instead, the
1171newline overflows into the right fringe, and the cursor appears in the 1172newline overflows into the right fringe, and the cursor appears in the
1172fringe when positioned on that newline. 1173fringe when positioned on that newline.
1173 1174
1175@node Temporary Face Changes
1176@section Temporary Face Changes
1177
1178These are commands which temporarily change the default face used to
1179display text in a buffer.
1180
1181@cindex increase buffer face height
1182@findex increase-buffer-face-height
1183@cindex decrease buffer face height
1184@findex decrease-buffer-face-height
1185@findex text-scale-mode
1186To increase the size of the font used to display text in the current
1187buffer, type @kbd{C-=} or @kbd{C-+}
1188(@code{increase-buffer-face-height}). With a numeric prefix argument,
1189the size will be increased by that many steps (the default is 1 step);
1190each step scales the font height by the value of the variable
1191@code{text-scale-mode-step}. If repeated, this command has a
1192cumulative effect. As a special case, a prefix argument of 0 will
1193remove any scaling currently active.
1194
1195To decrease the size of the text, type @kbd{C--}
1196(@code{decrease-buffer-face-height}). The behavior is similar to that
1197of @code{increase-buffer-face-height}, but in reverse.
1198
1199These commands automatically enable or disable the
1200@code{text-scale-mode} minor-mode, depending on whether the current
1201font scaling is other than 1 or not.
1202
1203@cindex variable pitch mode
1204@findex variable-pitch-mode
1205To temporarily change the display face in the current buffer to a
1206variable-pitch (``proportional'') font, use the command @kbd{M-x
1207variable-pitch-mode} to enable or disable the Variable Pitch minor
1208mode.
1209
1174@node Display Custom 1210@node Display Custom
1175@section Customization of Display 1211@section Customization of Display
1176 1212
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 943504fce04..92d49d94a62 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,9 @@
12008-06-03 Miles Bader <miles@gnu.org>
2
3 * display.texi (Displaying Faces): Add
4 add-relative-face-remapping, remove-relative-face-remapping,
5 set-base-face-remapping, and set-default-base-face-remapping.
6
12008-06-01 Miles Bader <miles@gnu.org> 72008-06-01 Miles Bader <miles@gnu.org>
2 8
3 * display.texi (Displaying Faces): Add face-remapping-alist. 9 * display.texi (Displaying Faces): Add face-remapping-alist.
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index bc57cfea26d..ef8f5bc4e5c 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -2420,6 +2420,78 @@ with the height doubled:
2420 2420
2421@end defvar 2421@end defvar
2422 2422
2423@noindent
2424The following functions implement a somewhat higher-level interface to
2425@code{face-remapping-alist}, making it easier to use
2426``cooperatively''. They are mainly intended for buffer-local use, and
2427so all make @code{face-remapping-alist} variable buffer-local as a
2428side-effect.
2429
2430These functions use entries in @code{face-remapping-alist} which have
2431the general form:
2432
2433@example
2434 (@var{face} @var{relative_specs_1} @var{relative_specs_2} @var{...} @var{base_specs})
2435@end example
2436
2437Everything except the @var{face} is a ``face spec'', a list of face
2438names or face attribute-value pairs. All face specs are merged
2439together, with earlier values taking precedence.
2440
2441The @var{relative_specs_}n values are ``relative specs'', and are
2442added by @code{add-relative-face-remapping} (and removed by
2443@code{remove-relative-face-remapping}. These are intended for face
2444modifications (such as increasing the size). Typical users of these
2445relative specs would be minor modes.
2446
2447@var{base_specs} is the lowest-priority value, and by default is just the
2448face name, which causes the global definition of that face to be used.
2449
2450A non-default value of @var{base_specs} may also be set using
2451@code{set-base-face-remapping}. Because this @emph{overwrites} the
2452default base-spec value (which inherits the global face definition),
2453it is up to the caller of @code{set-base-face-remapping} to add such
2454inheritance if it is desired. A typical use of
2455@code{set-base-face-remapping} would be a major mode adding a face
2456remappings, e.g., of the default face.
2457
2458
2459@defun add-relative-face-remapping face &rest specs
2460This functions adds a face remapping entry of @var{face} to @var{specs}
2461in the current buffer.
2462
2463It returns a ``cookie'' which can be used to later delete the remapping with
2464@code{remove-relative-face-remapping}.
2465
2466@var{specs} can be any value suitable for the @code{face} text
2467property, including a face name, a list of face names, or a
2468face-attribute property list. The attributes given by @var{specs}
2469will be merged with any other currently active face remappings of
2470@var{face}, and with the global definition of @var{face} (by default;
2471this may be changed using @code{set-base-face-remapping}),
2472with the most recently added relative remapping taking precedence.
2473@end defun
2474
2475@defun remove-relative-face-remapping cookie
2476This function removes a face remapping previously added by
2477@code{add-relative-face-remapping}. @var{cookie} should be a return
2478value from that function.
2479@end defun
2480
2481@defun set-base-face-remapping face &rest specs
2482This function sets the ``base remapping'' of @var{face} in the current
2483buffer to @var{specs}. If @var{specs} is empty, the default base
2484remapping is restored, which inherits from the global definition of
2485@var{face}; note that this is different from @var{specs} containing a
2486single value @code{nil}, which has the opposite result (the global
2487definition of @var{face} is ignored).
2488@end defun
2489
2490@defun set-default-base-face-remapping face
2491This function sets the ``base remapping'' of @var{face} to its default
2492value, which inherits from @var{face}'s global definition.
2493@end defun
2494
2423@node Font Selection 2495@node Font Selection
2424@subsection Font Selection 2496@subsection Font Selection
2425 2497
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0f9730d19b9..33a7651ad93 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12008-06-03 Miles Bader <miles@gnu.org>
2
3 * face-remap.el: New file.
4 * Makefile.in (ELCFILES): Add face-remap.elc.
5
12008-06-03 Stefan Monnier <monnier@iro.umontreal.ca> 62008-06-03 Stefan Monnier <monnier@iro.umontreal.ca>
2 7
3 * progmodes/flymake.el (flymake-process-filter): Make sure the source 8 * progmodes/flymake.el (flymake-process-filter): Make sure the source
diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index b92024e7242..2fa71c9a52e 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -480,6 +480,7 @@ ELCFILES = \
480 $(lisp)/eshell/eshell.elc \ 480 $(lisp)/eshell/eshell.elc \
481 $(lisp)/expand.elc \ 481 $(lisp)/expand.elc \
482 $(lisp)/ezimage.elc \ 482 $(lisp)/ezimage.elc \
483 $(lisp)/face-remap.elc \
483 $(lisp)/facemenu.elc \ 484 $(lisp)/facemenu.elc \
484 $(lisp)/faces.elc \ 485 $(lisp)/faces.elc \
485 $(lisp)/ffap.elc \ 486 $(lisp)/ffap.elc \
diff --git a/lisp/face-remap.el b/lisp/face-remap.el
new file mode 100644
index 00000000000..fe517a77a33
--- /dev/null
+++ b/lisp/face-remap.el
@@ -0,0 +1,242 @@
1;;; face-remap.el --- Functions for managing `face-remapping-alist'
2;;
3;; Copyright (C) 2008 Free Software Foundation, Inc.
4;;
5;; Author: Miles Bader <miles@gnu.org>
6;; Keywords: faces face display user commands
7;;
8;; This file is part of GNU Emacs.
9;;
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14;;
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19;;
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22;;
23
24;;; Commentary:
25
26;;
27;; This file defines some simple operations that can be used for
28;; maintaining the `face-remapping-alist' in a cooperative way. This is
29;; especially important for the `default' face.
30;;
31;; Each face-remapping definition in `face-remapping-alist' added by
32;; this code uses the form:
33;;
34;; (face RELATIVE_SPECS_1 RELATIVE_SPECS_2 ... BASE_SPECS)
35;;
36;; The "specs" values are a lists of face names or face attribute-value
37;; pairs, and are merged together, with earlier values taking precedence.
38;;
39;; The RELATIVE_SPECS_* values are added by `add-relative-face-remapping'
40;; (and removed by `remove-relative-face-remapping', and are intended for
41;; face "modifications" (such as increasing the size). Typical users of
42;; relative specs would be minor modes.
43;;
44;; BASE_SPECS is the lowest-priority value, and by default is just the
45;; face name, which causes the global definition of that face to be used.
46;;
47;; A non-default value of BASE_SPECS may also be set using
48;; `set-base-face-remapping'. Because this _overwrites_ the default
49;; value inheriting from the global face definition, it is up to the
50;; caller of set-base-face-remapping to add such inheritance if it is
51;; desired. A typical use of set-base-face-remapping would be a major
52;; mode setting face remappings, e.g., of the default face.
53;;
54;; All modifications cause face-remapping-alist to be made buffer-local.
55;;
56
57
58;;; Code:
59
60
61;; ----------------------------------------------------------------
62;; Utility functions
63
64;;;### autoload
65(defun add-relative-face-remapping (face &rest specs)
66 "Add a face remapping entry of FACE to SPECS in the current buffer.
67
68Return a cookie which can be used to delete the remapping with
69`remove-relative-face-remapping'.
70
71SPECS can be any value suitable for the `face' text property,
72including a face name, a list of face names, or a face-attribute
73property list. The attributes given by SPECS will be merged with
74any other currently active face remappings of FACE, and with the
75global definition of FACE, with the most recently added relative
76remapping taking precedence.
77
78The base (lowest priority) remapping may be set to a specific
79value, instead of the default of the global face definition,
80using `set-base-face-remapping'."
81 (make-local-variable 'face-remapping-alist)
82 (let ((entry (assq face face-remapping-alist)))
83 (when (null entry)
84 (setq entry (list face face)) ; explicitly merge with global def
85 (push entry face-remapping-alist))
86 (setcdr entry (cons specs (cdr entry)))
87 (cons face specs)))
88
89(defun remove-relative-face-remapping (cookie)
90 "Remove a face remapping previously added by `add-relative-face-remapping'.
91COOKIE should be the return value from that function."
92 (let ((remapping (assq (car cookie) face-remapping-alist)))
93 (when remapping
94 (let ((updated-entries (remq (cdr cookie) (cdr remapping))))
95 (unless (eq updated-entries (cdr remapping))
96 (setcdr remapping updated-entries)
97 (when (or (null updated-entries)
98 (and (eq (car-safe updated-entries) (car cookie))
99 (null (cdr updated-entries))))
100 (setq face-remapping-alist
101 (remq remapping face-remapping-alist)))
102 (cdr cookie))))))
103
104;;;### autoload
105(defun set-default-base-face-remapping (face)
106 "Set the base remapping of FACE to inherit from FACE's global definition."
107 (let ((entry (assq face face-remapping-alist)))
108 (when entry
109 ;; If there's nothing except a base remapping, we simply remove
110 ;; the entire remapping entry, as setting the base to the default
111 ;; would be the same as the global definition. Otherwise, we
112 ;; modify the base remapping.
113 (if (null (cddr entry)) ; nothing except base remapping
114 (setq face-remapping-alist ; so remove entire entry
115 (remq entry face-remapping-alist))
116 (setcar (last entry) face))))) ; otherwise, just inherit global def
117
118;;;### autoload
119(defun set-base-face-remapping (face &rest specs)
120 "Set the base remapping of FACE in the current buffer to SPECS.
121If SPECS is empty, the default base remapping is restored, which
122inherits from the global definition of FACE; note that this is
123different from SPECS containing a single value `nil', which does
124not inherit from the global definition of FACE."
125 (if (or (null specs)
126 (and (eq (car specs) face) (null (cdr specs)))) ; default
127 ;; Set entry back to default
128 (set-default-base-face-remapping face)
129 ;; Set the base remapping
130 (make-local-variable 'face-remapping-alist)
131 (let ((entry (assq face face-remapping-alist)))
132 (if entry
133 (setcar (last entry) specs) ; overwrite existing base entry
134 (push (list face specs) face-remapping-alist)))))
135
136
137;; ----------------------------------------------------------------
138;; text-scale-mode
139
140(defcustom text-scale-mode-step 1.2
141 "Scale factor used by `text-scale-mode'.
142Each positive or negative step scales the default face height by this amount."
143 :group 'display
144 :type 'number)
145
146;; current remapping cookie for text-scale-mode
147(defvar text-scale-mode-remapping nil)
148(make-variable-buffer-local 'text-scale-mode-remapping)
149
150;; Lighter displayed for text-scale-mode in mode-line minor-mode list
151(defvar text-scale-mode-lighter "+0")
152(make-variable-buffer-local 'text-scale-mode-lighter)
153
154;; Number of steps that text-scale-mode will increase/decrease text height
155(defvar text-scale-mode-amount 0)
156(make-variable-buffer-local 'text-scale-mode-amount)
157
158(define-minor-mode text-scale-mode
159 "Minor mode for displaying buffer text in a larger/smaller font than usual.
160
161The amount of scaling is determined by the variable
162`text-scale-mode-amount': one step scales the global default
163face size by the value of the variable `text-scale-mode-step' (a
164negative amount shrinks the text).
165
166The `increase-buffer-face-height' and
167`decrease-buffer-face-height' functions may be used to
168interactively modify the variable `text-scale-mode-amount' (they
169also enable or disable `text-scale-mode' as necessary."
170 :lighter (" " text-scale-mode-lighter)
171 (when text-scale-mode-remapping
172 (remove-relative-face-remapping text-scale-mode-remapping))
173 (setq text-scale-mode-lighter
174 (format (if (>= text-scale-mode-amount 0) "+%d" "%d")
175 text-scale-mode-amount))
176 (setq text-scale-mode-remapping
177 (and text-scale-mode
178 (add-relative-face-remapping 'default
179 :height
180 (expt text-scale-mode-step
181 text-scale-mode-amount))))
182 (force-window-update (current-buffer)))
183
184;;;###autoload (global-set-key [(control =)] 'increase-buffer-face-height)
185;;;###autoload (global-set-key [(control +)] 'increase-buffer-face-height)
186;;;###autoload
187(defun increase-buffer-face-height (&optional inc)
188 "Increase the height of the default face in the current buffer by INC steps.
189If the new height is other than the default, `text-scale-mode' is enabled.
190
191Each step scales the height of the default face by the variable
192`text-scale-mode-step' (a negative number of steps decreases the
193height by the same amount). As a special case, an argument of 0
194will remove any scaling currently active."
195 (interactive
196 (list
197 (cond ((eq current-prefix-arg '-) -1)
198 ((numberp current-prefix-arg) current-prefix-arg)
199 ((consp current-prefix-arg) -1)
200 (t 1))))
201 (setq text-scale-mode-amount (if (= inc 0) 0 (+ text-scale-mode-amount inc)))
202 (text-scale-mode (if (zerop text-scale-mode-amount) -1 1)))
203
204;;;###autoload (global-set-key [(control -)] 'decrease-buffer-face-height)
205;;;###autoload
206(defun decrease-buffer-face-height (&optional dec)
207 "Decrease the height of the default face in the current buffer by DEC steps.
208See `increase-buffer-face-height' for more details."
209 (interactive
210 (list
211 (cond ((eq current-prefix-arg '-) -1)
212 ((numberp current-prefix-arg) current-prefix-arg)
213 ((consp current-prefix-arg) -1)
214 (t 1))))
215 (increase-buffer-face-height (- dec)))
216
217
218;; ----------------------------------------------------------------
219;; variable-pitch-mode
220
221;; suggested key binding: (global-set-key "\C-cv" 'variable-pitch-mode)
222
223;; current remapping cookie for variable-pitch-mode
224(defvar variable-pitch-mode-remapping nil)
225(make-variable-buffer-local 'variable-pitch-mode-remapping)
226
227(define-minor-mode variable-pitch-mode
228 "Variable-pitch default-face mode. When active, causes the
229buffer text to be displayed using the `variable-pitch' face."
230 :lighter " VarPitch"
231 (when variable-pitch-mode-remapping
232 (remove-relative-face-remapping variable-pitch-mode-remapping))
233 (setq variable-pitch-mode-remapping
234 (and variable-pitch-mode
235 (add-relative-face-remapping 'default 'variable-pitch)))
236 (force-window-update (current-buffer)))
237
238
239(provide 'face-remap)
240
241;; arch-tag: 5c5f034b-8d58-4967-82bd-d61fd364e686
242;;; face-remap.el ends here