]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/generic.el
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-13
[gnu-emacs] / lisp / emacs-lisp / generic.el
index 6851faeddd64a2a1b265e9b38edb042b60e2c596..e52072e9db113206652e82737d6b0511889e3e26 100644 (file)
@@ -1,6 +1,7 @@
 ;;; generic.el --- defining simple major modes with comment and font-lock
 ;;
-;; Copyright (C) 1997, 1999, 2004, 2005 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 1999, 2002, 2003, 2004,
+;;   2005, 2006 Free Software Foundation, Inc.
 ;;
 ;; Author:  Peter Breton <pbreton@cs.umb.edu>
 ;; Created: Fri Sep 27 1996
@@ -20,8 +21,8 @@
 
 ;; 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, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;;
 ;; Each generic mode can define the following:
 ;;
-;; * List of comment-characters.  The entries in this list should be
-;;   either a character, a one or two character string or a cons pair.
-;;   If the entry is a character or a string, it is added to the
-;;   mode's syntax table with `comment-start' syntax.  If the entry is
-;;   a cons pair, the elements of the pair are considered to be
-;;   `comment-start' and `comment-end' respectively.  (The latter
-;;   should be nil if you want comments to end at end of line.)
-;;   LIMITATIONS: Emacs does not support comment strings of more than
-;;   two characters in length.
+;; * List of comment-characters.  The elements of this list should be
+;;   either a character, a one or two character string, or a cons
+;;   cell.  If the entry is a character or a string, it is added to
+;;   the mode's syntax table with "comment starter" syntax.  If the
+;;   entry is a cons cell, the `car' and `cdr' of the pair are
+;;   considered the "comment starter" and "comment ender"
+;;   respectively.  (The latter should be nil if you want comments to
+;;   end at the end of the line.)  Emacs does not support comment
+;;   strings of more than two characters in length.
 ;;
 ;; * List of keywords to font-lock.  Each keyword should be a string.
 ;;   If you have additional keywords which should be highlighted in a
 (defvar generic-font-lock-keywords nil
   "Keywords for `font-lock-defaults' in a generic mode.")
 (make-variable-buffer-local 'generic-font-lock-keywords)
-(defvaralias 'generic-font-lock-defaults 'generic-font-lock-keywords)
-(make-obsolete-variable 'generic-font-lock-defaults 'generic-font-lock-keywords "22.1")
+(define-obsolete-variable-alias 'generic-font-lock-defaults 'generic-font-lock-keywords "22.1")
 
 ;;;###autoload
 (defvar generic-mode-list nil
@@ -117,44 +117,37 @@ instead (which see).")
 ;;;###autoload
 (defmacro define-generic-mode (mode comment-list keyword-list
                                    font-lock-list auto-mode-list
-                                   function-list &optional docstring
-                                   &rest custom-keyword-args)
+                                   function-list &optional docstring)
   "Create a new generic mode MODE.
 
-MODE is the name of the command for the generic mode; it need not
-be quoted.  The optional DOCSTRING is the documentation for the
-mode command.  If you do not supply it, a default documentation
-string will be used instead.
+MODE is the name of the command for the generic mode; don't quote it.
+The optional DOCSTRING is the documentation for the mode command.  If
+you do not supply it, `define-generic-mode' uses a default
+documentation string instead.
 
-COMMENT-LIST is a list, whose entries are either a single
-character, a one or two character string or a cons pair.  If the
-entry is a character or a string, it is added to the mode's
-syntax table with `comment-start' syntax.  If the entry is a cons
-pair, the elements of the pair are considered to be
-`comment-start' and `comment-end' respectively.  (The latter
-should be nil if you want comments to end at end of line.)  Note
-that Emacs has limitations regarding comment characters.
+COMMENT-LIST is a list in which each element is either a character, a
+string of one or two characters, or a cons cell.  A character or a
+string is set up in the mode's syntax table as a \"comment starter\".
+If the entry is a cons cell, the `car' is set up as a \"comment
+starter\" and the `cdr' as a \"comment ender\".  (Use nil for the
+latter if you want comments to end at the end of the line.)  Note that
+the syntax table has limitations about what comment starters and
+enders are actually possible.
 
 KEYWORD-LIST is a list of keywords to highlight with
 `font-lock-keyword-face'.  Each keyword should be a string.
 
-FONT-LOCK-LIST is a list of additional expressions to highlight.
-Each entry in the list should have the same form as an entry in
+FONT-LOCK-LIST is a list of additional expressions to highlight.  Each
+element of this list should have the same form as an element of
 `font-lock-keywords'.
 
 AUTO-MODE-LIST is a list of regular expressions to add to
-`auto-mode-alist'.  These regexps are added to `auto-mode-alist'
-as soon as `define-generic-mode' is called.
+`auto-mode-alist'.  These regular expressions are added when Emacs
+runs the macro expansion.
 
-FUNCTION-LIST is a list of functions to call to do some
-additional setup.
-
-The optional CUSTOM-KEYWORD-ARGS are pairs of keywords and
-values.  They will be passed to the generated `defcustom' form of
-the mode hook variable MODE-hook.  Defaults to MODE without the
-possible trailing \"-mode\".  (This default may not be a valid
-customization group defined with `defgroup'.  Make sure it is.)
-You can specify keyword arguments without specifying a docstring.
+FUNCTION-LIST is a list of functions to call to do some additional
+setup.  The mode command calls these functions just before it runs the
+mode hook `MODE-hook'.
 
 See the file generic-x.el for some examples of `define-generic-mode'."
   (declare (debug (sexp def-form def-form def-form form def-form
@@ -165,22 +158,9 @@ See the file generic-x.el for some examples of `define-generic-mode'."
   (when (eq (car-safe mode) 'quote)
     (setq mode (eval mode)))
 
-  (when (and docstring (not (stringp docstring)))
-    ;; DOCSTRING is not a string so we assume that it's actually the
-    ;; first keyword of CUSTOM-KEYWORD-ARGS.
-    (push docstring custom-keyword-args)
-    (setq docstring nil))
-
   (let* ((name (symbol-name mode))
         (pretty-name (capitalize (replace-regexp-in-string
-                                  "-mode\\'" "" name)))
-        (mode-hook (intern (concat name "-hook"))))
-
-    (unless (plist-get custom-keyword-args :group)
-      (setq custom-keyword-args
-           (plist-put custom-keyword-args 
-                      :group `',(intern (replace-regexp-in-string
-                                         "-mode\\'" "" name)))))
+                                  "-mode\\'" "" name))))
 
     `(progn
        ;; Add a new entry.
@@ -190,15 +170,11 @@ See the file generic-x.el for some examples of `define-generic-mode'."
        (dolist (re ,auto-mode-list)
         (add-to-list 'auto-mode-alist (cons re ',mode)))
 
-       (defcustom ,mode-hook nil
-        ,(concat "Hook run when entering " pretty-name " mode.")
-        :type 'hook
-        ,@custom-keyword-args)
-
        (defun ,mode ()
         ,(or docstring
              (concat pretty-name " mode.\n"
-                     "This a generic mode defined with `define-generic-mode'."))
+                     "This a generic mode defined with `define-generic-mode'.\n"
+                     "It runs `" name "-hook' as the last thing it does."))
         (interactive)
         (generic-mode-internal ',mode ,comment-list ,keyword-list
                                ,font-lock-list ,function-list)))))
@@ -226,7 +202,7 @@ See the file generic-x.el for some examples of `define-generic-mode'."
     (when keyword-list
       (push (concat "\\_<" (regexp-opt keyword-list t) "\\_>")
            generic-font-lock-keywords))
-    (setq font-lock-defaults '(generic-font-lock-keywords nil))
+    (setq font-lock-defaults '(generic-font-lock-keywords))
 
     ;; Call a list of functions
     (mapcar 'funcall function-list)