comparison man/xemacs/major.texi @ 2522:52dc9b940348

[xemacs-hg @ 2005-01-28 00:12:32 by ben] cc-mode patch from Shyamal Prasad xemacs/programs.texi: Updated it to reflect current status of programming modes. xemacs/programs.texi: New section introduces CC Mode. Introduces customization with reference to CC Mode manual. Also introduce C/AWK modes in prog-modes package xemacs/programs.texi: Removed - it was obsolete. prog-modes package documentation now contains indentation description for old C mode xemacs/major.texi: Add description of major mode hooks. Cleaned up and updated programming mode descriptions. xemacs/xemacs.texi: Updated Detailed Node listing for new CC Mode section in programs.texi
author ben
date Fri, 28 Jan 2005 00:12:39 +0000
parents 3ecd8885ac67
children 40dc584fce16
comparison
equal deleted inserted replaced
2521:67a2797862bc 2522:52dc9b940348
24 @key{DEL}, and @key{LFD} are changed frequently. In addition, commands 24 @key{DEL}, and @key{LFD} are changed frequently. In addition, commands
25 which handle comments use the mode to determine how to delimit comments. 25 which handle comments use the mode to determine how to delimit comments.
26 Many major modes redefine the syntactical properties of characters 26 Many major modes redefine the syntactical properties of characters
27 appearing in the buffer. @xref{Syntax}. 27 appearing in the buffer. @xref{Syntax}.
28 28
29 The major modes fall into three major groups. Lisp mode (which has 29 The major modes fall into three major groups. Programming modes
30 several variants), C mode, and Muddle mode are for specific programming 30 (@pxref{Programs}) are for specific programming languages. Text modes
31 languages. Text mode, Nroff mode, @TeX{} mode, and Outline mode are for 31 (like Nroff mode, @TeX{} mode, Outline mode, XML mode, etc.@:) are for
32 editing English text. The remaining major modes are not intended for use 32 editing human readable text. The remaining major modes are not intended
33 on users' files; they are used in buffers created by Emacs for specific 33 for direct use in editing user files; they are used in buffers created
34 purposes and include Dired mode for buffers made by Dired (@pxref{Dired}), 34 by Emacs for specific purposes. Examples of such modes include Dired
35 Mail mode for buffers made by @kbd{C-x m} (@pxref{Sending Mail}), and Shell 35 mode which is used for buffers made by Dired (@pxref{Dired}), Mail mode
36 mode for buffers used for communicating with an inferior shell process 36 for buffers made by @kbd{C-x m} (@pxref{Sending Mail}), and Shell mode
37 for buffers used for communicating with an inferior shell process
37 (@pxref{Interactive Shell}). 38 (@pxref{Interactive Shell}).
38 39
39 Most programming language major modes specify that only blank lines 40 Most programming language major modes specify that only blank lines
40 separate paragraphs. This is so that the paragraph commands remain useful. 41 separate paragraphs. This is so that the paragraph commands remain useful.
41 @xref{Paragraphs}. They also cause Auto Fill mode to use the definition of 42 @xref{Paragraphs}. They also cause Auto Fill mode to use the definition of
42 @key{TAB} to indent the new lines it creates. This is because most lines 43 @key{TAB} to indent the new lines it creates. This is because most lines
43 in a program are usually indented. @xref{Indentation}. 44 in a program are usually indented. @xref{Indentation}.
44 45
45 @menu 46 @menu
46 * Choosing Modes:: How major modes are specified or chosen. 47 * Choosing Modes:: How major modes are specified or chosen.
48 * Mode Hooks:: Customizing a major mode
47 @end menu 49 @end menu
48 50
49 @node Choosing Modes,,Major Modes,Major Modes 51 @node Choosing Modes, Mode Hooks, Major Modes, Major Modes
50 @section Choosing Major Modes 52 @section Choosing Major Modes
51 53
52 You can select a major mode explicitly for the current buffer, but 54 You can select a major mode explicitly for the current buffer, but
53 most of the time Emacs determines which mode to use based on the file 55 most of the time Emacs determines which mode to use based on the file
54 name or some text in the file. 56 name or some text in the file.
109 when you create a new buffer with @kbd{C-x b}, Emacs uses the major mode 111 when you create a new buffer with @kbd{C-x b}, Emacs uses the major mode
110 specified by the variable @code{default-major-mode}. Normally this 112 specified by the variable @code{default-major-mode}. Normally this
111 value is the symbol @code{fundamental-mode}, which specifies Fundamental 113 value is the symbol @code{fundamental-mode}, which specifies Fundamental
112 mode. If @code{default-major-mode} is @code{nil}, the major mode is 114 mode. If @code{default-major-mode} is @code{nil}, the major mode is
113 taken from the previously selected buffer. 115 taken from the previously selected buffer.
116
117 @node Mode Hooks, , Choosing Modes, Major Modes
118 @section Mode Hook Variables
119
120 @cindex Hook variables
121 @cindex mode hook
122 @findex add-hook
123 @findex remove-hook
124 @vindex lisp-mode-hook
125 @vindex emacs-lisp-mode-hook
126 @vindex lisp-interaction-mode-hook
127 @vindex scheme-mode-hook
128
129 The last step taken by a major mode, by convention, is to invoke a
130 list of user supplied functions that are stored in a ``hook'' variable.
131 This allows a user to further customize the major mode, and is
132 particularly convenient for setting up buffer local variables
133 (@pxref{Locals}).
134
135 The name of the hook variable is created by appending the string
136 @code{-hook} to the name of the major mode. For example, the hook
137 variable used by @code{text-mode} would be named @code{text-mode-hook}.
138 By convention the mode hook function receives no arguments. If a hook
139 variable does not exist, or it has the value @code{nil}, the major mode
140 simply ignores it.
141
142 The recommended way to add functions to a hook variable is with the
143 @code{add-hook} function. For example, to automatically turn on the
144 Auto Fill mode when Text mode is invoked the following code can be used in
145 the initialization file (@pxref{Init File})
146
147 @example
148 (add-hook 'text-mode-hook 'turn-on-auto-fill)
149 @end example
150
151 The @code{add-hook} function will check that the function is not already
152 listed in the hook variable before adding it. It will also create a hook
153 variable with the value @code{nil} if one does not exist before adding
154 the function. @code{add-hook} adds functions to the front of the hook
155 variable list. This means that the last hook added is run first by the
156 major mode. It is considered very poor style to write hook functions
157 that depend on the order that hooks are executed.
158
159 Hooks can be removed from hook variables with @code{remove-hook}.
160
161