(cpp-create-bg-face): Don't really make a face.
[bpt/emacs.git] / lisp / progmodes / cpp.el
index 78a11ac..618e5f2 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 1994, 1995 Free Software Foundation
 
-;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
+;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
 ;; Keywords: c, faces, tools
 
 ;; This file is part of GNU Emacs.
@@ -18,8 +18,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 ;;; Code:
 
 ;;; Customization:
-
-(defvar cpp-config-file (convert-standard-filename ".cpp.el")
-  "*File name to save cpp configuration.")
-
-(defvar cpp-known-face 'invisible
-  "*Face used for known cpp symbols.")
-
-(defvar cpp-unknown-face 'highlight
-  "*Face used for unknown cpp cymbols.")
-
-(defvar cpp-face-type 'light 
+(defgroup cpp nil
+  "Highlight or hide text according to cpp conditionals."
+  :group 'C
+  :prefix "cpp-")
+
+(defcustom cpp-config-file (convert-standard-filename ".cpp.el")
+  "*File name to save cpp configuration."
+  :type 'file
+  :group 'cpp)
+
+(defcustom cpp-known-face 'invisible
+  "*Face used for known cpp symbols."
+  :type 'face
+  :group 'cpp)
+
+(defcustom cpp-unknown-face 'highlight
+  "*Face used for unknown cpp symbols."
+  :type 'face
+  :group 'cpp)
+
+(defcustom cpp-face-type 'light 
   "*Indicate what background face type you prefer.
 Can be either light or dark for color screens, mono for monochrome
-screens, and none if you don't use a window system.")
-
-(defvar cpp-known-writable t
-  "*Non-nil means you are allowed to modify the known conditionals.")
-
-(defvar cpp-unknown-writable t
-  "*Non-nil means you are allowed to modify the unknown conditionals.")
-
-(defvar cpp-edit-list nil
+screens, and none if you don't use a window system."
+  :options '(light dark mono nil)
+  :type 'symbol
+  :group 'cpp)
+
+(defcustom cpp-known-writable t
+  "*Non-nil means you are allowed to modify the known conditionals."
+  :type 'boolean
+  :group 'cpp)
+
+(defcustom cpp-unknown-writable t
+  "*Non-nil means you are allowed to modify the unknown conditionals."
+  :type 'boolean
+  :group 'cpp)
+
+(defcustom cpp-edit-list nil
   "Alist of cpp macros and information about how they should be displayed.
 Each entry is a list with the following elements:
 0. The name of the macro (a string).
 1. Face used for text that is `ifdef' the macro.
 2. Face used for text that is `ifndef' the macro.
-3. `t', `nil', or `both' depending on what text may be edited.")
+3. `t', `nil', or `both' depending on what text may be edited."
+  :type '(repeat (list string face face
+                      (choice (const t)
+                              (const nil)
+                              (const both))))
+  :group 'cpp)
 
 (defvar cpp-overlay-list nil)
 ;; List of cpp overlays active in the current buffer.
@@ -107,45 +130,63 @@ Each entry is a list with the following elements:
     ("true" . t)
     ("both" . both)))
 
-(defvar cpp-face-default-list nil
-  "List of faces you can choose from for cpp conditionals.")
+(defcustom cpp-face-default-list nil
+  "Alist of faces you can choose from for cpp conditionals.
+Each element has the form (STRING . FACE), where STRING
+serves as a name (for `cpp-highlight-buffer' only)
+and FACE is either a face (a symbol)
+or a cons cell (background-color . COLOR)."
+  :type '(repeat (cons string (choice face (cons (const background-color) string))))
+  :group 'cpp)
 
-(defvar cpp-face-light-name-list
+(defcustom cpp-face-light-name-list
   '("light gray" "light blue" "light cyan" "light yellow" "light pink"
     "pale green" "beige" "orange" "magenta" "violet" "medium purple"
     "turquoise")
-  "Background colours useful with dark foreground colors.")
+  "Background colours useful with dark foreground colors."
+  :type '(repeat string)
+  :group 'cpp)
 
-(defvar cpp-face-dark-name-list
+(defcustom cpp-face-dark-name-list
   '("dim gray" "blue" "cyan" "yellow" "red"
     "dark green" "brown" "dark orange" "dark khaki" "dark violet" "purple"
     "dark turquoise")
-  "Background colours useful with light foreground colors.")
-
-(defvar cpp-face-light-list nil
-  "Alist of names and faces to be used for light backgrounds.")
-
-(defvar cpp-face-dark-list nil
-  "Alist of names and faces to be used for dark backgrounds.")
-
-(defvar cpp-face-mono-list
-  '(("bold" . 'bold)
-    ("bold-italic" . 'bold-italic)
-    ("italic" . 'italic)
-    ("underline" . 'underline))
-  "Alist of names and faces to be used for monocrome screens.")
-
-(defvar cpp-face-none-list
+  "Background colours useful with light foreground colors."
+  :type '(repeat string)
+  :group 'cpp)
+
+(defcustom cpp-face-light-list nil
+  "Alist of names and faces to be used for light backgrounds."
+  :type '(repeat (cons string face))
+  :group 'cpp)
+
+(defcustom cpp-face-dark-list nil
+  "Alist of names and faces to be used for dark backgrounds."
+  :type '(repeat (cons string face))
+  :group 'cpp)
+
+(defcustom cpp-face-mono-list
+  '(("bold" . bold)
+    ("bold-italic" . bold-italic)
+    ("italic" . italic)
+    ("underline" . underline))
+  "Alist of names and faces to be used for monochrome screens."
+  :type '(repeat (cons string face))
+  :group 'cpp)
+
+(defcustom cpp-face-none-list
    '(("default" . default)
      ("invisible" . invisible))
-   "Alist of names and faces available even if you don't use a window system.")
+   "Alist of names and faces available even if you don't use a window system."
+  :type '(repeat (cons string face))
+  :group 'cpp)
 
 (defvar cpp-face-all-list
   (append cpp-face-light-list
          cpp-face-dark-list
          cpp-face-mono-list
          cpp-face-none-list)
-  "All faces used for highligting text inside cpp conditionals.")
+  "All faces used for highlighting text inside cpp conditionals.")
 
 ;;; Parse Buffer:
 
@@ -167,6 +208,9 @@ This command pops up a buffer which you should edit to specify
 what kind of highlighting to use, and the criteria for highlighting.
 A prefix arg suppresses display of that buffer."
   (interactive "P")
+  (unless (or (eq t buffer-invisibility-spec)
+             (memq 'cpp buffer-invisibility-spec))
+    (add-to-invisibility-spec 'cpp))
   (setq cpp-parse-symbols nil)
   (cpp-parse-reset)
   (if (null cpp-edit-list)
@@ -279,7 +323,7 @@ A prefix arg suppresses display of that buffer."
 
 (defun cpp-parse-error (error)
   ;; Error message issued by the cpp parser.
-  (error (concat error " at line %d") (count-lines (point-min) (point))))
+  (error "%s at line %d" error (count-lines (point-min) (point))))
 
 (defun cpp-parse-reset ()
   "Reset display of cpp conditionals to normal."
@@ -331,7 +375,7 @@ A prefix arg suppresses display of that buffer."
 
 (defun cpp-make-overlay-hidden (overlay)
   ;; Make overlay hidden and intangible.
-  (overlay-put overlay 'invisible t)
+  (overlay-put overlay 'invisible 'cpp)
   (overlay-put overlay 'intangible t)
   ;; Unfortunately `intangible' is not implemented for overlays yet,
   ;; so we make is read-only instead.
@@ -509,7 +553,10 @@ You can also use the keyboard accelerators indicated like this: [K]ey."
 (defun cpp-edit-load ()
   "Load cpp configuration."
   (interactive)
-  (cond ((file-readable-p cpp-config-file)
+  (cond ((null init-file-user)
+        ;; If -q was specified, don't load any init files.
+        nil)
+       ((file-readable-p cpp-config-file)
         (load-file cpp-config-file))
        ((file-readable-p (concat "~/" cpp-config-file))
         (load-file cpp-config-file)))
@@ -517,7 +564,7 @@ You can also use the keyboard accelerators indicated like this: [K]ey."
       (cpp-edit-reset)))
 
 (defun cpp-edit-save ()
-  "Load cpp configuration."
+  "Save the current cpp configuration in a file."
   (interactive)
   (require 'pp)
   (save-excursion
@@ -746,10 +793,7 @@ BRANCH should be either nil (false branch), t (true branch) or 'both."
 
 (defun cpp-create-bg-face (color)
   ;; Create entry for face with background COLOR.
-  (let ((name (intern (concat "cpp " color))))
-    (make-face name)
-    (set-face-background name color)
-    (cons color name)))
+  (cons color (cons 'background-color color)))
 
 (cpp-choose-default-face (if window-system cpp-face-type 'none))