@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
-@c Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003
+@c Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/modes
@node Modes, Documentation, Keymaps, Top
@cindex Fundamental mode
Major modes specialize Emacs for editing particular kinds of text.
-Each buffer has only one major mode at a time.
+Each buffer has only one major mode at a time. For each major mode
+there is a function to switch to that mode in the current buffer; its
+name should end in @samp{-mode}. These functions work by setting
+buffer-local variable bindings and other data associated with the
+buffer, such as a local keymap. The effect lasts until you switch
+to another major mode in the same buffer.
The least specialized major mode is called @dfn{Fundamental mode}.
This mode has no mode-specific definitions or variable settings, so each
parent argument, since it automatically enforces the most important
coding conventions for you.
+@findex define-generic-mode
+ For a very simple programming language major mode that handles
+comments and fontification, you can use @code{define-generic-mode}
+in @file{generic.el}.
+
Rmail Edit mode offers an example of changing the major mode
temporarily for a buffer, so it can be edited in a different way (with
ordinary Emacs commands rather than Rmail commands). In such cases, the
* Example Major Modes:: Text mode and Lisp modes.
* Auto Major Mode:: How Emacs chooses the major mode automatically.
* Mode Help:: Finding out how to use a mode.
-* Derived Modes:: Defining a new major mode based on another major
+* Derived Modes:: Defining a new major mode based on another major
mode.
@end menu
would affect buffers that do not use this mode. It is undesirable for a
mode to have such global effects. @xref{Buffer-Local Variables}.
-With rare exceptions, the only reasonable way to use
+With rare exceptions, the only reasonable way to use
@code{make-variable-buffer-local} in a Lisp package is for a variable
which is used only within that package. Using it on a variable used by
other packages would interfere with them.
major mode command symbol should have a property named @code{mode-class}
with value @code{special}, put on as follows:
-@cindex @code{mode-class} property
+@kindex mode-class @r{(property)}
@cindex @code{special}
@example
(put 'funny-mode 'mode-class 'special)
@smallexample
@group
;; @r{Create mode-specific tables.}
-(defvar text-mode-syntax-table nil
+(defvar text-mode-syntax-table nil
"Syntax table used while in text mode.")
@end group
@smallexample
@group
;; @r{Create mode-specific table variables.}
-(defvar lisp-mode-syntax-table nil "")
+(defvar lisp-mode-syntax-table nil "")
(defvar emacs-lisp-mode-syntax-table nil "")
(defvar lisp-mode-abbrev-table nil "")
@end group
;; @r{Set syntax of chars up to 0 to class of chars that are}
;; @r{part of symbol names but not words.}
;; @r{(The number 0 is @code{48} in the @sc{ascii} character set.)}
- (while (< i ?0)
+ (while (< i ?0)
(modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
(setq i (1+ i)))
@dots{}
@end smallexample
Finally, here is the complete major mode function definition for
-Lisp mode.
+Lisp mode.
@smallexample
@group
How Major Modes are Chosen, emacs, The GNU Emacs Manual}.
@end defun
-@defopt default-major-mode
+@defopt default-major-mode
This variable holds the default major mode for new buffers. The
standard value is @code{fundamental-mode}.
@end group
@group
("\\.el\\'" . emacs-lisp-mode)
- ("\\.c\\'" . c-mode)
+ ("\\.c\\'" . c-mode)
("\\.h\\'" . c-mode)
@dots{})
@end group
@smallexample
@group
(setq auto-mode-alist
- (append
+ (append
;; @r{File name (within directory) starts with a dot.}
- '(("/\\.[^/]*\\'" . fundamental-mode)
+ '(("/\\.[^/]*\\'" . fundamental-mode)
;; @r{File name has no dot.}
- ("[^\\./]*\\'" . fundamental-mode)
+ ("[^\\./]*\\'" . fundamental-mode)
;; @r{File name ends in @samp{.C}.}
("\\.C\\'" . c++-mode))
auto-mode-alist))
The new command @var{variant} is defined to call the function
@var{parent}, then override certain aspects of that parent mode:
-@itemize @bullet
+@itemize @bullet
@item
The new mode has its own keymap, named @code{@var{variant}-map}.
@code{define-derived-mode} initializes this map to inherit from
@item
The new mode has its own syntax table, kept in the variable
@code{@var{variant}-syntax-table}.
-@code{define-derived-mode} initializes this variable by copying
+@code{define-derived-mode} initializes this variable by copying
@code{@var{parent}-syntax-table}, if it is not already set.
@item
The new mode has its own abbrev table, kept in the variable
@code{@var{variant}-abbrev-table}.
-@code{define-derived-mode} initializes this variable by copying
+@code{define-derived-mode} initializes this variable by copying
@code{@var{parent}-abbrev-table}, if it is not already set.
@item
The new mode has its own mode hook, @code{@var{variant}-hook},
which it runs in standard fashion as the very last thing that it does.
-(The new mode also runs the mode hook of @var{parent} as part
+(The new mode also runs the mode hook of @var{parent} as part
of calling @var{parent}.)
@end itemize
In addition, you can specify how to override other aspects of
@var{parent} with @var{body}. The command @var{variant}
-evaluates the forms in @var{body} after setting up all its usual
+evaluates the forms in @var{body} after setting up all its usual
overrides, just before running @code{@var{variant}-hook}.
The argument @var{docstring} specifies the documentation string for the
@smallexample
(define-minor-mode hungry-mode
"Toggle Hungry mode.
-With no argument, this command toggles the mode.
+With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.
Null prefix argument turns off the mode.
;; The minor mode bindings.
'(("\C-\^?" . hungry-electric-delete)
("\C-\M-\^?"
- . (lambda ()
+ . (lambda ()
(interactive)
(hungry-electric-delete t)))))
@end smallexample
window is scrolled. @code{header-line-format} is used likewise for
header lines.
- The mode line and header line of a window are normally updated
-whenever a different buffer is shown in the window, or when the buffer's
-modified-status changes from @code{nil} to @code{t} or vice-versa. If
-you modify any of the variables referenced by @code{mode-line-format}
-(@pxref{Mode Line Variables}), or any other variables and data
-structures that affect how text is displayed (@pxref{Display}), you may
-want to force an update of the mode line so as to display the new
-information or display it in the new way.
+ For efficiency, Emacs does not recompute the mode line and header
+line of a window in every redisplay. It does so when circumstances
+appear to call for it---for instance, if you change the window
+configuration, switch buffers, narrow or widen the buffer, scroll, or
+change the buffer's modification status. If you modify any of the
+variables referenced by @code{mode-line-format} (@pxref{Mode Line
+Variables}), or any other variables and data structures that affect
+how text is displayed (@pxref{Display}), you may want to force an
+update of the mode line so as to display the new information or
+display it in the new way.
@c Emacs 19 feature
@defun force-mode-line-update
Force redisplay of the current buffer's mode line and header line.
+The next redisplay will update the mode line and header line based on
+the latest values of all relevant variables.
+
+This function also forces recomputation of the menu bar menus
+and the frame title.
@end defun
The mode line is usually displayed in inverse video; see
@code{mode-line-inverse-video} in @ref{Inverse Video}.
+ A window that is just one line tall does not display either a mode
+line or a header line, even if the variables call for one. A window
+that is two lines tall cannot display both a mode line and a header
+line at once; if the variables call for both, only the mode line
+actually appears.
+
@menu
* Mode Line Data:: The data structure that controls the mode line.
* Mode Line Variables:: Variables used in that data structure.
'mode-line-mule-info
'mode-line-modified
'mode-line-frame-identification
- "%b--"
+ "%b--"
@end group
@group
;; @r{Note that this is evaluated while making the list.}
;; @r{It makes a mode line construct which is just a string.}
(getenv "HOST")
@end group
- ":"
+ ":"
'default-directory
" "
'global-mode-string
" %[("
'(:eval (mode-line-mode-name))
- 'mode-line-process
- 'minor-mode-alist
- "%n"
+ 'mode-line-process
+ 'minor-mode-alist
+ "%n"
")%]--"
@group
'(which-func-mode ("" which-func-format "--"))
@group
minor-mode-alist
@result{} ((vc-mode vc-mode)
- (abbrev-mode " Abbrev")
- (overwrite-mode overwrite-mode)
- (auto-fill-function " Fill")
+ (abbrev-mode " Abbrev")
+ (overwrite-mode overwrite-mode)
+ (auto-fill-function " Fill")
(defining-kbd-macro " Def")
(isearch-mode isearch-mode))
@end group
;; @r{properties to make it mouse-sensitive.}
(:eval (mode-line-mode-name))
mode-line-process
- minor-mode-alist
- "%n"
+ minor-mode-alist
+ "%n"
")%]--"
@end group
@group
If this variable is non-@code{nil}, its value should be a function that
finds the next ``definition'' to put in the buffer index, scanning
backward in the buffer from point. It should return @code{nil} if it
-doesn't find another ``definition'' before point. Otherwise it shuould
+doesn't find another ``definition'' before point. Otherwise it should
leave point at the place it finds a ``definition,'' and return any
non-@code{nil} value.
* Search-based Fontification::
* Other Font Lock Variables::
* Levels of Font Lock::
+* Precalculated Fontification::
* Faces for Font Lock::
* Syntactic Font Lock::
@end menu
it finds using @code{font-lock-keyword-face}.
When @var{function} is called, it receives one argument, the limit of
-the search. It should return non-@code{nil} if it succeeds, and set the
-match data to describe the match that was found.
+the search; it should searching at point, and not search beyond the
+limit. It should return non-@code{nil} if it succeeds, and set the
+match data to describe the match that was found. Returning @code{nil}
+indicates failure of the search.
+
+Fontification will call @var{function} repeatedly with the same limit,
+and with point where the previous invocation left it, until
+@var{function} fails. On failure, @var{function} need not reset point
+in any particular way.
@item (@var{matcher} . @var{match})
In this kind of element, @var{matcher} is either a regular
wherever they appear.
@end itemize
+@node Precalculated Fontification
+@subsection Precalculated Fontification
+
+In addition to using @code{font-lock-defaults} for search-based
+fontification, you may use the special character property
+@code{font-lock-face} (@pxref{Special Properties}). This property
+acts just like the explicit @code{face} property, but its activation
+is toggled when the user calls @kbd{M-x font-lock-mode}. Using
+@code{font-lock-face} is especially conveninent for special modes
+which construct their text programmatically, such as
+@code{list-buffers} and @code{occur}.
+
+If your mode does not use any of the other machinery of Font Lock
+(i.e. it only uses the @code{font-lock-face} property), you can tell
+Emacs not to load all of font-lock.el (unless it's already loaded), by
+setting the variable @code{font-lock-core-only} to non-nil as part of
+the @code{font-lock-defaults} settings. Here is the canonical way to
+do this:
+
+@example
+(set (make-local-variable 'font-lock-defaults)
+ '(nil t nil nil nil (font-lock-core-only . t)))
+@end example
+
@node Faces for Font Lock
@subsection Faces for Font Lock
@item font-lock-function-name-face
@vindex font-lock-function-name-face
Used (typically) for the name of a function being defined or declared,
-in a function definition or declaration.
+in a function definition or declaration.
@item font-lock-variable-name-face
@vindex font-lock-variable-name-face
table by itself is not sufficient.
@defvar font-lock-syntactic-keywords
-This variable enables and controls syntactic Font Lock. Its value
-should be a list of elements of this form:
+This variable enables and controls syntactic Font Lock. It is
+normally set via @code{font-lock-defaults}. Its value should be a
+list of elements of this form:
@example
(@var{matcher} @var{subexp} @var{syntax} @var{override} @var{laxmatch})
@end example
However, instead of specifying the value @var{facename} to use for the
-@code{face} property, it specifies the value @var{syntax} to use for the
-@code{syntax-table} property. Here, @var{syntax} can be a variable
-whose value is a syntax table, a syntax entry of the form
-@code{(@var{syntax-code} . @var{matching-char})}, or an expression whose
-value is one of those two types.
+@code{face} property, it specifies the value @var{syntax} to use for
+the @code{syntax-table} property. Here, @var{syntax} can be a string
+(as taken by @code{modify-syntax-entry}), a syntax table, a cons cell
+(as returned by @code{string-to-syntax}), or an expression whose value
+is one of those two types. @var{override} cannot be @code{prepend} or
+@code{append}.
+
+For example, an element of the form:
+
+@example
+("\\$\\(#\\)" 1 ".")
+@end example
+
+highlights syntactically a hash character when following a dollar
+character, with a SYNTAX of @code{"."} (meaning punctuation syntax).
+Assuming that the buffer syntax table specifies hash characters to
+have comment start syntax, the element will only highlight hash
+characters that do not follow dollar characters as comments
+syntactically.
+
+An element of the form:
+
+@example
+ ("\\('\\).\\('\\)"
+ (1 "\"")
+ (2 "\""))
+@end example
+
+highlights syntactically both single quotes which surround a single
+character, with a SYNTAX of @code{"\""} (meaning string quote syntax).
+Assuming that the buffer syntax table does not specify single quotes
+to have quote syntax, the element will only highlight single quotes of
+the form @samp{'@var{c}'} as strings syntactically. Other forms, such
+as @samp{foo'bar} or @samp{'fubar'}, will not be highlighted as
+strings.
+
@end defvar
@node Hooks
these functions are called with arguments or their values are used in
some way. You can use @code{add-hook} to add a function to the list,
but you must take care in writing the function. (A few of these
-variables are actually normal hooks which were named before we
-established the convention of using @samp{-hook} for them.)
+variables, notably those ending in @samp{-hooks}, are actually
+normal hooks which were named before we established the convention of
+using @samp{-hook} for them.)
If the variable's name ends in @samp{-function}, then its value
is just a single function, not a list of functions.
argument @var{append} is non-@code{nil}, the new hook function goes at
the end of the hook list and will be executed last.
-If @var{local} is non-@code{nil}, that says to make the new hook
-function buffer-local in the current buffer and automatically calls
-@code{make-local-hook} to make the hook itself buffer-local.
+If @var{local} is non-@code{nil}, that says to add @var{function}
+to the buffer-local hook list instead of to the global hook list.
@end defun
@defun remove-hook hook function &optional local
If @var{local} is non-@code{nil}, that says to remove @var{function}
from the buffer-local hook list instead of from the global hook list.
-If the hook variable itself is not buffer-local, then the value of
-@var{local} makes no difference.
-@end defun
-
-@defun make-local-hook hook
-This function makes the hook variable @code{hook} buffer-local in the
-current buffer. When a hook variable is buffer-local, it can have
-buffer-local and global hook functions, and @code{run-hooks} runs all of
-them.
-
-This function works by adding @code{t} as an element of the buffer-local
-value. That serves as a flag to use the hook functions listed in the default
-value of the hook variable, as well as those listed in the buffer-local value.
-Since @code{run-hooks} understands this flag, @code{make-local-hook}
-works with all normal hooks. It works for only some non-normal
-hooks---those whose callers have been updated to understand this meaning
-of @code{t}.
-
-Do not use @code{make-local-variable} directly for hook variables; it is
-not sufficient.
@end defun