annotate lisp/face-remap.el @ 95532:b657ba21e4d3

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Wed, 04 Jun 2008 07:12:44 +0000
parents 0f9689c194e6
children 3a67eec377e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95515
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; face-remap.el --- Functions for managing `face-remapping-alist'
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
2 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
4 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;; Author: Miles Bader <miles@gnu.org>
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Keywords: faces face display user commands
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
7 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
9 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; (at your option) any later version.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
14 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
19 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
22 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
23
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
25
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
26 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
27 ;; This file defines some simple operations that can be used for
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;; maintaining the `face-remapping-alist' in a cooperative way. This is
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
29 ;; especially important for the `default' face.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
31 ;; Each face-remapping definition in `face-remapping-alist' added by
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 ;; this code uses the form:
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
34 ;; (face RELATIVE_SPECS_1 RELATIVE_SPECS_2 ... BASE_SPECS)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 ;; The "specs" values are a lists of face names or face attribute-value
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 ;; pairs, and are merged together, with earlier values taking precedence.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
38 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
39 ;; The RELATIVE_SPECS_* values are added by `add-relative-face-remapping'
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
40 ;; (and removed by `remove-relative-face-remapping', and are intended for
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
41 ;; face "modifications" (such as increasing the size). Typical users of
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
42 ;; relative specs would be minor modes.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
43 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
44 ;; BASE_SPECS is the lowest-priority value, and by default is just the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
45 ;; face name, which causes the global definition of that face to be used.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
46 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 ;; A non-default value of BASE_SPECS may also be set using
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
48 ;; `set-base-face-remapping'. Because this _overwrites_ the default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
49 ;; value inheriting from the global face definition, it is up to the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
50 ;; caller of set-base-face-remapping to add such inheritance if it is
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
51 ;; desired. A typical use of set-base-face-remapping would be a major
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
52 ;; mode setting face remappings, e.g., of the default face.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
53 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
54 ;; All modifications cause face-remapping-alist to be made buffer-local.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 ;;
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
56
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
57
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
58 ;;; Code:
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
59
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
60
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
61 ;; ----------------------------------------------------------------
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
62 ;; Utility functions
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
63
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
64 ;;;### autoload
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
65 (defun add-relative-face-remapping (face &rest specs)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
66 "Add a face remapping entry of FACE to SPECS in the current buffer.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
67
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
68 Return a cookie which can be used to delete the remapping with
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
69 `remove-relative-face-remapping'.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
70
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
71 SPECS can be any value suitable for the `face' text property,
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
72 including a face name, a list of face names, or a face-attribute
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
73 property list. The attributes given by SPECS will be merged with
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
74 any other currently active face remappings of FACE, and with the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 global definition of FACE, with the most recently added relative
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
76 remapping taking precedence.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
77
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
78 The base (lowest priority) remapping may be set to a specific
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
79 value, instead of the default of the global face definition,
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
80 using `set-base-face-remapping'."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
81 (make-local-variable 'face-remapping-alist)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
82 (let ((entry (assq face face-remapping-alist)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
83 (when (null entry)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
84 (setq entry (list face face)) ; explicitly merge with global def
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
85 (push entry face-remapping-alist))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
86 (setcdr entry (cons specs (cdr entry)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
87 (cons face specs)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
88
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
89 (defun remove-relative-face-remapping (cookie)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
90 "Remove a face remapping previously added by `add-relative-face-remapping'.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
91 COOKIE should be the return value from that function."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
92 (let ((remapping (assq (car cookie) face-remapping-alist)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
93 (when remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
94 (let ((updated-entries (remq (cdr cookie) (cdr remapping))))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
95 (unless (eq updated-entries (cdr remapping))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
96 (setcdr remapping updated-entries)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
97 (when (or (null updated-entries)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
98 (and (eq (car-safe updated-entries) (car cookie))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
99 (null (cdr updated-entries))))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
100 (setq face-remapping-alist
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
101 (remq remapping face-remapping-alist)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
102 (cdr cookie))))))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
103
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
104 ;;;### autoload
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 (defun set-default-base-face-remapping (face)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 "Set the base remapping of FACE to inherit from FACE's global definition."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
107 (let ((entry (assq face face-remapping-alist)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
108 (when entry
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
109 ;; If there's nothing except a base remapping, we simply remove
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 ;; the entire remapping entry, as setting the base to the default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 ;; would be the same as the global definition. Otherwise, we
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 ;; modify the base remapping.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 (if (null (cddr entry)) ; nothing except base remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
114 (setq face-remapping-alist ; so remove entire entry
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
115 (remq entry face-remapping-alist))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
116 (setcar (last entry) face))))) ; otherwise, just inherit global def
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
117
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 ;;;### autoload
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
119 (defun set-base-face-remapping (face &rest specs)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
120 "Set the base remapping of FACE in the current buffer to SPECS.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
121 If SPECS is empty, the default base remapping is restored, which
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
122 inherits from the global definition of FACE; note that this is
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 different from SPECS containing a single value `nil', which does
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
124 not inherit from the global definition of FACE."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
125 (if (or (null specs)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
126 (and (eq (car specs) face) (null (cdr specs)))) ; default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
127 ;; Set entry back to default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
128 (set-default-base-face-remapping face)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
129 ;; Set the base remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
130 (make-local-variable 'face-remapping-alist)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
131 (let ((entry (assq face face-remapping-alist)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
132 (if entry
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
133 (setcar (last entry) specs) ; overwrite existing base entry
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
134 (push (list face specs) face-remapping-alist)))))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
135
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
136
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
137 ;; ----------------------------------------------------------------
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 ;; text-scale-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
139
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
140 (defcustom text-scale-mode-step 1.2
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
141 "Scale factor used by `text-scale-mode'.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
142 Each positive or negative step scales the default face height by this amount."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
143 :group 'display
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
144 :type 'number)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
145
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
146 ;; current remapping cookie for text-scale-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
147 (defvar text-scale-mode-remapping nil)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 (make-variable-buffer-local 'text-scale-mode-remapping)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
149
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
150 ;; Lighter displayed for text-scale-mode in mode-line minor-mode list
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
151 (defvar text-scale-mode-lighter "+0")
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
152 (make-variable-buffer-local 'text-scale-mode-lighter)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
153
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 ;; Number of steps that text-scale-mode will increase/decrease text height
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
155 (defvar text-scale-mode-amount 0)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 (make-variable-buffer-local 'text-scale-mode-amount)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
157
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
158 (define-minor-mode text-scale-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
159 "Minor mode for displaying buffer text in a larger/smaller font than usual.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
160
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
161 The amount of scaling is determined by the variable
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
162 `text-scale-mode-amount': one step scales the global default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
163 face size by the value of the variable `text-scale-mode-step' (a
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
164 negative amount shrinks the text).
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
165
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
166 The `increase-buffer-face-height' and
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
167 `decrease-buffer-face-height' functions may be used to
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
168 interactively modify the variable `text-scale-mode-amount' (they
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
169 also enable or disable `text-scale-mode' as necessary."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
170 :lighter (" " text-scale-mode-lighter)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
171 (when text-scale-mode-remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
172 (remove-relative-face-remapping text-scale-mode-remapping))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
173 (setq text-scale-mode-lighter
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
174 (format (if (>= text-scale-mode-amount 0) "+%d" "%d")
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
175 text-scale-mode-amount))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
176 (setq text-scale-mode-remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
177 (and text-scale-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
178 (add-relative-face-remapping 'default
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
179 :height
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
180 (expt text-scale-mode-step
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
181 text-scale-mode-amount))))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
182 (force-window-update (current-buffer)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
183
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
184 ;;;###autoload
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
185 (defun increase-buffer-face-height (&optional inc)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
186 "Increase the height of the default face in the current buffer by INC steps.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
187 If the new height is other than the default, `text-scale-mode' is enabled.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
188
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
189 Each step scales the height of the default face by the variable
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
190 `text-scale-mode-step' (a negative number of steps decreases the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
191 height by the same amount). As a special case, an argument of 0
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
192 will remove any scaling currently active."
95527
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
193 (interactive "p")
95515
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
194 (setq text-scale-mode-amount (if (= inc 0) 0 (+ text-scale-mode-amount inc)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
195 (text-scale-mode (if (zerop text-scale-mode-amount) -1 1)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
196
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
197 ;;;###autoload
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
198 (defun decrease-buffer-face-height (&optional dec)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
199 "Decrease the height of the default face in the current buffer by DEC steps.
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
200 See `increase-buffer-face-height' for more details."
95527
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
201 (interactive "p")
95515
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
202 (increase-buffer-face-height (- dec)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
203
95527
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
204 ;;;###autoload (define-key ctl-x-map [(control ?+)] 'adjust-buffer-face-height)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
205 ;;;###autoload (define-key ctl-x-map [(control ?-)] 'adjust-buffer-face-height)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
206 ;;;###autoload (define-key ctl-x-map [(control ?=)] 'adjust-buffer-face-height)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
207 ;;;###autoload (define-key ctl-x-map [(control ?0)] 'adjust-buffer-face-height)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
208 ;;;###autoload
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
209 (defun adjust-buffer-face-height (&optional inc)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
210 "Increase or decrease the height of the default face in the current buffer.
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
211
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
212 The actual adjustment made depends on the final component of the
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
213 key-binding used to invoke the command, with all modifiers
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
214 removed:
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
215
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
216 +, = Increase the default face height by one step
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
217 - Decrease the default face height by one step
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
218 0 Reset the default face height to the global default
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
219
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
220 Then, continue to read input events and further adjust the face
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
221 height as long as the input event read (with all modifiers
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
222 removed) is one the above.
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
223
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
224 Each step scales the height of the default face by the variable
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
225 `text-scale-mode-step' (a negative number of steps decreases the
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
226 height by the same amount). As a special case, an argument of 0
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
227 will remove any scaling currently active.
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
228
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
229 This command is a special-purpose wrapper around the
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
230 `increase-buffer-face-height' command which makes repetition
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
231 convenient even when it is bound in a non-top-level keymap. For
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
232 binding in a top-level keymap, `increase-buffer-face-height' or
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
233 `decrease-default-face-height' may be more appropriate."
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
234 (interactive "p")
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
235 (let ((first t)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
236 (step t)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
237 (ev last-command-event))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
238 (while step
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
239 (let ((base (event-basic-type ev)))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
240 (cond ((or (eq base ?+) (eq base ?=))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
241 (setq step inc))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
242 ((eq base ?-)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
243 (setq step (- inc)))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
244 ((eq base ?0)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
245 (setq step 0))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
246 (first
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
247 (setq step inc))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
248 (t
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
249 (setq step nil))))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
250 (when step
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
251 (increase-buffer-face-height step)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
252 (setq inc 1 first nil)
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
253 (setq ev (read-event))))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
254 (push ev unread-command-events)))
0f9689c194e6 Add adjust-buffer-face-height command
Miles Bader <miles@gnu.org>
parents: 95515
diff changeset
255
95515
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
256
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
257 ;; ----------------------------------------------------------------
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
258 ;; variable-pitch-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
259
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
260 ;; suggested key binding: (global-set-key "\C-cv" 'variable-pitch-mode)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
261
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
262 ;; current remapping cookie for variable-pitch-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
263 (defvar variable-pitch-mode-remapping nil)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
264 (make-variable-buffer-local 'variable-pitch-mode-remapping)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
265
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
266 (define-minor-mode variable-pitch-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
267 "Variable-pitch default-face mode. When active, causes the
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
268 buffer text to be displayed using the `variable-pitch' face."
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
269 :lighter " VarPitch"
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
270 (when variable-pitch-mode-remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
271 (remove-relative-face-remapping variable-pitch-mode-remapping))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
272 (setq variable-pitch-mode-remapping
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
273 (and variable-pitch-mode
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
274 (add-relative-face-remapping 'default 'variable-pitch)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
275 (force-window-update (current-buffer)))
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
276
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
277
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
278 (provide 'face-remap)
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
279
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
280 ;; arch-tag: 5c5f034b-8d58-4967-82bd-d61fd364e686
328f63bafded Add lisp/face-remap.el and associated documentation
Miles Bader <miles@gnu.org>
parents:
diff changeset
281 ;;; face-remap.el ends here