Mercurial > emacs
annotate lisp/facemenu.el @ 9575:ff5a8ffc542c
Add support for AIX 4.1 and architecture.
author | Richard Kenner <kenner@gnu.org> |
---|---|
date | Mon, 17 Oct 1994 23:16:35 +0000 |
parents | 9a4ed505445e |
children | fe1c170fa35a |
rev | line source |
---|---|
8743 | 1 ;;; facemenu.el -- Create a face menu for interactively adding fonts to text |
2 ;; Copyright (c) 1994 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Boris Goldowsky <boris@cs.rochester.edu> | |
5 ;; Keywords: faces | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
23 ;;; Commentary: | |
24 ;; This file defines a menu of faces (bold, italic, etc) which | |
25 ;; allows you to set the face used for a region of the buffer. | |
26 ;; Some faces also have keybindings, which are shown in the menu. | |
27 | |
28 ;;; Installation: | |
29 ;; Put this file somewhere on emacs's load-path, and put | |
30 ;; (require 'facemenu) | |
31 ;; in your .emacs file. | |
32 | |
33 ;;; Usage: | |
34 ;; Selecting a face from the menu or typing the keyboard equivalent | |
35 ;; will change the region to use that face. | |
36 ;; If you use transient-mark-mode and the region is not active, the | |
37 ;; face will be remembered and used for the next insertion. It will | |
38 ;; be forgotten if you move point or make other modifications before | |
39 ;; inserting or typing anything. | |
40 ;; | |
41 ;; Faces can be selected from the keyboard as well. | |
42 ;; The standard keybindings are M-s (or ESC s) + letter: | |
43 ;; M-s i = "set italic", M-s b = "set bold", etc. | |
44 | |
45 ;;; Customization: | |
46 ;; An alternative set of keybindings that may be easier to type can be set up | |
47 ;; using "Hyper" keys. This requires that you set up a hyper-key on your | |
48 ;; keyboard. On my system, putting the following command in my .xinitrc: | |
49 ;; xmodmap -e "keysym Alt_L = Hyper_L" -e "add Mod2 = Hyper_L" | |
50 ;; makes the key labelled "Alt" act as a hyper key, but check with local | |
51 ;; X-perts for how to do it on your system. If you do this, then put the | |
52 ;; following in your .emacs before the (require 'facemenu): | |
53 ;; (setq facemenu-keybindings | |
54 ;; '((default . [?\H-d]) | |
55 ;; (bold . [?\H-b]) | |
56 ;; (italic . [?\H-i]) | |
57 ;; (bold-italic . [?\H-o]) | |
58 ;; (underline . [?\H-u]))) | |
59 ;; (setq facemenu-keymap global-map) | |
60 ;; (setq facemenu-key nil) | |
61 ;; | |
62 ;; In general, the order of the faces that appear in the menu and their | |
63 ;; keybindings can be controlled by setting the variable | |
64 ;; `facemenu-keybindings'. Faces that you never want to add to your | |
65 ;; document (e.g., `region') are listed in `facemenu-unlisted-faces'. | |
66 | |
67 ;;; Known Problems: | |
68 ;; There is at present no way to display what the faces look like in | |
69 ;; the menu itself. | |
70 ;; | |
71 ;; `list-faces-display' shows the faces in a different order than | |
72 ;; this menu, which could be confusing. I do /not/ sort the list | |
73 ;; alphabetically, because I like the default order: it puts the most | |
74 ;; basic, common fonts first. | |
75 ;; | |
76 ;; Please send me any other problems, comments or ideas. | |
77 | |
78 ;;; Code: | |
79 | |
80 (provide 'facemenu) | |
81 | |
82 (defvar facemenu-key "\M-s" | |
83 "Prefix to use for facemenu commands.") | |
84 | |
85 (defvar facemenu-keymap nil | |
86 "Map for keybindings of face commands. | |
87 If nil, `facemenu-update' will create one. | |
88 `Facemenu-update' also fills in the keymap according to the bindings | |
89 requested in facemenu-keybindings.") | |
90 | |
91 (defvar facemenu-keybindings | |
92 '((default . "d") | |
93 (bold . "b") | |
94 (italic . "i") | |
95 (bold-italic . "o") ; O for "Oblique" or "bOld"... | |
96 (underline . "u")) | |
97 "Alist of interesting faces and keybindings. | |
98 Each element is itself a list: the car is the name of the face, | |
99 the next element is the key to use as a keyboard equivalent of the menu item; | |
100 the binding is made in facemenu-keymap. | |
101 | |
102 The faces specifically mentioned in this list are put at the top of | |
103 the menu, in the order specified. All other faces which are defined, | |
104 except for those in `facemenu-unlisted-faces', are listed after them, | |
105 but get no keyboard equivalents. | |
106 | |
107 If you change this variable after loading facemenu.el, you will need to call | |
108 `facemenu-update' to make it take effect.") | |
109 | |
110 (defvar facemenu-unlisted-faces | |
111 '(modeline region secondary-selection highlight scratch-face) | |
112 "Faces that are not included in the Face menu. | |
113 Set this before loading facemenu.el, or call `facemenu-update' after | |
114 changing it.") | |
115 | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
116 (defvar facemenu-colors |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
117 (if (eq 'x window-system) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
118 (mapcar 'list (x-defined-colors))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
119 "Alist of colors, used for completion.") |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
120 |
8743 | 121 (defvar facemenu-next nil) ; set when we are going to set a face on next char. |
122 (defvar facemenu-loc nil) | |
123 | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
124 (defalias 'facemenu-foreground (make-sparse-keymap "Foreground")) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
125 (defalias 'facemenu-background (make-sparse-keymap "Background")) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
126 |
8743 | 127 (defun facemenu-update () |
128 "Add or update the \"Face\" menu in the menu bar." | |
129 (interactive) | |
130 | |
131 ;; Set up keymaps | |
132 (fset 'facemenu-menu (setq facemenu-menu (make-sparse-keymap "Face"))) | |
133 (if (null facemenu-keymap) | |
134 (fset 'facemenu-keymap | |
135 (setq facemenu-keymap (make-sparse-keymap "Set face")))) | |
136 (if facemenu-key | |
137 (define-key global-map facemenu-key facemenu-keymap)) | |
138 | |
139 ;; Define basic keys | |
8747
d7115dce85f9
(facemenu-update): Don't use quoted constant lists
Richard M. Stallman <rms@gnu.org>
parents:
8743
diff
changeset
|
140 ;; We construct this list structure explicitly because a quoted constant |
d7115dce85f9
(facemenu-update): Don't use quoted constant lists
Richard M. Stallman <rms@gnu.org>
parents:
8743
diff
changeset
|
141 ;; would be pure. |
8850
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
142 (define-key facemenu-menu [update] (cons "Update Menu" 'facemenu-update)) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
143 (define-key facemenu-menu [display] (cons "Display Faces" |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
144 'list-faces-display)) |
8850
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
145 (define-key facemenu-menu [sep1] (list "-------------")) |
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
146 (define-key facemenu-menu [remove] (cons "Remove Properties" |
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
147 'facemenu-remove-all)) |
8747
d7115dce85f9
(facemenu-update): Don't use quoted constant lists
Richard M. Stallman <rms@gnu.org>
parents:
8743
diff
changeset
|
148 (define-key facemenu-menu [read-only] (cons "Read-Only" |
d7115dce85f9
(facemenu-update): Don't use quoted constant lists
Richard M. Stallman <rms@gnu.org>
parents:
8743
diff
changeset
|
149 'facemenu-set-read-only)) |
8850
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
150 (define-key facemenu-menu [invisible] (cons "Invisible" |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
151 'facemenu-set-invisible)) |
8953
231a4d114799
(facemenu-update): Make menu separators all dashes.
Richard M. Stallman <rms@gnu.org>
parents:
8850
diff
changeset
|
152 (define-key facemenu-menu [sep2] (list "-------------")) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
153 (define-key facemenu-menu [bg] (cons "Background Color" |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
154 'facemenu-background)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
155 (define-key facemenu-menu [fg] (cons "Foreground Color" |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
156 'facemenu-foreground)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
157 (define-key facemenu-menu [sep3] (list "-------------")) |
8850
90773ae84a4f
(facemenu-update): Reverse the menu order again.
Richard M. Stallman <rms@gnu.org>
parents:
8747
diff
changeset
|
158 (define-key facemenu-menu [other] (cons "Other..." 'facemenu-set-face)) |
8743 | 159 |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
160 (define-key 'facemenu-foreground "o" (cons "Other" 'facemenu-set-foreground)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
161 (define-key 'facemenu-background "o" (cons "Other" 'facemenu-set-background)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
162 |
8743 | 163 ;; Define commands for face-changing |
164 (facemenu-iterate | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
165 (lambda (f) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
166 (let* ((face (car f)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
167 (name (symbol-name face)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
168 (key (cdr f)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
169 (menu (cond ((string-match "^fg:" name) 'facemenu-foreground) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
170 ((string-match "^bg:" name) 'facemenu-background) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
171 (t facemenu-menu)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
172 (if (memq menu '(facemenu-foreground facemenu-background)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
173 (setq name (substring name 3))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
174 (cond ((memq face facemenu-unlisted-faces) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
175 nil) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
176 ((null key) (define-key menu (vector face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
177 (cons name 'facemenu-set-face-from-menu))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
178 (t (let ((function (intern (concat "facemenu-set-" name)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
179 (fset function |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
180 (` (lambda () (interactive) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
181 (facemenu-set-face (quote (, face)))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
182 (define-key facemenu-keymap key (cons name function)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
183 (define-key menu key (cons name function)))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
184 nil) |
8743 | 185 (facemenu-complete-face-list facemenu-keybindings)) |
186 | |
187 (define-key global-map (vector 'menu-bar 'Face) | |
188 (cons "Face" facemenu-menu))) | |
189 | |
190 ; We'd really like to name the menu items as follows, | |
191 ; but we can't since menu entries don't display text properties (yet?) | |
192 ; (let ((s (copy-sequence (symbol-name face)))) | |
193 ; (put-text-property 0 (1- (length s)) | |
194 ; 'face face s) | |
195 ; s) | |
196 | |
197 ;;;###autoload | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
198 (defun facemenu-read-color (prompt) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
199 "Read a color using the minibuffer." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
200 (let ((col (completing-read (or "Color: ") facemenu-colors nil t))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
201 (if (equal "" col) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
202 nil |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
203 col))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
204 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
205 ;;;###autoload |
8743 | 206 (defun facemenu-set-face (face &optional start end) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
207 "Add FACE to the region or next character typed. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
208 It will be added to the top of the face list; any faces lower on the list that |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
209 will not show through at all will be removed. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
210 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
211 Interactively, the face to be used is prompted for. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
212 If the region is active, it will be set to the requested face. If |
8743 | 213 it is inactive \(even if mark-even-if-inactive is set) the next |
214 character that is typed \(via `self-insert-command') will be set to | |
215 the the selected face. Moving point or switching buffers before | |
216 typing a character cancels the request." | |
217 (interactive (list (read-face-name "Use face: "))) | |
218 (if mark-active | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
219 (let ((start (or start (region-beginning))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
220 (end (or end (region-end)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
221 (facemenu-add-face face start end)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
222 (setq facemenu-next face |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
223 facemenu-loc (point)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
224 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
225 (defun facemenu-set-foreground (color &optional start end) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
226 "Set the foreground color of the region or next character typed. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
227 The color is prompted for. A face named `fg:color' is used \(or created). |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
228 If the region is active, it will be set to the requested face. If |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
229 it is inactive \(even if mark-even-if-inactive is set) the next |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
230 character that is typed \(via `self-insert-command') will be set to |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
231 the the selected face. Moving point or switching buffers before |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
232 typing a character cancels the request." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
233 (interactive (list (facemenu-read-color "Foreground color: "))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
234 (let ((face (intern (concat "fg:" color)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
235 (or (facemenu-get-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
236 (error "Unknown color: %s" color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
237 (facemenu-set-face face start end))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
238 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
239 (defun facemenu-set-background (color &optional start end) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
240 "Set the background color of the region or next character typed. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
241 The color is prompted for. A face named `bg:color' is used \(or created). |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
242 If the region is active, it will be set to the requested face. If |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
243 it is inactive \(even if mark-even-if-inactive is set) the next |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
244 character that is typed \(via `self-insert-command') will be set to |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
245 the the selected face. Moving point or switching buffers before |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
246 typing a character cancels the request." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
247 (interactive (list (facemenu-read-color "Background color: "))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
248 (let ((face (intern (concat "bg:" color)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
249 (or (facemenu-get-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
250 (error "Unknown color: %s" color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
251 (facemenu-set-face face start end))) |
8743 | 252 |
253 (defun facemenu-set-face-from-menu (face start end) | |
254 "Set the face of the region or next character typed. | |
255 This function is designed to be called from a menu; the face to use | |
256 is the menu item's name. | |
257 If the region is active, it will be set to the requested face. If | |
258 it is inactive \(even if mark-even-if-inactive is set) the next | |
259 character that is typed \(via `self-insert-command') will be set to | |
260 the the selected face. Moving point or switching buffers before | |
261 typing a character cancels the request." | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
262 (interactive (list last-command-event |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
263 (if mark-active (region-beginning)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
264 (if mark-active (region-end)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
265 (facemenu-get-face face) |
8743 | 266 (if start |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
267 (facemenu-add-face face start end) |
8743 | 268 (setq facemenu-next face facemenu-loc (point)))) |
269 | |
270 (defun facemenu-set-invisible (start end) | |
271 "Make the region invisible. | |
272 This sets the `invisible' text property; it can be undone with | |
273 `facemenu-remove-all'." | |
274 (interactive "r") | |
275 (put-text-property start end 'invisible t)) | |
276 | |
277 (defun facemenu-set-intangible (start end) | |
278 "Make the region intangible: disallow moving into it. | |
279 This sets the `intangible' text property; it can be undone with | |
280 `facemenu-remove-all'." | |
281 (interactive "r") | |
282 (put-text-property start end 'intangible t)) | |
283 | |
284 (defun facemenu-set-read-only (start end) | |
285 "Make the region unmodifiable. | |
286 This sets the `read-only' text property; it can be undone with | |
287 `facemenu-remove-all'." | |
288 (interactive "r") | |
289 (put-text-property start end 'read-only t)) | |
290 | |
291 (defun facemenu-remove-all (start end) | |
292 "Remove all text properties that facemenu added to region." | |
293 (interactive "*r") ; error if buffer is read-only despite the next line. | |
294 (let ((inhibit-read-only t)) | |
295 (remove-text-properties | |
296 start end '(face nil invisible nil intangible nil | |
297 read-only nil category nil)))) | |
298 | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
299 (defun facemenu-get-face (face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
300 "Make sure FACE exists. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
301 If not, it is created. If it is created and is of the form `fg:color', then |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
302 set the foreground to that color. If of the form `bg:color', set the |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
303 background. In any case, add it to the appropriate menu. Returns nil if |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
304 given a bad color." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
305 (if (internal-find-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
306 t |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
307 (make-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
308 (let* ((name (symbol-name face)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
309 (color (substring name 3))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
310 (cond ((string-match "^fg:" name) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
311 (set-face-foreground face color) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
312 (define-key 'facemenu-foreground (vector face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
313 (cons color 'facemenu-set-face-from-menu)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
314 (x-color-defined-p color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
315 ((string-match "^bg:" name) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
316 (set-face-background face color) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
317 (define-key 'facemenu-background (vector face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
318 (cons color 'facemenu-set-face-from-menu)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
319 (x-color-defined-p color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
320 (t |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
321 (define-key facemenu-menu (vector face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
322 (cons name 'facemenu-set-face-from-menu)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
323 t))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
324 |
8743 | 325 (defun facemenu-after-change (begin end old-length) |
326 "May set the face of just-inserted text to user's request. | |
327 This only happens if the change is an insertion, and | |
328 `facemenu-set-face[-from-menu]' was called with point at the | |
329 beginning of the insertion." | |
330 (if (null facemenu-next) ; exit immediately if no work | |
331 nil | |
332 (if (and (= 0 old-length) ; insertion | |
333 (= facemenu-loc begin)) ; point wasn't moved in between | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
334 (facemenu-add-face facemenu-next begin end)) |
8743 | 335 (setq facemenu-next nil))) |
336 | |
337 (defun facemenu-complete-face-list (&optional oldlist) | |
338 "Return alist of all faces that are look different. | |
339 Starts with given LIST of faces, and adds elements only if they display | |
340 differently from any face already on the list. | |
341 The original LIST will end up at the end of the returned list, in reverse | |
342 order. The elements added will have null cdrs." | |
343 (let ((list nil)) | |
344 (facemenu-iterate | |
345 (function | |
346 (lambda (item) | |
347 (if (internal-find-face (car item)) | |
348 (setq list (cons item list))) | |
349 nil)) | |
350 oldlist) | |
351 (facemenu-iterate | |
352 (function | |
353 (lambda (new-face) | |
354 (if (not (facemenu-iterate | |
355 (function | |
356 (lambda (item) (face-equal (car item) new-face t))) | |
357 list)) | |
358 (setq list (cons (cons new-face nil) list))) | |
359 nil)) | |
360 (nreverse (face-list))) | |
361 list)) | |
362 | |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
363 (defun facemenu-add-face (face start end) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
364 "Add FACE to text between START and END. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
365 For each section of that region that has a different face property, FACE will |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
366 be consed onto it, and other faces that are completely hidden by that will be |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
367 removed from the list." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
368 (interactive "*xFace:\nr") |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
369 (let ((part-start start) part-end) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
370 (while (not (= part-start end)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
371 (setq part-end (next-single-property-change part-start 'face nil end)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
372 (let ((prev (get-text-property part-start 'face))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
373 (put-text-property part-start part-end 'face |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
374 (if (null prev) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
375 face |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
376 (facemenu-discard-redundant-faces |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
377 (cons face |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
378 (if (listp prev) prev (list prev))))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
379 (setq part-start part-end)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
380 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
381 (defun facemenu-discard-redundant-faces (face-list &optional mask) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
382 "Remove from FACE-LIST any faces that won't show at all. |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
383 This means they have no non-nil elements that aren't also non-nil in an |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
384 earlier face." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
385 (let ((useful nil)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
386 (cond ((null face-list) nil) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
387 ((null mask) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
388 (cons (car face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
389 (facemenu-discard-redundant-faces |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
390 (cdr face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
391 (copy-sequence (internal-get-face (car face-list)))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
392 ((let ((i (length mask)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
393 (face (internal-get-face (car face-list)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
394 (while (>= (setq i (1- i)) 0) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
395 (if (and (aref face i) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
396 (not (aref mask i))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
397 (progn (setq useful t) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
398 (aset mask i t)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
399 useful) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
400 (cons (car face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
401 (facemenu-discard-redundant-faces (cdr face-list) mask))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
402 (t (facemenu-discard-redundant-faces (cdr face-list) mask))))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
403 |
8743 | 404 (defun facemenu-iterate (func iterate-list) |
405 "Apply FUNC to each element of LIST until one returns non-nil. | |
406 Returns the non-nil value it found, or nil if all were nil." | |
407 (while (and iterate-list (not (funcall func (car iterate-list)))) | |
408 (setq iterate-list (cdr iterate-list))) | |
409 (car iterate-list)) | |
410 | |
411 (facemenu-update) | |
412 (add-hook 'menu-bar-final-items 'Face) | |
413 (add-hook 'after-change-functions 'facemenu-after-change) | |
414 | |
415 ;;; facemenu.el ends here |