Function: define-generic-mode

define-generic-mode is an autoloaded macro defined in generic.el.gz.

Signature

(define-generic-mode MODE COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST FUNCTION-LIST &optional DOCSTRING)

Documentation

Create a new generic mode MODE.

A "generic" mode is a simple major mode with basic support for comment syntax and Font Lock mode, but otherwise does not have any special keystrokes or functionality available.

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 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 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 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 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.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/generic.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;###autoload
(defmacro define-generic-mode (mode comment-list keyword-list
				    font-lock-list auto-mode-list
				    function-list &optional docstring)
  "Create a new generic mode MODE.

A \"generic\" mode is a simple major mode with basic support for
comment syntax and Font Lock mode, but otherwise does not have
any special keystrokes or functionality available.

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 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
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 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 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
			[&optional stringp] &rest [keywordp form]))
	   (indent 1)
           (doc-string 7)
           (autoload-macro expand))

  ;; Backward compatibility.
  (when (eq (car-safe mode) 'quote)
    (setq mode (eval mode t)))

  (let* ((name (symbol-name mode))
	 (pretty-name (capitalize (replace-regexp-in-string
				   "-mode\\'" "" name))))

    `(progn
       (progn
         :autoload-end

         ;; Add a new entry.
         (add-to-list 'generic-mode-list ,name)

         ;; Add it to auto-mode-alist
         (dolist (re ,auto-mode-list)
	   (add-to-list 'auto-mode-alist (cons re ',mode))))

       (defun ,mode ()
	 ,(or docstring
	      (concat pretty-name " mode.\n"
		      "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)))))