annotate lisp/utils/facemenu.el @ 70:131b0175ea99 r20-0b30

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