annotate lisp/utils/facemenu.el @ 209:41ff10fd062f r20-4b3

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