Fix up coding system.
[bpt/emacs.git] / lisp / facemenu.el
index 220b0f1..6586b77 100644 (file)
 ;;      (italic      . [?\H-i])
 ;;      (bold-italic . [?\H-l])
 ;;      (underline   . [?\H-u])))
+;;   (facemenu-update)
 ;;   (setq facemenu-keymap global-map)
-;;   (setq facemenu-key nil)
 ;;   (define-key global-map [?\H-c] 'facemenu-set-foreground) ; set fg color
 ;;   (define-key global-map [?\H-C] 'facemenu-set-background) ; set bg color
-;;   (require 'facemenu)
 ;;
 ;; The order of the faces that appear in the menu and their keybindings can be
 ;; controlled by setting the variables `facemenu-keybindings' and
 ;;; Provide some binding for startup:
 ;;;###autoload (define-key global-map "\M-g" 'facemenu-keymap)
 ;;;###autoload (autoload 'facemenu-keymap "facemenu" "Keymap for face-changing commands." t 'keymap)
+  
+;; Global bindings:
+(define-key global-map [C-down-mouse-2] 'facemenu-menu)
+(define-key global-map "\M-g" 'facemenu-keymap)
 
-(defvar facemenu-key "\M-g"
-  "Prefix key to use for facemenu commands.")
+(defgroup facemenu nil
+  "Create a face menu for interactively adding fonts to text"
+  :group 'faces
+  :prefix "facemenu-")
 
-(defvar facemenu-keybindings
+(defcustom facemenu-keybindings
   '((default     . "d")
     (bold        . "b")
     (italic      . "i")
   "Alist of interesting faces and keybindings. 
 Each element is itself a list: the car is the name of the face,
 the next element is the key to use as a keyboard equivalent of the menu item;
-the binding is made in facemenu-keymap.
+the binding is made in `facemenu-keymap'.
 
 The faces specifically mentioned in this list are put at the top of
 the menu, in the order specified.  All other faces which are defined,
@@ -119,16 +124,20 @@ except for those in `facemenu-unlisted-faces', are listed after them,
 but get no keyboard equivalents.
 
 If you change this variable after loading facemenu.el, you will need to call
-`facemenu-update' to make it take effect.")
+`facemenu-update' to make it take effect."
+  :type '(repeat (cons face string))
+  :group 'facemenu)
 
-(defvar facemenu-new-faces-at-end t
-  "Where in the menu to insert newly-created faces.
+(defcustom facemenu-new-faces-at-end t
+  "*Where in the menu to insert newly-created faces.
 This should be nil to put them at the top of the menu, or t to put them
-just before \"Other\" at the end.")
+just before \"Other\" at the end."
+  :type 'boolean
+  :group 'facemenu)
 
-(defvar facemenu-unlisted-faces
+(defcustom facemenu-unlisted-faces
   '(modeline region secondary-selection highlight scratch-face)
-  "List of faces not to include in the Face menu.
+  "*List of faces not to include in the Face menu.
 You can set this list before loading facemenu.el, or add a face to it before
 creating that face if you do not want it to be listed.  If you change the
 variable so as to eliminate faces that have already been added to the menu,
@@ -136,7 +145,11 @@ call `facemenu-update' to recalculate the menu contents.
 
 If this variable is t, no faces will be added to the menu.  This is useful for
 temporarily turning off the feature that automatically adds faces to the menu
-when they are created.")
+when they are created."
+  :type '(choice (const :tag "Don't add" t)
+                (const :tag "None" nil)
+                (repeat face))
+  :group 'facemenu)
 
 ;;;###autoload
 (defvar facemenu-face-menu
@@ -242,20 +255,31 @@ requested in `facemenu-keybindings'.")
 (defalias 'facemenu-keymap facemenu-keymap)
 
 
-(defvar facemenu-add-face-function nil
+(defcustom facemenu-add-face-function nil
   "Function called at beginning of text to change or `nil'.
 This function is passed the FACE to set and END of text to change, and must
-return a string which is inserted.  It may set `facemenu-end-add-face'.")
+return a string which is inserted.  It may set `facemenu-end-add-face'."
+  :type '(choice (const :tag "None" nil)
+                function)
+  :group 'facemenu)
 
-(defvar facemenu-end-add-face nil
+(defcustom facemenu-end-add-face nil
   "String to insert or function called at end of text to change or `nil'.
 This function is passed the FACE to set, and must return a string which is
-inserted.")
-
-(defvar facemenu-remove-face-function nil
-  "When non-`nil' function called to remove faces.
+inserted."
+  :type '(choice (const :tag "None" nil)
+                string
+                function)
+  :group 'facemenu)
+
+(defcustom facemenu-remove-face-function nil
+  "When non-nil, this is a function called to remove faces.
 This function is passed the START and END of text to change.
-May also be `t' meaning to use `facemenu-add-face-function'.")
+May also be `t' meaning to use `facemenu-add-face-function'."
+  :type '(choice (const :tag "None" nil)
+                (const :tag "Use add-face" t)
+                function)
+  :group 'facemenu)
 
 ;;; Internal Variables
 
@@ -269,10 +293,6 @@ If null, `facemenu-read-color' will set it.")
 You can call this to update things if you change any of the menu configuration
 variables."
   (interactive)
-  
-  ;; Global bindings:
-  (define-key global-map [C-down-mouse-2] 'facemenu-menu)
-  (if facemenu-key (define-key global-map facemenu-key 'facemenu-keymap))
 
   ;; Add each defined face to the menu.
   (facemenu-iterate 'facemenu-add-new-face
@@ -360,7 +380,7 @@ typing a character to insert cancels the specification."
 This sets the `invisible' text property; it can be undone with
 `facemenu-remove-special'."
   (interactive "r")
-  (put-text-property start end 'invisible t))
+  (add-text-properties start end '(invisible t)))
 
 ;;;###autoload
 (defun facemenu-set-intangible (start end)
@@ -368,7 +388,7 @@ This sets the `invisible' text property; it can be undone with
 This sets the `intangible' text property; it can be undone with
 `facemenu-remove-special'."
   (interactive "r")
-  (put-text-property start end 'intangible t))
+  (add-text-properties start end '(intangible t)))
 
 ;;;###autoload
 (defun facemenu-set-read-only (start end)
@@ -376,7 +396,7 @@ This sets the `intangible' text property; it can be undone with
 This sets the `read-only' text property; it can be undone with
 `facemenu-remove-special'."
   (interactive "r")
-  (put-text-property start end 'read-only t))
+  (add-text-properties start end '(read-only t)))
 
 ;;;###autoload
 (defun facemenu-remove-props (start end)
@@ -491,7 +511,7 @@ This function queries the window-system server to find out what the
 color names mean.  It returns nil if the colors differ or if it can't
 determine the correct answer."
   (cond ((equal a b) t)
-       ((and (or (eq window-system 'x) (eq window-system 'win32))
+       ((and (memq window-system '(x w32))
              (equal (x-color-values a) (x-color-values b))))
        ((eq window-system 'pc)
         (and (x-color-defined-p a) (x-color-defined-p b)
@@ -597,22 +617,35 @@ or nil if given a bad color."
   "Add a FACE to the appropriate Face menu.
 Automatically called when a new face is created."
   (let* ((name (symbol-name face))
-        (menu (cond ((string-match "^fg:" name) 
-                     (setq name (substring name 3))
-                     'facemenu-foreground-menu)
-                    ((string-match "^bg:" name) 
-                     (setq name (substring name 3))
-                     'facemenu-background-menu)
-                    (t 'facemenu-face-menu)))
+        menu docstring
         (key (cdr (assoc face facemenu-keybindings)))
         function menu-val)
+    (cond ((string-match "^fg:" name) 
+          (setq name (substring name 3))
+          (setq docstring
+                (format "Select foreground color %s for subsequent insertion."
+                        name))
+          (setq menu 'facemenu-foreground-menu))
+         ((string-match "^bg:" name) 
+          (setq name (substring name 3))
+          (setq docstring
+                (format "Select background color %s for subsequent insertion."
+                        name))
+          (setq menu 'facemenu-background-menu))
+         (t
+          (setq docstring
+                (format "Select face `%s' for subsequent insertion."
+                        name))
+          (setq menu 'facemenu-face-menu)))
     (cond ((eq t facemenu-unlisted-faces))
          ((memq face facemenu-unlisted-faces))
          (key ; has a keyboard equivalent.  These go at the front.
           (setq function (intern (concat "facemenu-set-" name)))
           (fset function
-                (` (lambda () (interactive)
-                     (facemenu-set-face (quote (, face))))))
+                `(lambda ()
+                   ,docstring
+                   (interactive)
+                   (facemenu-set-face (quote ,face))))
           (define-key 'facemenu-keymap key (cons name function))
           (define-key menu key (cons name function)))
          ((facemenu-iterate ; check if equivalent face is already in the menu
@@ -632,7 +665,7 @@ Automatically called when a new face is created."
   nil) ; Return nil for facemenu-iterate
 
 (defun facemenu-complete-face-list (&optional oldlist)
-  "Return list of all faces that are look different.
+  "Return list of all faces that look different.
 Starts with given ALIST of faces, and adds elements only if they display 
 differently from any face already on the list.
 The faces on ALIST will end up at the end of the returned list, in reverse