diff options
| author | Richard M. Stallman | 1995-01-22 16:47:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-01-22 16:47:10 +0000 |
| commit | 88d690a96e2d6547fe2aafc6e3a6a8215643ef0d (patch) | |
| tree | 6da2763b267f2dc3bb8706c6c1165de322a3573d | |
| parent | 5f329f439f5d8ab874363348f2837e4cb0505f91 (diff) | |
| download | emacs-88d690a96e2d6547fe2aafc6e3a6a8215643ef0d.tar.gz emacs-88d690a96e2d6547fe2aafc6e3a6a8215643ef0d.zip | |
(facemenu-keybindings, facemenu-face-menu):
Keybinding for bold-italic changed from M-g o to M-g l; M-g o is
now "other".
(facemenu-justification-menu, facemenu-indentation-menu):
New submenus, moved from enriched.el
(list-colors-display, facemenu-color-equal): New functions.
(facemenu-menu): Added "Display Faces" item.
(facemenu-new-faces-at-end): New variable.
(facemenu-add-new-face): Obey facemenu-new-faces-at-end.
(facemenu-menu, facemenu-keymap, facemenu-face-menu)
(facemenu-foreground-menu, facemenu-background-menu)
(facemenu-special-menu): Now have function definitions as prefix keys.
(facemenu-menu, facemenu-update): Refer to submenus by their names
rather than including their values.
(facemenu-set-face): Error if read-only; add item to menu if necessary.
(facemenu-get-face): Always return FACE.
(facemenu-add-new-face): Don't add if facemenu-unlisted-faces is t.
(facemenu-unlisted-faces): Doc fix.
Revise keybindings; doc fix.
(facemenu-new-faces-at-end): New vbl. (facemenu-add-new-face): Use it.
(facemenu-set-face, facemenu-set-face-from-menu): Check read-only.
(facemenu-set-face): Doc fix.
(facemenu-face-menu, facemenu-foreground-menu,
facemenu-background-menu, facemenu-special-menu): New or renamed
variables for submenus.
(facemenu-color-alist): Renamed from facemenu-colors.
(facemenu-add-new-face): New function.
(facemenu-update): Don't redo top-level menu;
nothing should change. Move menu setup to defvars. Use
facemenu-add-new-face. Changed global binding to C-down-mouse-3.
(facemenu-menu): "Update" item removed; should
no longer be needed interactively.
(facemenu-complete-face-list): Just return faces, not keybindings.
| -rw-r--r-- | lisp/facemenu.el | 242 |
1 files changed, 180 insertions, 62 deletions
diff --git a/lisp/facemenu.el b/lisp/facemenu.el index 6acabf66215..831e3a3f81c 100644 --- a/lisp/facemenu.el +++ b/lisp/facemenu.el | |||
| @@ -24,11 +24,15 @@ | |||
| 24 | ;; This file defines a menu of faces (bold, italic, etc) which allows you to | 24 | ;; This file defines a menu of faces (bold, italic, etc) which allows you to |
| 25 | ;; set the face used for a region of the buffer. Some faces also have | 25 | ;; set the face used for a region of the buffer. Some faces also have |
| 26 | ;; keybindings, which are shown in the menu. Faces with names beginning with | 26 | ;; keybindings, which are shown in the menu. Faces with names beginning with |
| 27 | ;; "fg:" or "bg:", as in "fg:red", are treated specially. It is assumed that | 27 | ;; "fg:" or "bg:", as in "fg:red", are treated specially. |
| 28 | ;; Such faces are assumed to consist only of a foreground (if "fg:") or | 28 | ;; Such faces are assumed to consist only of a foreground (if "fg:") or |
| 29 | ;; background (if "bg:") color. They are thus put into the color submenus | 29 | ;; background (if "bg:") color. They are thus put into the color submenus |
| 30 | ;; rather than the general Face submenu. Such faces can also be created on | 30 | ;; rather than the general Face submenu. These faces can also be |
| 31 | ;; demand from the "Other..." menu items. | 31 | ;; automatically created by selecting the "Other..." menu items in the |
| 32 | ;; "Foreground" and "Background" submenus. | ||
| 33 | ;; | ||
| 34 | ;; The menu also contains submenus for indentation and justification-changing | ||
| 35 | ;; commands. | ||
| 32 | 36 | ||
| 33 | ;;; Usage: | 37 | ;;; Usage: |
| 34 | ;; Selecting a face from the menu or typing the keyboard equivalent will | 38 | ;; Selecting a face from the menu or typing the keyboard equivalent will |
| @@ -38,32 +42,42 @@ | |||
| 38 | ;; modifications before inserting or typing anything. | 42 | ;; modifications before inserting or typing anything. |
| 39 | ;; | 43 | ;; |
| 40 | ;; Faces can be selected from the keyboard as well. | 44 | ;; Faces can be selected from the keyboard as well. |
| 41 | ;; The standard keybindings are M-s (or ESC s) + letter: | 45 | ;; The standard keybindings are M-g (or ESC g) + letter: |
| 42 | ;; M-s i = "set italic", M-s b = "set bold", etc. | 46 | ;; M-g i = "set italic", M-g b = "set bold", etc. |
| 43 | 47 | ||
| 44 | ;;; Customization: | 48 | ;;; Customization: |
| 45 | ;; An alternative set of keybindings that may be easier to type can be set up | 49 | ;; An alternative set of keybindings that may be easier to type can be set up |
| 46 | ;; using "Hyper" keys. This requires that you set up a hyper-key on your | 50 | ;; using "Alt" or "Hyper" keys. This requires that you either have or create |
| 47 | ;; keyboard. On my system, putting the following command in my .xinitrc: | 51 | ;; an Alt or Hyper key on your keyboard. On my keyboard, there is a key |
| 52 | ;; labeled "Alt", but to make it act as an Alt key I have to put this command | ||
| 53 | ;; into my .xinitrc: | ||
| 54 | ;; xmodmap -e "add Mod3 = Alt_L" | ||
| 55 | ;; Or, I can make it into a Hyper key with this: | ||
| 48 | ;; xmodmap -e "keysym Alt_L = Hyper_L" -e "add Mod2 = Hyper_L" | 56 | ;; xmodmap -e "keysym Alt_L = Hyper_L" -e "add Mod2 = Hyper_L" |
| 49 | ;; makes the key labelled "Alt" act as a hyper key, but check with local | 57 | ;; Check with local X-perts for how to do it on your system. |
| 50 | ;; X-perts for how to do it on your system. If you do this, then put the | 58 | ;; Then you can define your keybindings with code like this in your .emacs: |
| 51 | ;; following in your .emacs before the (require 'facemenu): | ||
| 52 | ;; (setq facemenu-keybindings | 59 | ;; (setq facemenu-keybindings |
| 53 | ;; '((default . [?\H-d]) | 60 | ;; '((default . [?\H-d]) |
| 54 | ;; (bold . [?\H-b]) | 61 | ;; (bold . [?\H-b]) |
| 55 | ;; (italic . [?\H-i]) | 62 | ;; (italic . [?\H-i]) |
| 56 | ;; (bold-italic . [?\H-o]) | 63 | ;; (bold-italic . [?\H-l]) |
| 57 | ;; (underline . [?\H-u]))) | 64 | ;; (underline . [?\H-u]))) |
| 58 | ;; (setq facemenu-keymap global-map) | 65 | ;; (setq facemenu-keymap global-map) |
| 59 | ;; (setq facemenu-key nil) | 66 | ;; (setq facemenu-key nil) |
| 67 | ;; (define-key global-map [?\H-c] 'facemenu-set-foreground) ; set fg color | ||
| 68 | ;; (define-key global-map [?\H-C] 'facemenu-set-background) ; set bg color | ||
| 69 | ;; (require 'facemenu) | ||
| 60 | ;; | 70 | ;; |
| 61 | ;; In general, the order of the faces that appear in the menu and their | 71 | ;; The order of the faces that appear in the menu and their keybindings can be |
| 62 | ;; keybindings can be controlled by setting the variable | 72 | ;; controlled by setting the variables `facemenu-keybindings' and |
| 63 | ;; `facemenu-keybindings'. Faces that you never want to add to your | 73 | ;; `facemenu-new-faces-at-end'. List faces that you don't use in documents |
| 64 | ;; document (e.g., `region') are listed in `facemenu-unlisted-faces'. | 74 | ;; (eg, `region') in `facemenu-unlisted-faces'. |
| 65 | 75 | ||
| 66 | ;;; Known Problems: | 76 | ;;; Known Problems: |
| 77 | ;; Bold and Italic do not combine to create bold-italic if you select them | ||
| 78 | ;; both, although most other combinations (eg bold + underline + some color) | ||
| 79 | ;; do the intuitive thing. | ||
| 80 | ;; | ||
| 67 | ;; There is at present no way to display what the faces look like in | 81 | ;; There is at present no way to display what the faces look like in |
| 68 | ;; the menu itself. | 82 | ;; the menu itself. |
| 69 | ;; | 83 | ;; |
| @@ -85,7 +99,7 @@ | |||
| 85 | '((default . "d") | 99 | '((default . "d") |
| 86 | (bold . "b") | 100 | (bold . "b") |
| 87 | (italic . "i") | 101 | (italic . "i") |
| 88 | (bold-italic . "o") ; O for "Oblique" or "bOld"... | 102 | (bold-italic . "l") ; {bold} intersect {italic} = {l} |
| 89 | (underline . "u")) | 103 | (underline . "u")) |
| 90 | "Alist of interesting faces and keybindings. | 104 | "Alist of interesting faces and keybindings. |
| 91 | Each element is itself a list: the car is the name of the face, | 105 | Each element is itself a list: the car is the name of the face, |
| @@ -100,29 +114,41 @@ but get no keyboard equivalents. | |||
| 100 | If you change this variable after loading facemenu.el, you will need to call | 114 | If you change this variable after loading facemenu.el, you will need to call |
| 101 | `facemenu-update' to make it take effect.") | 115 | `facemenu-update' to make it take effect.") |
| 102 | 116 | ||
| 117 | (defvar facemenu-new-faces-at-end t | ||
| 118 | "Where in the menu to insert newly-created faces. | ||
| 119 | This should be nil to put them at the top of the menu, or t to put them | ||
| 120 | just before \"Other\" at the end.") | ||
| 121 | |||
| 103 | (defvar facemenu-unlisted-faces | 122 | (defvar facemenu-unlisted-faces |
| 104 | '(modeline region secondary-selection highlight scratch-face) | 123 | '(modeline region secondary-selection highlight scratch-face) |
| 105 | "Faces that are not included in the Face menu. | 124 | "List of faces not to include in the Face menu. |
| 106 | Set this before loading facemenu.el, or call `facemenu-update' after | 125 | Set this before loading facemenu.el, or call `facemenu-update' after |
| 107 | changing it.") | 126 | changing it. |
| 108 | 127 | ||
| 109 | (defvar facemenu-face-menu | 128 | If this variable is t, no faces will be added to the menu. This is useful for |
| 129 | temporarily turning off the feature that automatically adds faces to the menu | ||
| 130 | when they are created.") | ||
| 131 | |||
| 132 | (defvar facemenu-face-menu | ||
| 110 | (let ((map (make-sparse-keymap "Face"))) | 133 | (let ((map (make-sparse-keymap "Face"))) |
| 111 | (define-key map [other] (cons "Other..." 'facemenu-set-face)) | 134 | (define-key map "o" (cons "Other..." 'facemenu-set-face)) |
| 112 | map) | 135 | map) |
| 113 | "Menu keymap for faces.") | 136 | "Menu keymap for faces.") |
| 137 | (defalias 'facemenu-face-menu facemenu-face-menu) | ||
| 114 | 138 | ||
| 115 | (defvar facemenu-foreground-menu | 139 | (defvar facemenu-foreground-menu |
| 116 | (let ((map (make-sparse-keymap "Foreground Color"))) | 140 | (let ((map (make-sparse-keymap "Foreground Color"))) |
| 117 | (define-key map "o" (cons "Other" 'facemenu-set-foreground)) | 141 | (define-key map "o" (cons "Other" 'facemenu-set-foreground)) |
| 118 | map) | 142 | map) |
| 119 | "Menu keymap for foreground colors.") | 143 | "Menu keymap for foreground colors.") |
| 144 | (defalias 'facemenu-foreground-menu facemenu-foreground-menu) | ||
| 120 | 145 | ||
| 121 | (defvar facemenu-background-menu | 146 | (defvar facemenu-background-menu |
| 122 | (let ((map (make-sparse-keymap "Background Color"))) | 147 | (let ((map (make-sparse-keymap "Background Color"))) |
| 123 | (define-key map "o" (cons "Other" 'facemenu-set-background)) | 148 | (define-key map "o" (cons "Other" 'facemenu-set-background)) |
| 124 | map) | 149 | map) |
| 125 | "Menu keymap for background colors") | 150 | "Menu keymap for background colors") |
| 151 | (defalias 'facemenu-background-menu facemenu-background-menu) | ||
| 126 | 152 | ||
| 127 | (defvar facemenu-special-menu | 153 | (defvar facemenu-special-menu |
| 128 | (let ((map (make-sparse-keymap "Special"))) | 154 | (let ((map (make-sparse-keymap "Special"))) |
| @@ -130,23 +156,58 @@ changing it.") | |||
| 130 | (define-key map [invisible] (cons "Invisible" 'facemenu-set-invisible)) | 156 | (define-key map [invisible] (cons "Invisible" 'facemenu-set-invisible)) |
| 131 | map) | 157 | map) |
| 132 | "Menu keymap for non-face text-properties.") | 158 | "Menu keymap for non-face text-properties.") |
| 159 | (defalias 'facemenu-special-menu facemenu-special-menu) | ||
| 160 | |||
| 161 | (defvar facemenu-justification-menu | ||
| 162 | (let ((map (make-sparse-keymap "Justification"))) | ||
| 163 | (define-key map [?c] (cons "Center" 'set-justification-center)) | ||
| 164 | (define-key map [?b] (cons "Full" 'set-justification-full)) | ||
| 165 | (define-key map [?r] (cons "Right" 'set-justification-right)) | ||
| 166 | (define-key map [?l] (cons "Left" 'set-justification-left)) | ||
| 167 | (define-key map [?u] (cons "Unfilled" 'set-nofill)) | ||
| 168 | map) | ||
| 169 | "Submenu for text justification commands.") | ||
| 170 | (defalias 'facemenu-justification-menu facemenu-justification-menu) | ||
| 171 | |||
| 172 | (defvar facemenu-indentation-menu | ||
| 173 | (let ((map (make-sparse-keymap "Indentation"))) | ||
| 174 | (define-key map [UnIndentRight] | ||
| 175 | (cons "UnIndentRight" 'decrease-right-margin)) | ||
| 176 | (define-key map [IndentRight] | ||
| 177 | (cons "IndentRight" 'increase-right-margin)) | ||
| 178 | (define-key map [Unindent] | ||
| 179 | (cons "UnIndent" 'decrease-left-margin)) | ||
| 180 | (define-key map [Indent] | ||
| 181 | (cons "Indent" 'increase-left-margin)) | ||
| 182 | map) | ||
| 183 | "Submenu for indentation commands.") | ||
| 184 | (defalias 'facemenu-indentation-menu facemenu-indentation-menu) | ||
| 133 | 185 | ||
| 134 | (defvar facemenu-menu | 186 | (defvar facemenu-menu |
| 135 | (let ((map (make-sparse-keymap "Face"))) | 187 | (let ((map (make-sparse-keymap "Face"))) |
| 136 | (define-key map [display] (cons "Display Faces" 'list-faces-display)) | 188 | (define-key map [dc] (cons "Display Colors" 'list-colors-display)) |
| 137 | (define-key map [remove] (cons "Remove Props" 'facemenu-remove-all)) | 189 | (define-key map [df] (cons "Display Faces" 'list-faces-display)) |
| 138 | (define-key map [sep1] (list "-----------------")) | 190 | (define-key map [rm] (cons "Remove Props" 'facemenu-remove-all)) |
| 139 | (define-key map [special] (cons "Special Props" facemenu-special-menu)) | 191 | (define-key map [s1] (list "-----------------")) |
| 140 | (define-key map [bg] (cons "Background Color" facemenu-background-menu)) | 192 | (define-key map [in] (cons "Indentation" 'facemenu-indentation-menu)) |
| 141 | (define-key map [fg] (cons "Foreground Color" facemenu-foreground-menu)) | 193 | (define-key map [ju] (cons "Justification" 'facemenu-justification-menu)) |
| 142 | (define-key map [face] (cons "Face" facemenu-face-menu)) | 194 | (define-key map [s2] (list "-----------------")) |
| 195 | (define-key map [sp] (cons "Special Props" 'facemenu-special-menu)) | ||
| 196 | (define-key map [bg] (cons "Background Color" 'facemenu-background-menu)) | ||
| 197 | (define-key map [fg] (cons "Foreground Color" 'facemenu-foreground-menu)) | ||
| 198 | (define-key map [fc] (cons "Face" 'facemenu-face-menu)) | ||
| 143 | map) | 199 | map) |
| 144 | "Facemenu top-level menu keymap.") | 200 | "Facemenu top-level menu keymap.") |
| 201 | (defalias 'facemenu-menu facemenu-menu) | ||
| 145 | 202 | ||
| 146 | (defvar facemenu-keymap (make-sparse-keymap "Set face") | 203 | (defvar facemenu-keymap |
| 204 | (let ((map (make-sparse-keymap "Set face"))) | ||
| 205 | (define-key map "o" (cons "Other" 'facemenu-set-face)) | ||
| 206 | map) | ||
| 147 | "Map for keyboard face-changing commands. | 207 | "Map for keyboard face-changing commands. |
| 148 | `Facemenu-update' fills in the keymap according to the bindings | 208 | `Facemenu-update' fills in the keymap according to the bindings |
| 149 | requested in `facemenu-keybindings'.") | 209 | requested in `facemenu-keybindings'.") |
| 210 | (defalias 'facemenu-keymap facemenu-keymap) | ||
| 150 | 211 | ||
| 151 | ;;; Internal Variables | 212 | ;;; Internal Variables |
| 152 | 213 | ||
| @@ -165,8 +226,8 @@ variables." | |||
| 165 | (interactive) | 226 | (interactive) |
| 166 | 227 | ||
| 167 | ;; Global bindings: | 228 | ;; Global bindings: |
| 168 | (define-key global-map [C-down-mouse-2] facemenu-menu) | 229 | (define-key global-map [C-down-mouse-2] 'facemenu-menu) |
| 169 | (if facemenu-key (define-key global-map facemenu-key facemenu-keymap)) | 230 | (if facemenu-key (define-key global-map facemenu-key 'facemenu-keymap)) |
| 170 | 231 | ||
| 171 | ;; Add each defined face to the menu. | 232 | ;; Add each defined face to the menu. |
| 172 | (facemenu-iterate 'facemenu-add-new-face | 233 | (facemenu-iterate 'facemenu-add-new-face |
| @@ -181,10 +242,12 @@ will not show through at all will be removed. | |||
| 181 | Interactively, the face to be used is prompted for. | 242 | Interactively, the face to be used is prompted for. |
| 182 | If the region is active, it will be set to the requested face. If | 243 | If the region is active, it will be set to the requested face. If |
| 183 | it is inactive \(even if mark-even-if-inactive is set) the next | 244 | it is inactive \(even if mark-even-if-inactive is set) the next |
| 184 | character that is typed \(via `self-insert-command') will be set to | 245 | character that is typed \(or otherwise inserted) will be set to |
| 185 | the the selected face. Moving point or switching buffers before | 246 | the the selected face. Moving point or switching buffers before |
| 186 | typing a character cancels the request." | 247 | typing a character cancels the request." |
| 187 | (interactive (list (read-face-name "Use face: "))) | 248 | (interactive (list (read-face-name "Use face: "))) |
| 249 | (barf-if-buffer-read-only) | ||
| 250 | (facemenu-add-new-face face) | ||
| 188 | (if mark-active | 251 | (if mark-active |
| 189 | (let ((start (or start (region-beginning))) | 252 | (let ((start (or start (region-beginning))) |
| 190 | (end (or end (region-end)))) | 253 | (end (or end (region-end)))) |
| @@ -228,12 +291,13 @@ This function is designed to be called from a menu; the face to use | |||
| 228 | is the menu item's name. | 291 | is the menu item's name. |
| 229 | If the region is active, it will be set to the requested face. If | 292 | If the region is active, it will be set to the requested face. If |
| 230 | it is inactive \(even if mark-even-if-inactive is set) the next | 293 | it is inactive \(even if mark-even-if-inactive is set) the next |
| 231 | character that is typed \(via `self-insert-command') will be set to | 294 | character that is typed \(or otherwise inserted) will be set to |
| 232 | the the selected face. Moving point or switching buffers before | 295 | the the selected face. Moving point or switching buffers before |
| 233 | typing a character cancels the request." | 296 | typing a character cancels the request." |
| 234 | (interactive (list last-command-event | 297 | (interactive (list last-command-event |
| 235 | (if mark-active (region-beginning)) | 298 | (if mark-active (region-beginning)) |
| 236 | (if mark-active (region-end)))) | 299 | (if mark-active (region-end)))) |
| 300 | (barf-if-buffer-read-only) | ||
| 237 | (facemenu-get-face face) | 301 | (facemenu-get-face face) |
| 238 | (if start | 302 | (if start |
| 239 | (facemenu-add-face face start end) | 303 | (facemenu-add-face face start end) |
| @@ -280,6 +344,47 @@ This sets the `read-only' text property; it can be undone with | |||
| 280 | nil | 344 | nil |
| 281 | col))) | 345 | col))) |
| 282 | 346 | ||
| 347 | ;;;###autoload | ||
| 348 | (defun list-colors-display (&optional list) | ||
| 349 | "Display colors. | ||
| 350 | You can optionally supply a LIST of colors to display, or this function will | ||
| 351 | get a list for the current display, removing alternate names for the same | ||
| 352 | color." | ||
| 353 | (interactive) | ||
| 354 | (if (and (null list) (eq 'x window-system)) | ||
| 355 | (let ((l (setq list (x-defined-colors)))) | ||
| 356 | (while (cdr l) | ||
| 357 | (if (facemenu-color-equal (car l) (car (cdr l))) | ||
| 358 | (setcdr l (cdr (cdr l))) | ||
| 359 | (setq l (cdr l)))))) | ||
| 360 | (with-output-to-temp-buffer "*Colors*" | ||
| 361 | (save-excursion | ||
| 362 | (set-buffer standard-output) | ||
| 363 | (let ((facemenu-unlisted-faces t) | ||
| 364 | s) | ||
| 365 | (while list | ||
| 366 | (setq s (point)) | ||
| 367 | (insert (car list)) | ||
| 368 | (indent-to 20) | ||
| 369 | (put-text-property s (point) 'face | ||
| 370 | (facemenu-get-face | ||
| 371 | (intern (concat "bg:" (car list))))) | ||
| 372 | (setq s (point)) | ||
| 373 | (insert " " (car list) "\n") | ||
| 374 | (put-text-property s (point) 'face | ||
| 375 | (facemenu-get-face | ||
| 376 | (intern (concat "fg:" (car list))))) | ||
| 377 | (setq list (cdr list))))))) | ||
| 378 | |||
| 379 | (defun facemenu-color-equal (a b) | ||
| 380 | "Return t if colors A and B are the same color. | ||
| 381 | A and B should be strings naming colors. The window-system server is queried | ||
| 382 | to find how they would actually be displayed. Nil is always returned if the | ||
| 383 | correct answer cannot be determined." | ||
| 384 | (cond ((equal a b) t) | ||
| 385 | ((and (eq 'x window-system) | ||
| 386 | (equal (x-color-values a) (x-color-values b)))))) | ||
| 387 | |||
| 283 | (defun facemenu-add-face (face start end) | 388 | (defun facemenu-add-face (face start end) |
| 284 | "Add FACE to text between START and END. | 389 | "Add FACE to text between START and END. |
| 285 | For each section of that region that has a different face property, FACE will | 390 | For each section of that region that has a different face property, FACE will |
| @@ -331,19 +436,20 @@ earlier face." | |||
| 331 | "Make sure FACE exists. | 436 | "Make sure FACE exists. |
| 332 | If not, it is created. If it is created and is of the form `fg:color', then | 437 | If not, it is created. If it is created and is of the form `fg:color', then |
| 333 | set the foreground to that color. If of the form `bg:color', set the | 438 | set the foreground to that color. If of the form `bg:color', set the |
| 334 | background. In any case, add it to the appropriate menu. Returns nil if | 439 | background. In any case, add it to the appropriate menu. Returns the face, |
| 335 | given a bad color." | 440 | or nil if given a bad color." |
| 336 | (or (internal-find-face symbol) | 441 | (if (or (internal-find-face symbol) |
| 337 | (let* ((face (make-face symbol)) | 442 | (let* ((face (make-face symbol)) |
| 338 | (name (symbol-name symbol)) | 443 | (name (symbol-name symbol)) |
| 339 | (color (substring name 3))) | 444 | (color (substring name 3))) |
| 340 | (cond ((string-match "^fg:" name) | 445 | (cond ((string-match "^fg:" name) |
| 341 | (set-face-foreground face color) | 446 | (set-face-foreground face color) |
| 342 | (and (eq 'x window-system) (x-color-defined-p color))) | 447 | (and (eq 'x window-system) (x-color-defined-p color))) |
| 343 | ((string-match "^bg:" name) | 448 | ((string-match "^bg:" name) |
| 344 | (set-face-background face color) | 449 | (set-face-background face color) |
| 345 | (and (eq 'x window-system) (x-color-defined-p color))) | 450 | (and (eq 'x window-system) (x-color-defined-p color))) |
| 346 | (t))))) | 451 | (t)))) |
| 452 | symbol)) | ||
| 347 | 453 | ||
| 348 | (defun facemenu-add-new-face (face) | 454 | (defun facemenu-add-new-face (face) |
| 349 | "Add a FACE to the appropriate Face menu. | 455 | "Add a FACE to the appropriate Face menu. |
| @@ -351,25 +457,37 @@ Automatically called when a new face is created." | |||
| 351 | (let* ((name (symbol-name face)) | 457 | (let* ((name (symbol-name face)) |
| 352 | (menu (cond ((string-match "^fg:" name) | 458 | (menu (cond ((string-match "^fg:" name) |
| 353 | (setq name (substring name 3)) | 459 | (setq name (substring name 3)) |
| 354 | facemenu-foreground-menu) | 460 | 'facemenu-foreground-menu) |
| 355 | ((string-match "^bg:" name) | 461 | ((string-match "^bg:" name) |
| 356 | (setq name (substring name 3)) | 462 | (setq name (substring name 3)) |
| 357 | facemenu-background-menu) | 463 | 'facemenu-background-menu) |
| 358 | (t facemenu-face-menu))) | 464 | (t 'facemenu-face-menu))) |
| 359 | key) | 465 | (key (cdr (assoc face facemenu-keybindings))) |
| 360 | (cond ((memq face facemenu-unlisted-faces) | 466 | function menu-val) |
| 361 | nil) | 467 | (cond ((eq t facemenu-unlisted-faces)) |
| 362 | ((setq key (cdr (assoc face facemenu-keybindings))) | 468 | ((memq face facemenu-unlisted-faces)) |
| 363 | (let ((function (intern (concat "facemenu-set-" name)))) | 469 | (key ; has a keyboard equivalent. These go at the front. |
| 364 | (fset function | 470 | (setq function (intern (concat "facemenu-set-" name))) |
| 365 | (` (lambda () (interactive) | 471 | (fset function |
| 366 | (facemenu-set-face (quote (, face)))))) | 472 | (` (lambda () (interactive) |
| 367 | (define-key facemenu-keymap key (cons name function)) | 473 | (facemenu-set-face (quote (, face)))))) |
| 368 | (define-key menu key (cons name function)))) | 474 | (define-key 'facemenu-keymap key (cons name function)) |
| 369 | (t (define-key menu (vector face) | 475 | (define-key menu key (cons name function))) |
| 370 | (cons name 'facemenu-set-face-from-menu))))) | 476 | ((facemenu-iterate ; check if equivalent face is already in the menu |
| 371 | ;; Return nil for facemenu-iterate's benefit: | 477 | (lambda (m) (and (listp m) |
| 372 | nil) | 478 | (symbolp (car m)) |
| 479 | (face-equal (car m) face))) | ||
| 480 | (cdr (symbol-function menu)))) | ||
| 481 | (t ; No keyboard equivalent. Figure out where to put it: | ||
| 482 | (setq key (vector face) | ||
| 483 | function 'facemenu-set-face-from-menu | ||
| 484 | menu-val (symbol-function menu)) | ||
| 485 | (if (and facemenu-new-faces-at-end | ||
| 486 | (> (length menu-val) 3)) | ||
| 487 | (define-key-after menu-val key (cons name function) | ||
| 488 | (car (nth (- (length menu-val) 3) menu-val))) | ||
| 489 | (define-key menu key (cons name function)))))) | ||
| 490 | nil) ; Return nil for facemenu-iterate | ||
| 373 | 491 | ||
| 374 | (defun facemenu-after-change (begin end old-length) | 492 | (defun facemenu-after-change (begin end old-length) |
| 375 | "May set the face of just-inserted text to user's request. | 493 | "May set the face of just-inserted text to user's request. |