comparison lisp/facemenu.el @ 71568:8d6af1c1c365

* facemenu.el (facemenu-listed-faces): New var. (facemenu-unlisted-faces): Variable deleted. (facemenu-add-new-face): Use facemenu-listed-faces.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 03 Jul 2006 14:31:35 +0000
parents 71f07d141fe2
children d6694b6039c1 138ce2701550
comparison
equal deleted inserted replaced
71567:f008b5943ba4 71568:8d6af1c1c365
65 ;; (define-key global-map [?\H-c] 'facemenu-set-foreground) ; set fg color 65 ;; (define-key global-map [?\H-c] 'facemenu-set-foreground) ; set fg color
66 ;; (define-key global-map [?\H-C] 'facemenu-set-background) ; set bg color 66 ;; (define-key global-map [?\H-C] 'facemenu-set-background) ; set bg color
67 ;; 67 ;;
68 ;; The order of the faces that appear in the menu and their keybindings can be 68 ;; The order of the faces that appear in the menu and their keybindings can be
69 ;; controlled by setting the variables `facemenu-keybindings' and 69 ;; controlled by setting the variables `facemenu-keybindings' and
70 ;; `facemenu-new-faces-at-end'. List faces that you don't use in documents 70 ;; `facemenu-new-faces-at-end'. List faces that you want to use in documents
71 ;; (eg, `region') in `facemenu-unlisted-faces'. 71 ;; in `facemenu-listed-faces'.
72 72
73 ;;; Known Problems: 73 ;;; Known Problems:
74 ;; Bold and Italic do not combine to create bold-italic if you select them 74 ;; Bold and Italic do not combine to create bold-italic if you select them
75 ;; both, although most other combinations (eg bold + underline + some color) 75 ;; both, although most other combinations (eg bold + underline + some color)
76 ;; do the intuitive thing. 76 ;; do the intuitive thing.
114 Each element is itself a list: the car is the name of the face, 114 Each element is itself a list: the car is the name of the face,
115 the next element is the key to use as a keyboard equivalent of the menu item; 115 the next element is the key to use as a keyboard equivalent of the menu item;
116 the binding is made in `facemenu-keymap'. 116 the binding is made in `facemenu-keymap'.
117 117
118 The faces specifically mentioned in this list are put at the top of 118 The faces specifically mentioned in this list are put at the top of
119 the menu, in the order specified. All other faces which are defined, 119 the menu, in the order specified. All other faces which are defined
120 except for those in `facemenu-unlisted-faces', are listed after them, 120 in `facemenu-listed-faces' are listed after them, but get no
121 but get no keyboard equivalents. 121 keyboard equivalents.
122 122
123 If you change this variable after loading facemenu.el, you will need to call 123 If you change this variable after loading facemenu.el, you will need to call
124 `facemenu-update' to make it take effect." 124 `facemenu-update' to make it take effect."
125 :type '(repeat (cons face string)) 125 :type '(repeat (cons face string))
126 :group 'facemenu) 126 :group 'facemenu)
130 This should be nil to put them at the top of the menu, or t to put them 130 This should be nil to put them at the top of the menu, or t to put them
131 just before \"Other\" at the end." 131 just before \"Other\" at the end."
132 :type 'boolean 132 :type 'boolean
133 :group 'facemenu) 133 :group 'facemenu)
134 134
135 (defcustom facemenu-unlisted-faces 135 (defcustom facemenu-listed-faces nil
136 `(modeline region secondary-selection highlight scratch-face 136 "*List of faces to include in the Face menu.
137 ,(purecopy "^font-lock-") ,(purecopy "^gnus-") ,(purecopy "^message-") 137 Each element should be a symbol, which is the name of a face.
138 ,(purecopy "^ediff-") ,(purecopy "^term-") ,(purecopy "^vc-") 138 The \"basic \" faces in `facemenu-keybindings' are automatically
139 ,(purecopy "^widget-") ,(purecopy "^custom-") ,(purecopy "^vm-")) 139 added to the Face menu, and are not included in this list.
140 "*List of faces not to include in the Face menu.
141 Each element may be either a symbol, which is the name of a face, or a string,
142 which is a regular expression to be matched against face names. Matching
143 faces will not be added to the menu.
144 140
145 You can set this list before loading facemenu.el, or add a face to it before 141 You can set this list before loading facemenu.el, or add a face to it before
146 creating that face if you do not want it to be listed. If you change the 142 creating that face if you want it to be listed. If you change the
147 variable so as to eliminate faces that have already been added to the menu, 143 variable so as to eliminate faces that have already been added to the menu,
148 call `facemenu-update' to recalculate the menu contents. 144 call `facemenu-update' to recalculate the menu contents.
149 145
150 If this variable is t, no faces will be added to the menu. This is useful for 146 If this variable is t, all faces will be added to the menu. This
151 temporarily turning off the feature that automatically adds faces to the menu 147 is useful for setting temporarily if you want to add faces to the
152 when they are created." 148 menu when they are created."
153 :type '(choice (const :tag "Don't add faces" t) 149 :type '(choice (const :tag "List all faces" t)
154 (const :tag "None (do add any face)" nil) 150 (const :tag "None" nil)
155 (repeat (choice symbol regexp))) 151 (repeat symbol))
156 :group 'facemenu) 152 :group 'facemenu
153 :version "22.1")
157 154
158 ;;;###autoload 155 ;;;###autoload
159 (defvar facemenu-face-menu 156 (defvar facemenu-face-menu
160 (let ((map (make-sparse-keymap "Face"))) 157 (let ((map (make-sparse-keymap "Face")))
161 (define-key map "o" (cons "Other..." 'facemenu-set-face)) 158 (define-key map "o" (cons "Other..." 'facemenu-set-face))
673 symbol (intern name))) 670 symbol (intern name)))
674 (setq menu 'facemenu-face-menu) 671 (setq menu 'facemenu-face-menu)
675 (setq docstring 672 (setq docstring
676 (format "Select face `%s' for subsequent insertion." 673 (format "Select face `%s' for subsequent insertion."
677 name)) 674 name))
678 (cond ((eq t facemenu-unlisted-faces)) 675 (cond ((facemenu-iterate ; check if equivalent face is already in the menu
679 ((memq symbol facemenu-unlisted-faces)) 676 (lambda (m) (and (listp m)
680 ;; test against regexps in facemenu-unlisted-faces 677 (symbolp (car m))
681 ((let ((unlisted facemenu-unlisted-faces) 678 (face-equal (car m) symbol)))
682 (matched nil)) 679 (cdr (symbol-function menu))))
683 (while (and unlisted (not matched)) 680 ;; Faces with a keyboard equivalent. These go at the front.
684 (if (and (stringp (car unlisted)) 681 (key
685 (string-match (car unlisted) name))
686 (setq matched t)
687 (setq unlisted (cdr unlisted))))
688 matched))
689 (key ; has a keyboard equivalent. These go at the front.
690 (setq function (intern (concat "facemenu-set-" name))) 682 (setq function (intern (concat "facemenu-set-" name)))
691 (fset function 683 (fset function
692 `(lambda () 684 `(lambda ()
693 ,docstring 685 ,docstring
694 (interactive) 686 (interactive)
698 (region-beginning)) 690 (region-beginning))
699 (if (and mark-active (not current-prefix-arg)) 691 (if (and mark-active (not current-prefix-arg))
700 (region-end))))) 692 (region-end)))))
701 (define-key 'facemenu-keymap key (cons name function)) 693 (define-key 'facemenu-keymap key (cons name function))
702 (define-key menu key (cons name function))) 694 (define-key menu key (cons name function)))
703 ((facemenu-iterate ; check if equivalent face is already in the menu 695 ;; Faces with no keyboard equivalent. Figure out where to put it:
704 (lambda (m) (and (listp m) 696 ((or (eq t facemenu-listed-faces)
705 (symbolp (car m)) 697 (memq symbol facemenu-listed-faces))
706 (face-equal (car m) symbol)))
707 (cdr (symbol-function menu))))
708 (t ; No keyboard equivalent. Figure out where to put it:
709 (setq key (vector symbol) 698 (setq key (vector symbol)
710 function 'facemenu-set-face-from-menu 699 function 'facemenu-set-face-from-menu
711 menu-val (symbol-function menu)) 700 menu-val (symbol-function menu))
712 (if (and facemenu-new-faces-at-end 701 (if (and facemenu-new-faces-at-end
713 (> (length menu-val) 3)) 702 (> (length menu-val) 3))
714 (define-key-after menu-val key (cons name function) 703 (define-key-after menu-val key (cons name function)
715 (car (nth (- (length menu-val) 3) menu-val))) 704 (car (nth (- (length menu-val) 3) menu-val)))
716 (define-key menu key (cons name function)))))) 705 (define-key menu key (cons name function))))))
717 nil) ; Return nil for facemenu-iterate 706 nil) ; Return nil for facemenu-iterate
718 707