Mercurial > emacs
annotate lisp/facemenu.el @ 10635:c807d6c947de
(kbd_buffer_get_event, swallow_events): Remove selection_request event
from input queue before processing it.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 02 Feb 1995 18:55:39 +0000 |
parents | 3d30caa4b459 |
children | c42fdf00dfa0 |
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: | |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
24 ;; This file defines a menu of faces (bold, italic, etc) which allows you to |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
25 ;; set the face used for a region of the buffer. Some faces also have |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
26 ;; keybindings, which are shown in the menu. Faces with names beginning with |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
27 ;; "fg:" or "bg:", as in "fg:red", are treated specially. |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
28 ;; Such faces are assumed to consist only of a foreground (if "fg:") or |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
29 ;; background (if "bg:") color. They are thus put into the color submenus |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
30 ;; rather than the general Face submenu. These faces can also be |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
31 ;; automatically created by selecting the "Other..." menu items in the |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
32 ;; "Foreground" and "Background" submenus. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
33 ;; |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
34 ;; The menu also contains submenus for indentation and justification-changing |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
35 ;; commands. |
8743 | 36 |
37 ;;; Usage: | |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
38 ;; Selecting a face from the menu or typing the keyboard equivalent will |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
39 ;; change the region to use that face. If you use transient-mark-mode and the |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
40 ;; region is not active, the face will be remembered and used for the next |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
41 ;; insertion. It will be forgotten if you move point or make other |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
42 ;; modifications before inserting or typing anything. |
8743 | 43 ;; |
44 ;; Faces can be selected from the keyboard as well. | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
45 ;; The standard keybindings are M-g (or ESC g) + letter: |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
46 ;; M-g i = "set italic", M-g b = "set bold", etc. |
8743 | 47 |
48 ;;; Customization: | |
49 ;; An alternative set of keybindings that may be easier to type can be set up | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
50 ;; using "Alt" or "Hyper" keys. This requires that you either have or create |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
51 ;; an Alt or Hyper key on your keyboard. On my keyboard, there is a key |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
52 ;; labeled "Alt", but to make it act as an Alt key I have to put this command |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
53 ;; into my .xinitrc: |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
54 ;; xmodmap -e "add Mod3 = Alt_L" |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
55 ;; Or, I can make it into a Hyper key with this: |
8743 | 56 ;; xmodmap -e "keysym Alt_L = Hyper_L" -e "add Mod2 = Hyper_L" |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
57 ;; Check with local X-perts for how to do it on your system. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
58 ;; Then you can define your keybindings with code like this in your .emacs: |
8743 | 59 ;; (setq facemenu-keybindings |
60 ;; '((default . [?\H-d]) | |
61 ;; (bold . [?\H-b]) | |
62 ;; (italic . [?\H-i]) | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
63 ;; (bold-italic . [?\H-l]) |
8743 | 64 ;; (underline . [?\H-u]))) |
65 ;; (setq facemenu-keymap global-map) | |
66 ;; (setq facemenu-key nil) | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
67 ;; (define-key global-map [?\H-c] 'facemenu-set-foreground) ; set fg color |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
68 ;; (define-key global-map [?\H-C] 'facemenu-set-background) ; set bg color |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
69 ;; (require 'facemenu) |
8743 | 70 ;; |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
71 ;; The order of the faces that appear in the menu and their keybindings can be |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
72 ;; controlled by setting the variables `facemenu-keybindings' and |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
73 ;; `facemenu-new-faces-at-end'. List faces that you don't use in documents |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
74 ;; (eg, `region') in `facemenu-unlisted-faces'. |
8743 | 75 |
76 ;;; Known Problems: | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
77 ;; Bold and Italic do not combine to create bold-italic if you select them |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
78 ;; both, although most other combinations (eg bold + underline + some color) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
79 ;; do the intuitive thing. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
80 ;; |
8743 | 81 ;; There is at present no way to display what the faces look like in |
82 ;; the menu itself. | |
83 ;; | |
84 ;; `list-faces-display' shows the faces in a different order than | |
85 ;; this menu, which could be confusing. I do /not/ sort the list | |
86 ;; alphabetically, because I like the default order: it puts the most | |
87 ;; basic, common fonts first. | |
88 ;; | |
89 ;; Please send me any other problems, comments or ideas. | |
90 | |
91 ;;; Code: | |
92 | |
93 (provide 'facemenu) | |
94 | |
10238
0fcafe7e34cc
(facemenu-key): Change to M-g.
Richard M. Stallman <rms@gnu.org>
parents:
9874
diff
changeset
|
95 (defvar facemenu-key "\M-g" |
8743 | 96 "Prefix to use for facemenu commands.") |
97 | |
98 (defvar facemenu-keybindings | |
99 '((default . "d") | |
100 (bold . "b") | |
101 (italic . "i") | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
102 (bold-italic . "l") ; {bold} intersect {italic} = {l} |
8743 | 103 (underline . "u")) |
104 "Alist of interesting faces and keybindings. | |
105 Each element is itself a list: the car is the name of the face, | |
106 the next element is the key to use as a keyboard equivalent of the menu item; | |
107 the binding is made in facemenu-keymap. | |
108 | |
109 The faces specifically mentioned in this list are put at the top of | |
110 the menu, in the order specified. All other faces which are defined, | |
111 except for those in `facemenu-unlisted-faces', are listed after them, | |
112 but get no keyboard equivalents. | |
113 | |
114 If you change this variable after loading facemenu.el, you will need to call | |
115 `facemenu-update' to make it take effect.") | |
116 | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
117 (defvar facemenu-new-faces-at-end t |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
118 "Where in the menu to insert newly-created faces. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
119 This should be nil to put them at the top of the menu, or t to put them |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
120 just before \"Other\" at the end.") |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
121 |
8743 | 122 (defvar facemenu-unlisted-faces |
123 '(modeline region secondary-selection highlight scratch-face) | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
124 "List of faces not to include in the Face menu. |
8743 | 125 Set this before loading facemenu.el, or call `facemenu-update' after |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
126 changing it. |
8743 | 127 |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
128 If this variable is t, no faces will be added to the menu. This is useful for |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
129 temporarily turning off the feature that automatically adds faces to the menu |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
130 when they are created.") |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
131 |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
132 (defvar facemenu-face-menu |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
133 (let ((map (make-sparse-keymap "Face"))) |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
134 (define-key map "o" (cons "Other..." 'facemenu-set-face)) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
135 map) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
136 "Menu keymap for faces.") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
137 (defalias 'facemenu-face-menu facemenu-face-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
138 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
139 (defvar facemenu-foreground-menu |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
140 (let ((map (make-sparse-keymap "Foreground Color"))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
141 (define-key map "o" (cons "Other" 'facemenu-set-foreground)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
142 map) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
143 "Menu keymap for foreground colors.") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
144 (defalias 'facemenu-foreground-menu facemenu-foreground-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
145 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
146 (defvar facemenu-background-menu |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
147 (let ((map (make-sparse-keymap "Background Color"))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
148 (define-key map "o" (cons "Other" 'facemenu-set-background)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
149 map) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
150 "Menu keymap for background colors") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
151 (defalias 'facemenu-background-menu facemenu-background-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
152 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
153 (defvar facemenu-special-menu |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
154 (let ((map (make-sparse-keymap "Special"))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
155 (define-key map [read-only] (cons "Read-Only" 'facemenu-set-read-only)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
156 (define-key map [invisible] (cons "Invisible" 'facemenu-set-invisible)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
157 map) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
158 "Menu keymap for non-face text-properties.") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
159 (defalias 'facemenu-special-menu facemenu-special-menu) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
160 |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
161 (defvar facemenu-justification-menu |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
162 (let ((map (make-sparse-keymap "Justification"))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
163 (define-key map [?c] (cons "Center" 'set-justification-center)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
164 (define-key map [?b] (cons "Full" 'set-justification-full)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
165 (define-key map [?r] (cons "Right" 'set-justification-right)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
166 (define-key map [?l] (cons "Left" 'set-justification-left)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
167 (define-key map [?u] (cons "Unfilled" 'set-nofill)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
168 map) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
169 "Submenu for text justification commands.") |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
170 (defalias 'facemenu-justification-menu facemenu-justification-menu) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
171 |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
172 (defvar facemenu-indentation-menu |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
173 (let ((map (make-sparse-keymap "Indentation"))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
174 (define-key map [UnIndentRight] |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
175 (cons "UnIndentRight" 'decrease-right-margin)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
176 (define-key map [IndentRight] |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
177 (cons "IndentRight" 'increase-right-margin)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
178 (define-key map [Unindent] |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
179 (cons "UnIndent" 'decrease-left-margin)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
180 (define-key map [Indent] |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
181 (cons "Indent" 'increase-left-margin)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
182 map) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
183 "Submenu for indentation commands.") |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
184 (defalias 'facemenu-indentation-menu facemenu-indentation-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
185 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
186 (defvar facemenu-menu |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
187 (let ((map (make-sparse-keymap "Face"))) |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
188 (define-key map [dc] (cons "Display Colors" 'list-colors-display)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
189 (define-key map [df] (cons "Display Faces" 'list-faces-display)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
190 (define-key map [rm] (cons "Remove Props" 'facemenu-remove-all)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
191 (define-key map [s1] (list "-----------------")) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
192 (define-key map [in] (cons "Indentation" 'facemenu-indentation-menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
193 (define-key map [ju] (cons "Justification" 'facemenu-justification-menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
194 (define-key map [s2] (list "-----------------")) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
195 (define-key map [sp] (cons "Special Props" 'facemenu-special-menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
196 (define-key map [bg] (cons "Background Color" 'facemenu-background-menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
197 (define-key map [fg] (cons "Foreground Color" 'facemenu-foreground-menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
198 (define-key map [fc] (cons "Face" 'facemenu-face-menu)) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
199 map) |
9874
2bf88bd23cbb
(facemenu-update): Use C-down-mouse-2 for the menu.
Richard M. Stallman <rms@gnu.org>
parents:
9623
diff
changeset
|
200 "Facemenu top-level menu keymap.") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
201 (defalias 'facemenu-menu facemenu-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
202 |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
203 (defvar facemenu-keymap |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
204 (let ((map (make-sparse-keymap "Set face"))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
205 (define-key map "o" (cons "Other" 'facemenu-set-face)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
206 map) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
207 "Map for keyboard face-changing commands. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
208 `Facemenu-update' fills in the keymap according to the bindings |
9874
2bf88bd23cbb
(facemenu-update): Use C-down-mouse-2 for the menu.
Richard M. Stallman <rms@gnu.org>
parents:
9623
diff
changeset
|
209 requested in `facemenu-keybindings'.") |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
210 (defalias 'facemenu-keymap facemenu-keymap) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
211 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
212 ;;; Internal Variables |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
213 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
214 (defvar facemenu-color-alist nil |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
215 ;; Don't initialize here; that doesn't work if preloaded. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
216 "Alist of colors, used for completion. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
217 If null, `facemenu-read-color' will set it.") |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
218 |
8743 | 219 (defvar facemenu-next nil) ; set when we are going to set a face on next char. |
220 (defvar facemenu-loc nil) | |
221 | |
222 (defun facemenu-update () | |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
223 "Add or update the \"Face\" menu in the menu bar. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
224 You can call this to update things if you change any of the menu configuration |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
225 variables." |
8743 | 226 (interactive) |
227 | |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
228 ;; Global bindings: |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
229 (define-key global-map [C-down-mouse-2] 'facemenu-menu) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
230 (if facemenu-key (define-key global-map facemenu-key 'facemenu-keymap)) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
231 |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
232 ;; Add each defined face to the menu. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
233 (facemenu-iterate 'facemenu-add-new-face |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
234 (facemenu-complete-face-list facemenu-keybindings))) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
235 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
236 ;;;###autoload |
8743 | 237 (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
|
238 "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
|
239 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
|
240 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
|
241 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
242 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
|
243 If the region is active, it will be set to the requested face. If |
8743 | 244 it is inactive \(even if mark-even-if-inactive is set) the next |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
245 character that is typed \(or otherwise inserted) will be set to |
8743 | 246 the the selected face. Moving point or switching buffers before |
247 typing a character cancels the request." | |
248 (interactive (list (read-face-name "Use face: "))) | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
249 (barf-if-buffer-read-only) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
250 (facemenu-add-new-face face) |
8743 | 251 (if mark-active |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
252 (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
|
253 (end (or end (region-end)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
254 (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
|
255 (setq facemenu-next face |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
256 facemenu-loc (point)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
257 |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
258 ;;;###autoload |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
259 (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
|
260 "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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 (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
|
268 (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
|
269 (or (facemenu-get-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
270 (error "Unknown color: %s" color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
271 (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
|
272 |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
273 ;;;###autoload |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
274 (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
|
275 "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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 (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
|
283 (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
|
284 (or (facemenu-get-face face) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
285 (error "Unknown color: %s" color)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
286 (facemenu-set-face face start end))) |
8743 | 287 |
288 (defun facemenu-set-face-from-menu (face start end) | |
289 "Set the face of the region or next character typed. | |
290 This function is designed to be called from a menu; the face to use | |
291 is the menu item's name. | |
292 If the region is active, it will be set to the requested face. If | |
293 it is inactive \(even if mark-even-if-inactive is set) the next | |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
294 character that is typed \(or otherwise inserted) will be set to |
8743 | 295 the the selected face. Moving point or switching buffers before |
296 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
|
297 (interactive (list last-command-event |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
298 (if mark-active (region-beginning)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
299 (if mark-active (region-end)))) |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
300 (barf-if-buffer-read-only) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
301 (facemenu-get-face face) |
8743 | 302 (if start |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
303 (facemenu-add-face face start end) |
8743 | 304 (setq facemenu-next face facemenu-loc (point)))) |
305 | |
306 (defun facemenu-set-invisible (start end) | |
307 "Make the region invisible. | |
308 This sets the `invisible' text property; it can be undone with | |
309 `facemenu-remove-all'." | |
310 (interactive "r") | |
311 (put-text-property start end 'invisible t)) | |
312 | |
313 (defun facemenu-set-intangible (start end) | |
314 "Make the region intangible: disallow moving into it. | |
315 This sets the `intangible' text property; it can be undone with | |
316 `facemenu-remove-all'." | |
317 (interactive "r") | |
318 (put-text-property start end 'intangible t)) | |
319 | |
320 (defun facemenu-set-read-only (start end) | |
321 "Make the region unmodifiable. | |
322 This sets the `read-only' text property; it can be undone with | |
323 `facemenu-remove-all'." | |
324 (interactive "r") | |
325 (put-text-property start end 'read-only t)) | |
326 | |
327 (defun facemenu-remove-all (start end) | |
328 "Remove all text properties that facemenu added to region." | |
329 (interactive "*r") ; error if buffer is read-only despite the next line. | |
330 (let ((inhibit-read-only t)) | |
331 (remove-text-properties | |
332 start end '(face nil invisible nil intangible nil | |
333 read-only nil category nil)))) | |
334 | |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
335 ;;;###autoload |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
336 (defun facemenu-read-color (prompt) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
337 "Read a color using the minibuffer." |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
338 (let ((col (completing-read (or "Color: ") |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
339 (or facemenu-color-alist |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
340 (if (eq 'x window-system) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
341 (mapcar 'list (x-defined-colors)))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
342 nil t))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
343 (if (equal "" col) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
344 nil |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
345 col))) |
8743 | 346 |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
347 ;;;###autoload |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
348 (defun list-colors-display (&optional list) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
349 "Display colors. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
350 You can optionally supply a LIST of colors to display, or this function will |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
351 get a list for the current display, removing alternate names for the same |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
352 color." |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
353 (interactive) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
354 (if (and (null list) (eq 'x window-system)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
355 (let ((l (setq list (x-defined-colors)))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
356 (while (cdr l) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
357 (if (facemenu-color-equal (car l) (car (cdr l))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
358 (setcdr l (cdr (cdr l))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
359 (setq l (cdr l)))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
360 (with-output-to-temp-buffer "*Colors*" |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
361 (save-excursion |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
362 (set-buffer standard-output) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
363 (let ((facemenu-unlisted-faces t) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
364 s) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
365 (while list |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
366 (setq s (point)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
367 (insert (car list)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
368 (indent-to 20) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
369 (put-text-property s (point) 'face |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
370 (facemenu-get-face |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
371 (intern (concat "bg:" (car list))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
372 (setq s (point)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
373 (insert " " (car list) "\n") |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
374 (put-text-property s (point) 'face |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
375 (facemenu-get-face |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
376 (intern (concat "fg:" (car list))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
377 (setq list (cdr list))))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
378 |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
379 (defun facemenu-color-equal (a b) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
380 "Return t if colors A and B are the same color. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
381 A and B should be strings naming colors. The window-system server is queried |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
382 to find how they would actually be displayed. Nil is always returned if the |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
383 correct answer cannot be determined." |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
384 (cond ((equal a b) t) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
385 ((and (eq 'x window-system) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
386 (equal (x-color-values a) (x-color-values b)))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
387 |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
388 (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
|
389 "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
|
390 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
|
391 be consed onto it, and other faces that are completely hidden by that will be |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
392 removed from the list. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
393 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
394 As a special case, if FACE is `default', then the region is left with NO face |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
395 text property. Otherwise, selecting the default face would not have any |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
396 effect." |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
397 (interactive "*xFace:\nr") |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
398 (if (eq face 'default) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
399 (remove-text-properties start end '(face default)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
400 (let ((part-start start) part-end) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
401 (while (not (= part-start end)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
402 (setq part-end (next-single-property-change part-start 'face nil end)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
403 (let ((prev (get-text-property part-start 'face))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
404 (put-text-property part-start part-end 'face |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
405 (if (null prev) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
406 face |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
407 (facemenu-discard-redundant-faces |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
408 (cons face |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
409 (if (listp prev) prev (list prev))))))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
410 (setq part-start part-end))))) |
9494
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
411 |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
412 (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
|
413 "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
|
414 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
|
415 earlier face." |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
416 (let ((useful nil)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
417 (cond ((null face-list) nil) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
418 ((null mask) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
419 (cons (car face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
420 (facemenu-discard-redundant-faces |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
421 (cdr face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
422 (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
|
423 ((let ((i (length mask)) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
424 (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
|
425 (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
|
426 (if (and (aref face i) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
427 (not (aref mask i))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
428 (progn (setq useful t) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
429 (aset mask i t)))) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
430 useful) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
431 (cons (car face-list) |
9a4ed505445e
(facemenu-read-color, facemenu-colors): New fn, var.
Richard M. Stallman <rms@gnu.org>
parents:
8953
diff
changeset
|
432 (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
|
433 (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
|
434 |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
435 (defun facemenu-get-face (symbol) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
436 "Make sure FACE exists. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
437 If not, it is created. If it is created and is of the form `fg:color', then |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
438 set the foreground to that color. If of the form `bg:color', set the |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
439 background. In any case, add it to the appropriate menu. Returns the face, |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
440 or nil if given a bad color." |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
441 (if (or (internal-find-face symbol) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
442 (let* ((face (make-face symbol)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
443 (name (symbol-name symbol)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
444 (color (substring name 3))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
445 (cond ((string-match "^fg:" name) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
446 (set-face-foreground face color) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
447 (and (eq 'x window-system) (x-color-defined-p color))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
448 ((string-match "^bg:" name) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
449 (set-face-background face color) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
450 (and (eq 'x window-system) (x-color-defined-p color))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
451 (t)))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
452 symbol)) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
453 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
454 (defun facemenu-add-new-face (face) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
455 "Add a FACE to the appropriate Face menu. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
456 Automatically called when a new face is created." |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
457 (let* ((name (symbol-name face)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
458 (menu (cond ((string-match "^fg:" name) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
459 (setq name (substring name 3)) |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
460 'facemenu-foreground-menu) |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
461 ((string-match "^bg:" name) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
462 (setq name (substring name 3)) |
10520
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
463 'facemenu-background-menu) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
464 (t 'facemenu-face-menu))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
465 (key (cdr (assoc face facemenu-keybindings))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
466 function menu-val) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
467 (cond ((eq t facemenu-unlisted-faces)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
468 ((memq face facemenu-unlisted-faces)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
469 (key ; has a keyboard equivalent. These go at the front. |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
470 (setq function (intern (concat "facemenu-set-" name))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
471 (fset function |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
472 (` (lambda () (interactive) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
473 (facemenu-set-face (quote (, face)))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
474 (define-key 'facemenu-keymap key (cons name function)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
475 (define-key menu key (cons name function))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
476 ((facemenu-iterate ; check if equivalent face is already in the menu |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
477 (lambda (m) (and (listp m) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
478 (symbolp (car m)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
479 (face-equal (car m) face))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
480 (cdr (symbol-function menu)))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
481 (t ; No keyboard equivalent. Figure out where to put it: |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
482 (setq key (vector face) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
483 function 'facemenu-set-face-from-menu |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
484 menu-val (symbol-function menu)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
485 (if (and facemenu-new-faces-at-end |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
486 (> (length menu-val) 3)) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
487 (define-key-after menu-val key (cons name function) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
488 (car (nth (- (length menu-val) 3) menu-val))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
489 (define-key menu key (cons name function)))))) |
3d30caa4b459
(facemenu-keybindings, facemenu-face-menu):
Richard M. Stallman <rms@gnu.org>
parents:
10238
diff
changeset
|
490 nil) ; Return nil for facemenu-iterate |
9623
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
491 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
492 (defun facemenu-after-change (begin end old-length) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
493 "May set the face of just-inserted text to user's request. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
494 This only happens if the change is an insertion, and |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
495 `facemenu-set-face[-from-menu]' was called with point at the |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
496 beginning of the insertion." |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
497 (if (null facemenu-next) ; exit immediately if no work |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
498 nil |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
499 (if (and (= 0 old-length) ; insertion |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
500 (= facemenu-loc begin)) ; point wasn't moved in between |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
501 (facemenu-add-face facemenu-next begin end)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
502 (setq facemenu-next nil))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
503 |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
504 (defun facemenu-complete-face-list (&optional oldlist) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
505 "Return list of all faces that are look different. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
506 Starts with given ALIST of faces, and adds elements only if they display |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
507 differently from any face already on the list. |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
508 The faces on ALIST will end up at the end of the returned list, in reverse |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
509 order." |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
510 (let ((list (nreverse (mapcar 'car oldlist)))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
511 (facemenu-iterate |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
512 (lambda (new-face) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
513 (if (not (memq new-face list)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
514 (setq list (cons new-face list))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
515 nil) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
516 (nreverse (face-list))) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
517 list)) |
fe1c170fa35a
(facemenu-get-face): Don't add to menu here.
Boris Goldowsky <boris@gnu.org>
parents:
9494
diff
changeset
|
518 |
8743 | 519 (defun facemenu-iterate (func iterate-list) |
520 "Apply FUNC to each element of LIST until one returns non-nil. | |
521 Returns the non-nil value it found, or nil if all were nil." | |
522 (while (and iterate-list (not (funcall func (car iterate-list)))) | |
523 (setq iterate-list (cdr iterate-list))) | |
524 (car iterate-list)) | |
525 | |
526 (facemenu-update) | |
527 (add-hook 'after-change-functions 'facemenu-after-change) | |
528 | |
529 ;;; facemenu.el ends here |