annotate lisp/utils/facemenu.el @ 78:c7528f8e288d r20-0b34

Import from CVS: tag r20-0b34
author cvs
date Mon, 13 Aug 2007 09:05:42 +0200
parents 131b0175ea99
children 4be1180a9e89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; facemenu.el --- create a face menu for interactively adding fonts to text
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
2 ;; Copyright (c) 1994, 1995 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; XEmacs version: Mike Sperber <sperber@informatik.uni-tuebingen.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Original author: Boris Goldowsky <boris@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
18 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 70
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
25 ;;; Synched up with: FSF 19.30.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; This file defines a menu of faces (bold, italic, etc) which allows you to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; set the face used for a region of the buffer. Some faces also have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; keybindings, which are shown in the menu. Faces with names beginning with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; "fg:" or "bg:", as in "fg:red", are treated specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; Such faces are assumed to consist only of a foreground (if "fg:") or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; background (if "bg:") color. They are thus put into the color submenus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; rather than the general Face submenu. These faces can also be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; automatically created by selecting the "Other..." menu items in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; "Foreground" and "Background" submenus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; The menu also contains submenus for indentation and justification-changing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
41 ;;; Installation:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
42 ;; Just do a (require 'facemenu).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
43 ;; If you want the menu bound to a mouse button under XEmacs, do
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
44 ;; (define-key global-map '(control button2) 'facemenu-menu)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
45
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; Selecting a face from the menu or typing the keyboard equivalent will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; change the region to use that face. If you use transient-mark-mode and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; region is not active, the face will be remembered and used for the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; insertion. It will be forgotten if you move point or make other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; modifications before inserting or typing anything.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Faces can be selected from the keyboard as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; The standard keybindings are M-g (or ESC g) + letter:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; M-g i = "set italic", M-g b = "set bold", etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; The order of the faces that appear in the menu and their keybindings can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; controlled by setting the variables `facemenu-keybindings' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; `facemenu-new-faces-at-end'. List faces that you don't use in documents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; (eg, `region') in `facemenu-unlisted-faces'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Known Problems:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; Bold and Italic do not combine to create bold-italic if you select them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; both, although most other combinations (eg bold + underline + some color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; do the intuitive thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; There is at present no way to display what the faces look like in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; the menu itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; `list-faces-display' shows the faces in a different order than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; this menu, which could be confusing. I do /not/ sort the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; alphabetically, because I like the default order: it puts the most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; basic, common fonts first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Please send me any other problems, comments or ideas.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (provide 'facemenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (require 'easymenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; Provide some binding for startup:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; XEmacs -- goto-line is a *much* better binding for M-g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;;dont ###autoload (define-key global-map "\M-g" 'facemenu-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defvar facemenu-key "\M-g"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Prefix key to use for facemenu commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar facemenu-keybindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 '((default . "d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (bold . "b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (italic . "i")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (bold-italic . "l") ; {bold} intersect {italic} = {l}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (underline . "u"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "Alist of interesting faces and keybindings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 Each element is itself a list: the car is the name of the face,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 the next element is the key to use as a keyboard equivalent of the menu item;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 the binding is made in facemenu-keymap.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 The faces specifically mentioned in this list are put at the top of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 the menu, in the order specified. All other faces which are defined,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 except for those in `facemenu-unlisted-faces', are listed after them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 but get no keyboard equivalents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 If you change this variable after loading facemenu.el, you will need to call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 `facemenu-update' to make it take effect.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (defvar facemenu-new-faces-at-end t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 "Where in the menu to insert newly-created faces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 This should be nil to put them at the top of the menu, or t to put them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 just before \"Other\" at the end.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvar facemenu-unlisted-faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 '(modeline region secondary-selection highlight scratch-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 gui-button-face isearch hyperlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 modeline modeline-buffer-id modeline-mousable modeline-mousable-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 pointer primary-selection secondary-selection list-mode-item-selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 text-cursor zmacs-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 left-margin right-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 "List of faces not to include in the Face menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 You can set this list before loading facemenu.el, or add a face to it before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 creating that face if you do not want it to be listed. If you change the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 variable so as to eliminate faces that have already been added to the menu,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 call `facemenu-update' to recalculate the menu contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 If this variable is t, no faces will be added to the menu. This is useful for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 temporarily turning off the feature that automatically adds faces to the menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 when they are created.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defvar facemenu-relevant-face-attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 '(foreground background font underline highlight dim blinking reverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 "List of face attributes that facemenu fiddles with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 This is only relevant for XEmacs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (easy-menu-define facemenu-face-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 "Menu for faces"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 `("Face"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ["Other..." facemenu-set-face t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (easy-menu-define facemenu-foreground-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "Menu for foreground colors"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 `("Foreground Color"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ["Other..." facemenu-set-foreground t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (easy-menu-define facemenu-background-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Menu for background colors"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 `("Background Color"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ["Other..." facemenu-set-background t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (easy-menu-define facemenu-size-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "Menu for font sizes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 '("Size"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ["Default" facemenu-set-size-default t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ["Bigger" facemenu-make-larger t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ["Smaller" facemenu-make-smaller t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ["Much Bigger" facemenu-make-much-larger t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ["Much Smaller" facemenu-make-much-smaller t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (easy-menu-define facemenu-special-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Menu for non-face text-properties."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 '("Special"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ["Read-Only" facemenu-set-read-only t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ["Invisible" facemenu-set-invisible t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ["Intangible" facemenu-set-intangible t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ["Remove Special" facemenu-remove-special t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (easy-menu-define facemenu-justification-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "Menu for text justification commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 '("Justification"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ["Center" set-justification-center t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ["Full" set-justification-full t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ["Right" set-justification-right t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ["Unfilled" set-justification-none t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (easy-menu-define facemenu-indentation-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Submenu for indentation commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 '("Indentation"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ["Indent More" increase-left-margin t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ["Indent Less" decrease-left-margin t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ["Indent Right More" increase-right-margin t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ["Indent Right Less" decrease-right-margin t]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defvar facemenu-menu nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "Facemenu top-level menu keymap.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defun facemenu-update-facemenu-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (easy-menu-define facemenu-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Facemenu top-level menu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (list "Text Properties"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 facemenu-face-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 facemenu-foreground-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 facemenu-background-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 facemenu-size-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 facemenu-special-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 "---"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 facemenu-justification-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 facemenu-indentation-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "---"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ["Remove Properties" facemenu-remove-props t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ["List Properties" list-text-properties-at t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ["Display Faces" list-faces-display t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ["Display Colors" list-colors-display t])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defvar facemenu-keymap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let ((map (make-sparse-keymap "Set face")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (define-key map ?o 'facemenu-set-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "Keymap for face-changing commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 `Facemenu-update' fills in the keymap according to the bindings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 requested in `facemenu-keybindings'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (defalias 'facemenu-keymap facemenu-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;;; Internal Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defvar facemenu-color-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;; Don't initialize here; that doesn't work if preloaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "Alist of colors, used for completion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 If null, `facemenu-read-color' will set it.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (defun facemenu-update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 "Add or update the \"Face\" menu in the menu bar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 You can call this to update things if you change any of the menu configuration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 variables."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; Add each defined face to the menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (facemenu-iterate 'facemenu-add-new-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (facemenu-complete-face-list facemenu-keybindings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (facemenu-update-facemenu-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; Global bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (easy-menu-change '("Edit") (car facemenu-menu) (cdr facemenu-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (define-key global-map [C-down-mouse-2] 'facemenu-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (if facemenu-key (define-key global-map facemenu-key 'facemenu-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (fset 'facemenu-region-active-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 'region-active-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 mark-active)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (defun facemenu-set-face (face &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "Add FACE to the region or next character typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 It will be added to the top of the face list; any faces lower on the list that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 will not show through at all will be removed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 Interactively, the face to be used is read with the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 If the region is active and there is no prefix argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 this command sets the region to the requested face.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 Otherwise, this command specifies the face for the next character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 inserted. Moving point or switching buffers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 typing a character to insert cancels the specification."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (interactive (list (read-face-name "Use face: ")))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
263 (setq zmacs-region-stays t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (barf-if-buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (facemenu-add-new-face face)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
266 (facemenu-update-facemenu-menu)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (if (and (facemenu-region-active-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (not current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (let ((start (or start (region-beginning)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (end (or end (region-end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (facemenu-add-face face start end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (facemenu-self-insert-face face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defun facemenu-set-foreground (color &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "Set the foreground color of the region or next character typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 The color is prompted for. A face named `fg:color' is used \(or created).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 If the region is active, it will be set to the requested face. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 it is inactive \(even if mark-even-if-inactive is set) the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 character that is typed \(via `self-insert-command') will be set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 the selected face. Moving point or switching buffers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 typing a character cancels the request."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (interactive (list (facemenu-read-color "Foreground color: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let ((face (intern (concat "fg:" color))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (or (facemenu-get-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (error "Unknown color: %s" color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (facemenu-set-face face start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun facemenu-set-background (color &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "Set the background color of the region or next character typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 The color is prompted for. A face named `bg:color' is used \(or created).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 If the region is active, it will be set to the requested face. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 it is inactive \(even if mark-even-if-inactive is set) the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 character that is typed \(via `self-insert-command') will be set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 the selected face. Moving point or switching buffers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 typing a character cancels the request."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (interactive (list (facemenu-read-color "Background color: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (let ((face (intern (concat "bg:" color))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (or (facemenu-get-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (error "Unknown color: %s" color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (facemenu-set-face face start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;;;###autoload
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
307 (defun facemenu-set-face-from-menu (face)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "Set the face of the region or next character typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 This function is designed to be called from a menu; the face to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 is the menu item's name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 If the region is active and there is no prefix argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 this command sets the region to the requested face.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Otherwise, this command specifies the face for the next character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 inserted. Moving point or switching buffers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 typing a character to insert cancels the specification."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
318 (let ((start (if (and (facemenu-region-active-p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
319 (not current-prefix-arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
320 (region-beginning)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
321 (end (if (and (facemenu-region-active-p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
322 (not current-prefix-arg))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
323 (region-end))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
324 (barf-if-buffer-read-only)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
325 (setq zmacs-region-stays t)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
326 (facemenu-get-face face)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
327 (if start
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
328 (facemenu-add-face face start end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
329 (facemenu-self-insert-face face))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (defun facemenu-self-insert-face (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq self-insert-face (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ((null self-insert-face) face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ((consp self-insert-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (facemenu-active-faces (cons face self-insert-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (facemenu-active-faces (list face self-insert-face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 self-insert-face-command this-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (defun facemenu-face-strip-size (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 "Create a symbol from the name of FACE devoid of size information,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 i.e. remove all larger- and smaller- prefixes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (let* ((face-symbol (face-name face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (face-name (symbol-name face-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (old-name face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (not (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 old-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq new-name (replace-in-string old-name "^larger-" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq old-name new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (not (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 old-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (setq new-name (replace-in-string old-name "^smaller-" ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq old-name new-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if (string-equal new-name face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 face-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (intern new-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (defun facemenu-face-default-size (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (cond ((null face) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ((consp face) (mapcar 'facemenu-face-strip-size face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (t (facemenu-face-strip-size face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defun facemenu-set-size-default (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (interactive "_r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (put-text-property start end 'size nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (alter-text-property start end 'face 'facemenu-face-default-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun facemenu-ensure-size-property (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 "Ensure that the text between START and END has a 'size text property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 If it is not present, it is set to 0."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (let ((start start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 pos bound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (while (setq pos (text-property-any start end 'size nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq bound (or (text-property-not-all pos end 'size nil) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (put-text-property pos bound 'size 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun facemenu-sized-face (face size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Make a face FACE larger or smaller according to SIZE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 If SIZE is positive, it calls `make-face-larger' SIZE times,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 else it calls `make-face-smaller' -SIZE times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (if (zerop size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let ((name (symbol-name face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (measure size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (change-face 'make-face-larger))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (if (> measure 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (setq prefix "larger-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq prefix "smaller-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (setq measure (- measure))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq size (- size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq change-face 'make-face-smaller))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (while (not (zerop measure))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (setq name (concat prefix name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq measure (1- measure)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (let ((symbol (intern name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (or (find-face symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (let ((face (copy-face face symbol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (while (not (zerop size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (funcall change-face face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (setq size (1- size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 face))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defun facemenu-adjust-face-sizes (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ((null face) (facemenu-sized-face 'default size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ((consp face) (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 #'(lambda (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (facemenu-sized-face (facemenu-face-strip-size face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 face))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
420 (t (facemenu-sized-face face size))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (defun facemenu-adjust-size (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 "Adjust the size of the text between FROM and TO according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 to the values of the 'size property in that region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (let ((pos from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 bound size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (while (< pos to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (setq size (get-text-property pos 'size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq bound (or (text-property-not-all pos to 'size size) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (alter-text-property pos bound 'face 'facemenu-adjust-face-sizes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (setq pos bound))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (defun facemenu-change-size (from to f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (facemenu-ensure-size-property from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (alter-text-property from to 'size f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (facemenu-adjust-size from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defun facemenu-make-larger (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (interactive "_r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (facemenu-change-size from to '1+))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun facemenu-make-smaller (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (interactive "_r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (facemenu-change-size from to '1-))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defun facemenu-make-much-larger (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (interactive "_r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (facemenu-change-size from to #'(lambda (s) (+ 5 s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defun facemenu-make-much-smaller (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (interactive "_r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (facemenu-change-size from to #'(lambda (s) (- s 5))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (defun facemenu-set-invisible (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 "Make the region invisible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 This sets the `invisible' text property; it can be undone with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 `facemenu-remove-special'."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
463 (interactive "r")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (put-text-property start end 'invisible t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun facemenu-set-intangible (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Make the region intangible: disallow moving into it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 This sets the `intangible' text property; it can be undone with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 `facemenu-remove-special'."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
471 (interactive "r")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (put-text-property start end 'intangible t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (defun facemenu-set-read-only (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "Make the region unmodifiable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 This sets the `read-only' text property; it can be undone with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 `facemenu-remove-special'."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
479 (interactive "r")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (put-text-property start end 'read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (defun facemenu-remove-props (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 "Remove all text properties that facemenu added to region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (interactive "*_r") ; error if buffer is read-only despite the next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (remove-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 start end '(face nil invisible nil intangible nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 read-only nil category nil size nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (defun facemenu-remove-special (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 "Remove all the \"special\" text properties from the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 These special properties include `invisible', `intangible' and `read-only'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (interactive "*_r") ; error if buffer is read-only despite the next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (remove-text-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 start end '(invisible nil intangible nil read-only nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defun list-text-properties-at (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "Pop up a buffer listing text-properties at LOCATION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (interactive "d")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
504 (let ((props (text-properties-at p)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (if (null props)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (message "None")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
507 (with-output-to-temp-buffer "*Text Properties*"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
508 (princ (format "Text properties at %d:\n\n" p))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
509 (while props
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
510 (princ (format "%-20s %S\n"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
511 (car props) (car (cdr props))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
512 (setq props (cdr (cdr props))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (defun facemenu-read-color (&optional prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 "Read a color using the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (read-color prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (let ((col (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (or prompt "Color: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (or facemenu-color-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (if (or (eq window-system 'x) (eq window-system 'win32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (mapcar 'list (x-defined-colors))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (if (equal "" col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 col))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (defun facemenu-canonicalize-color (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (downcase (replace-in-string c " " "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defun facemenu-unique (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 "Uniquify LIST, deleting elements using `delete'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 Return the list with subsequent duplicate items removed by side effects."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (let ((list list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (setq list (setcdr list (delete (car list) (cdr list))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (defun list-colors-display (&optional list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 "Display names of defined colors, and show what they look like.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 If the optional argument LIST is non-nil, it should be a list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 colors to display. Otherwise, this command computes a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 of colors that the current display can handle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (setq list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (facemenu-unique
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (mapcar 'facemenu-canonicalize-color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (mapcar 'car (read-color-completion-table)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (if (and (null list) (or (eq window-system 'x) (eq window-system 'win32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (setq list (x-defined-colors))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; Delete duplicate colors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (let ((l list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (while (cdr l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (if (facemenu-color-equal (car l) (car (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (setcdr l (cdr (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (setq l (cdr l))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (with-output-to-temp-buffer "*Colors*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (let ((facemenu-unlisted-faces t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (if (not (string-match "[0-9]" (car list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (setq s (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (insert (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (indent-to 20)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (put-text-property s (point) 'face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (facemenu-get-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (intern (concat "bg:" (car list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (setq s (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (insert " " (car list) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (put-text-property s (point) 'face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (facemenu-get-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (intern (concat "fg:" (car list)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq list (cdr list)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (fset 'facemenu-color-values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (if (fboundp 'x-color-values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 'x-color-values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 #'(lambda (color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (color-instance-rgb-components
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (make-color-instance color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (defun facemenu-color-equal (a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 "Return t if colors A and B are the same color.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 A and B should be strings naming colors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 This function queries the window-system server to find out what the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 color names mean. It returns nil if the colors differ or if it can't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 determine the correct answer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (cond ((equal a b) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ((and (equal (facemenu-color-values a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (facemenu-color-values b))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
599 (defun facemenu-add-face (face start end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "Add FACE to text between START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 For each section of that region that has a different face property, FACE will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 be consed onto it, and other faces that are completely hidden by that will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 removed from the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 As a special case, if FACE is `default', then the region is left with NO face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 text property. Otherwise, selecting the default face would not have any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 effect."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (interactive "*_xFace:\nr")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
609 (if (eq face 'default)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
610 (remove-text-properties start end '(face default))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
611 (let ((part-start start) part-end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
612 (while (not (= part-start end))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
613 (setq part-end (next-single-property-change part-start 'face nil end))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
614 (let* ((prev (get-text-property part-start 'face))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
615 (size (get-text-property part-start 'size))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
616 (face (if size (facemenu-sized-face face size) face)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
617 (put-text-property part-start part-end 'face
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
618 (if (null prev)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
619 face
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
620 (facemenu-active-faces
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
621 (cons face
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
622 (if (listp prev) prev (list prev)))))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 24
diff changeset
623 (setq part-start part-end)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (defun facemenu-face-attributes (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "Create a vector of the relevant face attributes of face FACE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (apply 'vector (mapcar #'(lambda (prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (face-property-instance face prop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 facemenu-relevant-face-attributes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (internal-get-face (car face-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (defun facemenu-active-faces (face-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 "Return from FACE-LIST those faces that would be used for display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 This means each face attribute is not specified in a face earlier in FACE-LIST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 and such a face is therefore active when used to display text."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (let* ((mask-atts (copy-sequence (facemenu-face-attributes (car face-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (default-atts (facemenu-face-attributes 'default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (active-list (list (car face-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (face-list (cdr face-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (mask-len (length mask-atts)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (while face-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (if (let ((face-atts (facemenu-face-attributes (car face-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (i mask-len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (useful nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (while (>= (setq i (1- i)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (and (aref face-atts i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (or (not (aref mask-atts i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (eq (aref mask-atts i) (aref default-atts i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (not (eq (aref face-atts i) (aref default-atts i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (aset mask-atts i (setq useful t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 useful)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (setq active-list (cons (car face-list) active-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (setq face-list (cdr face-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (nreverse active-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (fset 'facemenu-find-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 'find-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 'internal-find-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (fset 'facemenu-color-defined-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 #'(lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (color-instance-p (make-color-instance c nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 #'(lambda (c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (and (or (eq window-system 'x) (eq window-system 'win32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (x-color-defined-p color)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (defun facemenu-get-face (symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 "Make sure FACE exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 If not, it is created. If it is created and is of the form `fg:color', then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 set the foreground to that color. If of the form `bg:color', set the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 background. In any case, add it to the appropriate menu. Returns the face,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 or nil if given a bad color."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (if (or (facemenu-find-face symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (let* ((face (make-face symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (name (symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (color-name (substring name 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (color (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (make-color-specifier color-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 color-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (facemenu-add-new-face symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (cond ((string-match "^fg:" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (set-face-foreground face color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (facemenu-color-defined-p color-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ((string-match "^bg:" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (set-face-background face color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (facemenu-color-defined-p color-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (defun facemenu-menu-has-face (menu face-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 "Check if menu MENU has an entry for face named by string FACE-NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 Returns entry if successful."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (facemenu-iterate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 #'(lambda (m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (and (vectorp m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (string-equal face-name (aref m 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (cdr menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (defun facemenu-insert-menu-entry (menu before-entry name function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 "Insert menu item with name NAME and associated function FUNCTION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 into menu MENU before entry BEFORE-ENTRY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (while (not (eq (cadr menu) before-entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (setq menu (cdr menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (setcdr menu (cons (vector name function t) (cdr menu))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (defun facemenu-add-new-face (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 "Add a FACE to the appropriate Face menu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 Automatically called when a new face is created."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (let* ((name (symbol-name face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (menu (cond ((string-match "^fg:" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (setq name (substring name 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 'facemenu-foreground-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ((string-match "^bg:" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq name (substring name 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 'facemenu-background-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (t 'facemenu-face-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (menu-value (symbol-value menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (key (cdr (assoc face facemenu-keybindings))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (cond ((eq t facemenu-unlisted-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ((string-match "^larger-" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ((string-match "^smaller-" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ((memq face facemenu-unlisted-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (key ; has a keyboard equivalent. These go at the front.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (let ((function (intern (concat "facemenu-set-" name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (fset function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (` (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (facemenu-set-face (quote (, face))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (define-key 'facemenu-keymap key function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (if (not (facemenu-menu-has-face menu-value name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (set menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (cons (car menu-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cons (vector name function t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (cdr menu-value)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ((facemenu-menu-has-face menu-value name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (t ; No keyboard equivalent. Figure out where to put it:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (let ((before-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (or (and facemenu-new-faces-at-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (facemenu-menu-has-face menu-value "Other..."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (cadr menu-value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (facemenu-insert-menu-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 menu-value before-entry name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (` (facemenu-set-face (quote (, face)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 nil) ; Return nil for facemenu-iterate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun facemenu-complete-face-list (&optional oldlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Return list of all faces that look different.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 Starts with given ALIST of faces, and adds elements only if they display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 differently from any face already on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 The faces on ALIST will end up at the end of the returned list, in reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 order."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (let ((list (nreverse (mapcar 'car oldlist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (facemenu-iterate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (lambda (new-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (if (not (memq new-face list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (setq list (cons new-face list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (nreverse (face-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (defun facemenu-iterate (func iterate-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 "Apply FUNC to each element of LIST until one returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 Returns the non-nil value it found, or nil if all were nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (while (and iterate-list (not (funcall func (car iterate-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (setq iterate-list (cdr iterate-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (car iterate-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (facemenu-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;;; facemenu.el ends here