File: generic.el.html

INTRODUCTION:

The macro define-generic-mode can be used to define small modes which provide basic comment and font-lock support. These modes are intended for the many configuration files and such which are too small for a "real" mode, but still have a regular syntax, comment characters and the like.

Each generic mode can define the following:

* 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 in font-lock-keyword-face.
  Each keyword should be a string.

* Additional expressions to font-lock. This should be a list of
  expressions, each of which should be of the same form as those in
  font-lock-keywords.

* List of regular expressions to be placed in auto-mode-alist.

* List of functions to call to do some additional setup

This should pretty much cover basic functionality; if you need much more than this, or you find yourself writing extensive customizations, perhaps you should be writing a major mode instead!

EXAMPLE:

You can use define-generic-mode like this:

  (define-generic-mode 'foo-generic-mode
    (list ?%)
    (list "keyword")
    nil
    (list "\\\\.FOO\\\\'")
    (list 'foo-setup-function))

to define a new generic-mode foo-generic-mode, which has '%' as a comment character, and "keyword" as a keyword. When files which end in '.FOO' are loaded, Emacs will go into foo-generic-mode and call foo-setup-function. You can also use the function foo-generic-mode (which is interactive) to put a buffer into foo-generic-mode.

GOTCHAS:

Be careful that your font-lock definitions are correct. Getting them wrong can cause Emacs to continually attempt to fontify! This problem is not specific to generic-mode.

Credit for suggestions, brainstorming, help with debugging:
  ACorreir@pervasive-sw.com (Alfred Correira)
Extensive cleanup by:
  Stefan Monnier (monnier+gnu/emacs@flint.cs.yale.edu)

Defined variables (2)

generic-font-lock-keywordsKeywords for ‘font-lock-defaults’ in a generic mode.
generic-mode-listA list of mode names for ‘generic-mode’.

Defined functions (9)

define-generic-mode(MODE COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST FUNCTION-LIST &optional DOCSTRING)
generic--normalize-comments(COMMENT-LIST)
generic-bracket-support()
generic-make-keywords-list(KEYWORD-LIST FACE &optional PREFIX SUFFIX)
generic-mode(MODE)
generic-mode-internal(MODE COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST FUNCTION-LIST)
generic-mode-set-comments(COMMENT-LIST)
generic-set-comment-syntax(ST COMMENT-LIST)
generic-set-comment-vars(COMMENT-LIST)

Defined faces (0)