annotate lisp/utils/facemenu.el @ 163:0132846995bd r20-3b8

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