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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8743
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; facemenu.el -- Create a face menu for interactively adding fonts to text
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (c) 1994 Free Software Foundation, Inc.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Author: Boris Goldowsky <boris@cs.rochester.edu>
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Keywords: faces
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; This file defines a menu of faces (bold, italic, etc) which
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; allows you to set the face used for a region of the buffer.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; Some faces also have keybindings, which are shown in the menu.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; Installation:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Put this file somewhere on emacs's load-path, and put
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; (require 'facemenu)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; in your .emacs file.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Usage:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;; Selecting a face from the menu or typing the keyboard equivalent
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; will change the region to use that face.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; If you use transient-mark-mode and the region is not active, the
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; face will be remembered and used for the next insertion. It will
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; be forgotten if you move point or make other modifications before
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; inserting or typing anything.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Faces can be selected from the keyboard as well.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; The standard keybindings are M-s (or ESC s) + letter:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; M-s i = "set italic", M-s b = "set bold", etc.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; Customization:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; An alternative set of keybindings that may be easier to type can be set up
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; using "Hyper" keys. This requires that you set up a hyper-key on your
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; keyboard. On my system, putting the following command in my .xinitrc:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; xmodmap -e "keysym Alt_L = Hyper_L" -e "add Mod2 = Hyper_L"
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; makes the key labelled "Alt" act as a hyper key, but check with local
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; X-perts for how to do it on your system. If you do this, then put the
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; following in your .emacs before the (require 'facemenu):
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; (setq facemenu-keybindings
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; '((default . [?\H-d])
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; (bold . [?\H-b])
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; (italic . [?\H-i])
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; (bold-italic . [?\H-o])
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; (underline . [?\H-u])))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; (setq facemenu-keymap global-map)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; (setq facemenu-key nil)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; In general, the order of the faces that appear in the menu and their
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; keybindings can be controlled by setting the variable
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; `facemenu-keybindings'. Faces that you never want to add to your
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; document (e.g., `region') are listed in `facemenu-unlisted-faces'.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;; Known Problems:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; There is at present no way to display what the faces look like in
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; the menu itself.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; `list-faces-display' shows the faces in a different order than
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; this menu, which could be confusing. I do /not/ sort the list
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; alphabetically, because I like the default order: it puts the most
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; basic, common fonts first.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; Please send me any other problems, comments or ideas.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; Code:
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (provide 'facemenu)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (defvar facemenu-key "\M-s"
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 "Prefix to use for facemenu commands.")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defvar facemenu-keymap nil
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Map for keybindings of face commands.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 If nil, `facemenu-update' will create one.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 `Facemenu-update' also fills in the keymap according to the bindings
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 requested in facemenu-keybindings.")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defvar facemenu-keybindings
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 '((default . "d")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (bold . "b")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (italic . "i")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (bold-italic . "o") ; O for "Oblique" or "bOld"...
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (underline . "u"))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "Alist of interesting faces and keybindings.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 Each element is itself a list: the car is the name of the face,
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 the next element is the key to use as a keyboard equivalent of the menu item;
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 the binding is made in facemenu-keymap.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 The faces specifically mentioned in this list are put at the top of
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 the menu, in the order specified. All other faces which are defined,
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 except for those in `facemenu-unlisted-faces', are listed after them,
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 but get no keyboard equivalents.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 If you change this variable after loading facemenu.el, you will need to call
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 `facemenu-update' to make it take effect.")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (defvar facemenu-unlisted-faces
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 '(modeline region secondary-selection highlight scratch-face)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "Faces that are not included in the Face menu.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 Set this before loading facemenu.el, or call `facemenu-update' after
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 changing it.")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (defvar facemenu-next nil) ; set when we are going to set a face on next char.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defvar facemenu-loc nil)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defun facemenu-update ()
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "Add or update the \"Face\" menu in the menu bar."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (interactive)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; Set up keymaps
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (fset 'facemenu-menu (setq facemenu-menu (make-sparse-keymap "Face")))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (if (null facemenu-keymap)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (fset 'facemenu-keymap
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (setq facemenu-keymap (make-sparse-keymap "Set face"))))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (if facemenu-key
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (define-key global-map facemenu-key facemenu-keymap))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; Define commands for face-changing
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (facemenu-complete-face-list facemenu-keybindings))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (define-key global-map (vector 'menu-bar 'Face)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (cons "Face" facemenu-menu)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ; We'd really like to name the menu items as follows,
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ; but we can't since menu entries don't display text properties (yet?)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ; (let ((s (copy-sequence (symbol-name face))))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ; (put-text-property 0 (1- (length s))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ; 'face face s)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ; s)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 it is inactive \(even if mark-even-if-inactive is set) the next
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 character that is typed \(via `self-insert-command') will be set to
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 the the selected face. Moving point or switching buffers before
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 typing a character cancels the request."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (interactive (list (read-face-name "Use face: ")))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defun facemenu-set-face-from-menu (face start end)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "Set the face of the region or next character typed.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 This function is designed to be called from a menu; the face to use
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 is the menu item's name.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 If the region is active, it will be set to the requested face. If
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 it is inactive \(even if mark-even-if-inactive is set) the next
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 character that is typed \(via `self-insert-command') will be set to
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 the the selected face. Moving point or switching buffers before
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (setq facemenu-next face facemenu-loc (point))))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (defun facemenu-set-invisible (start end)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 "Make the region invisible.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 This sets the `invisible' text property; it can be undone with
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 `facemenu-remove-all'."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (interactive "r")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (put-text-property start end 'invisible t))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (defun facemenu-set-intangible (start end)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 "Make the region intangible: disallow moving into it.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 This sets the `intangible' text property; it can be undone with
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 `facemenu-remove-all'."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (interactive "r")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (put-text-property start end 'intangible t))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (defun facemenu-set-read-only (start end)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 "Make the region unmodifiable.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 This sets the `read-only' text property; it can be undone with
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 `facemenu-remove-all'."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (interactive "r")
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (put-text-property start end 'read-only t))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defun facemenu-remove-all (start end)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 "Remove all text properties that facemenu added to region."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (interactive "*r") ; error if buffer is read-only despite the next line.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (let ((inhibit-read-only t))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (remove-text-properties
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 start end '(face nil invisible nil intangible nil
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 read-only nil category nil))))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (defun facemenu-after-change (begin end old-length)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 "May set the face of just-inserted text to user's request.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 This only happens if the change is an insertion, and
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 `facemenu-set-face[-from-menu]' was called with point at the
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 beginning of the insertion."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (if (null facemenu-next) ; exit immediately if no work
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 nil
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (if (and (= 0 old-length) ; insertion
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (setq facemenu-next nil)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (defun facemenu-complete-face-list (&optional oldlist)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 "Return alist of all faces that are look different.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 Starts with given LIST of faces, and adds elements only if they display
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 differently from any face already on the list.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 The original LIST will end up at the end of the returned list, in reverse
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 order. The elements added will have null cdrs."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (let ((list nil))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (facemenu-iterate
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (function
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (lambda (item)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (if (internal-find-face (car item))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (setq list (cons item list)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 nil))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 oldlist)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (facemenu-iterate
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (function
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (lambda (new-face)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (if (not (facemenu-iterate
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (function
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (lambda (item) (face-equal (car item) new-face t)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 list))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq list (cons (cons new-face nil) list)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 nil))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (nreverse (face-list)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 list))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (defun facemenu-iterate (func iterate-list)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 "Apply FUNC to each element of LIST until one returns non-nil.
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 Returns the non-nil value it found, or nil if all were nil."
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (while (and iterate-list (not (funcall func (car iterate-list))))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (setq iterate-list (cdr iterate-list)))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (car iterate-list))
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (facemenu-update)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (add-hook 'menu-bar-final-items 'Face)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (add-hook 'after-change-functions 'facemenu-after-change)
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
03445a867bed Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 ;;; facemenu.el ends here