emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r106535: More updates to Modes chapte


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r106535: More updates to Modes chapter of Emacs manual.
Date: Mon, 28 Nov 2011 14:24:48 +0800
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 106535
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Mon 2011-11-28 14:24:48 +0800
message:
  More updates to Modes chapter of Emacs manual.
  
  * doc/emacs/modes.texi (Major Modes): Move major-mode variable doc here from
  Choosing Modes.  Document describe-mode.  Document prog-mode-hook
  and text-mode-hook.  Add example of using hooks.
  (Minor Modes): Document behavior of mode command calls from Lisp.
  Note that setting the mode variable using Customize will DTRT.
  (Choosing Modes): Add example of setting a minor mode using a
  local variable.
modified:
  admin/FOR-RELEASE
  doc/emacs/ChangeLog
  doc/emacs/modes.texi
=== modified file 'admin/FOR-RELEASE'
--- a/admin/FOR-RELEASE 2011-10-23 14:57:53 +0000
+++ b/admin/FOR-RELEASE 2011-11-28 06:24:48 +0000
@@ -170,7 +170,7 @@
 files.texi        cyd
 fixit.texi        
 fortran-xtra.texi 
-frames.texi       
+frames.texi       cyd
 glossary.texi
 help.texi         cyd
 indent.texi       
@@ -182,6 +182,7 @@
 mark.texi         cyd
 mini.texi         
 misc.texi         
+modes.texi        cyd
 msdog.texi        
 msdog-xtra.texi   
 mule.texi         
@@ -197,7 +198,7 @@
 trouble.texi      
 vc-xtra.texi
 vc1-xtra.texi
-windows.texi      
+windows.texi      cyd
 xresources.texi   
 
 ** Check the Lisp manual.

=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog       2011-11-27 08:22:37 +0000
+++ b/doc/emacs/ChangeLog       2011-11-28 06:24:48 +0000
@@ -1,3 +1,13 @@
+2011-11-28  Chong Yidong  <address@hidden>
+
+       * modes.texi (Major Modes): Move major-mode variable doc here from
+       Choosing Modes.  Document describe-mode.  Document prog-mode-hook
+       and text-mode-hook.  Add example of using hooks.
+       (Minor Modes): Document behavior of mode command calls from Lisp.
+       Note that setting the mode variable using Customize will DTRT.
+       (Choosing Modes): Add example of setting a minor mode using a
+       local variable.
+
 2011-11-27  Chong Yidong  <address@hidden>
 
        * frames.texi (Creating Frames): Move frame parameter example to

=== modified file 'doc/emacs/modes.texi'
--- a/doc/emacs/modes.texi      2011-11-16 17:47:25 +0000
+++ b/doc/emacs/modes.texi      2011-11-28 06:24:48 +0000
@@ -3,11 +3,11 @@
 @c   Free Software Foundation, Inc.
 @c See file emacs.texi for copying conditions.
 @node Modes, Indentation, International, Top
address@hidden Editing Modes
address@hidden Major and Minor Modes
 
-  Emacs contains many @dfn{editing modes}, each of which alters its
-basic behavior in useful ways.  These are divided into @dfn{major
-modes} and @dfn{minor modes}.
+  Emacs contains many @dfn{editing modes} that alter its basic
+behavior in useful ways.  These are divided into @dfn{major modes} and
address@hidden modes}.
 
   Major modes provide specialized facilities for working on a
 particular file type, such as a C source file (@pxref{Programs}), or a
@@ -38,15 +38,8 @@
 
   Every buffer possesses a major mode, which determines the editing
 behavior of Emacs while that buffer is current.  The mode line
-normally shows the name of the current major mode, in parentheses.
address@hidden Line}.
-
-  Usually, the major mode is automatically set by Emacs, when you
-first visit a file or create a buffer.  @xref{Choosing Modes}.  You
-can explicitly select a new major mode by using an @kbd{M-x} command.
-Take the name of the mode and add @code{-mode} to get the name of the
-command to select that mode.  Thus, you can enter Lisp mode with
address@hidden lisp-mode}.
+normally shows the name of the current major mode, in parentheses
+(@pxref{Mode Line}).
 
   The least specialized major mode is called @dfn{Fundamental mode}.
 This mode has no mode-specific redefinitions or variable settings, so
@@ -55,73 +48,140 @@
 
   For editing text of a specific type that Emacs knows about, such as
 Lisp code or English text, you typically use a more specialized major
-mode, such as Lisp mode or Text mode.  Such major modes change the
-meanings of some keys to become more specifically adapted to the
-language being edited.  The ones that are commonly changed are
address@hidden, @key{DEL}, and @kbd{C-j}.  The prefix key @kbd{C-c}
-normally contains mode-specific commands.  In addition, the commands
-which handle comments use the mode to determine how comments are to be
-delimited.  Many major modes redefine the syntactical properties of
-characters appearing in the buffer.
-
-  The major modes fall into three major groups.  The first group
-contains modes for normal text, either plain or with mark-up.  It
-includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline
-mode.  The second group contains modes for specific programming
-languages.  These include Lisp mode (which has several variants), C
-mode, Fortran mode, and others.  The remaining major modes are not
-intended for use on users' files; they are used in buffers created for
-specific purposes by Emacs, such as Dired mode for buffers made by
-Dired (@pxref{Dired}), Message mode for buffers made by @kbd{C-x m}
-(@pxref{Sending Mail}), and Shell mode for buffers used for
-communicating with an inferior shell process (@pxref{Interactive
-Shell}).
-
-  Most programming-language major modes specify that only blank lines
-separate paragraphs.  This is to make the paragraph commands useful.
-(@xref{Paragraphs}.)  They also cause Auto Fill mode to use the
-definition of @key{TAB} to indent the new lines it creates.  This is
-because most lines in a program are usually indented
-(@pxref{Indentation}).
+mode, such as Lisp mode or Text mode.  Most major modes fall into
+three major groups.  The first group contains modes for normal text,
+either plain or with mark-up.  It includes Text mode, HTML mode, SGML
+mode, @TeX{} mode and Outline mode.  The second group contains modes
+for specific programming languages.  These include Lisp mode (which
+has several variants), C mode, Fortran mode, and others.  The third
+group consists of major modes that are not associated directly with
+files; they are used in buffers created for specific purposes by
+Emacs, such as Dired mode for buffers made by Dired (@pxref{Dired}),
+Message mode for buffers made by @kbd{C-x m} (@pxref{Sending Mail}),
+and Shell mode for buffers used to communicate with an inferior shell
+process (@pxref{Interactive Shell}).
+
+  Usually, the major mode is automatically set by Emacs, when you
+first visit a file or create a buffer (@pxref{Choosing Modes}).  You
+can explicitly select a new major mode by using an @kbd{M-x} command.
+Take the name of the mode and add @code{-mode} to get the name of the
+command to select that mode.  Thus, you can enter Lisp mode with
address@hidden lisp-mode}.
+
address@hidden major-mode
+  The value of the buffer-local variable @code{major-mode} is a symbol
+with the same name as the major mode command (e.g. @code{lisp-mode}).
+This variable is set automatically; you should not change it yourself.
+
+  The default value of @code{major-mode} determines the major mode to
+use for files that do not specify a major mode, and for new buffers
+created with @kbd{C-x b}.  Normally, this default value is the symbol
address@hidden, which specifies Fundamental mode.  You can
+change this default value via the Customization interface (@pxref{Easy
+Customization}), or by adding a line like this to your init file
+(@pxref{Init File}):
+
address@hidden
+(setq-default major-mode 'text-mode)
address@hidden smallexample
+
address@hidden
+If the default value of @code{major-mode} is @code{nil}, the major
+mode is taken from the previously current buffer.
+
+  Specialized major modes often change the meanings of certain keys to
+do something more suitable for the mode.  For instance, programming
+language modes bind @key{TAB} to indent the current line according to
+the rules of the language (@pxref{Indentation}).  The keys that are
+commonly changed are @key{TAB}, @key{DEL}, and @kbd{C-j}.  Many modes
+also define special commands of their own, usually bound in the prefix
+key @kbd{C-c}.  Major modes can also alter user options and variables;
+for instance, programming language modes typicaly set a buffer-local
+value for the variable @code{comment-start}, which determines how
+source code comments are delimited (@pxref{Comments}).
+
address@hidden describe-mode
address@hidden C-h m
+  To view the documentation for the current major mode, including a
+list of its key bindings, type @code{C-h m} (@code{describe-mode}).
+
address@hidden mode hook
address@hidden text-mode-hook
address@hidden prog-mode-hook
+  Every major mode, apart from Fundamental mode, defines a @dfn{mode
+hook}, a customizable list of Lisp functions to run each time the mode
+is enabled in a buffer.  @xref{Hooks}, for more information about
+hooks.  Each mode hook is named after its major mode, e.g. Fortran
+mode has @code{fortran-mode-hook}.  Furthermore, all text-based major
+modes run @code{text-mode-hook}, and all programming language modes
+run @code{prog-mode-hook}, prior to running their own mode hooks.
+
+  Mode hooks are commonly used to enable minor modes (@pxref{Minor
+Modes}).  For example, you can put the following lines in your init
+file to enable Flyspell minor mode in all text-based major modes
+(@pxref{Spelling}), and Eldoc minor mode in Emacs Lisp mode
+(@pxref{Lisp Doc}):
+
address@hidden
+(add-hook 'text-mode-hook 'flyspell-mode)
+(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
address@hidden example
 
 @node Minor Modes
 @section Minor Modes
 @cindex minor modes
 @cindex mode, minor
 
-  A minor mode is an optional editing modes that alters the behavior
-of Emacs in some well-defined way.  Unlike major modes, any number of
+  A minor mode is an optional editing mode that alters the behavior of
+Emacs in some well-defined way.  Unlike major modes, any number of
 minor modes can be in effect at any time.  Some minor modes are
address@hidden: they apply only to the current buffer, so you can
-enable the mode in certain buffers and not others.  Other minor modes
-are @dfn{global}: while enabled, they affect everything you do in the
-Emacs session, in all buffers.  Some global minor modes are enabled by
-default.
-
-  Most minor modes say in the mode line when they are enabled, just
-after the major mode indicator.  For example, @samp{Fill} in the mode
-line means that Auto Fill mode is enabled.  @xref{Mode Line}.
-
-  Each minor mode is associated with a command, called the @dfn{mode
-command}, which turns it on or off.  The name of this command consists
-of the name of the minor mode, followed by @samp{-mode}; for instance,
-the mode command for Auto Fill mode is @code{auto-fill-mode}.  Calling
-the minor mode command with no prefix argument @dfn{toggles} the mode,
-turning it on if it was off, and off if it was on.  A positive
-argument always turns the mode on, and a zero or negative argument
-always turns it off.  Mode commands are usually invoked with
address@hidden, but you can bind keys to them if you wish (@pxref{Key
-Bindings}).
address@hidden, and can be turned on (enabled) in certain buffers
+and off (disabled) in others.  Other minor modes are @dfn{global}:
+while enabled, they affect everything you do in the Emacs session, in
+all buffers.  Most minor modes are disabled by default, but a few are
+enabled by default.
+
+  Most buffer-local minor modes say in the mode line when they are
+enabled, just after the major mode indicator.  For example,
address@hidden in the mode line means that Auto Fill mode is enabled.
address@hidden Line}.
+
address@hidden mode commands for minor modes
+  Like major modes, each minor mode is associated with a @dfn{mode
+command}, whose name consists of the mode name followed by
address@hidden  For instance, the mode command for Auto Fill mode is
address@hidden  But unlike a major mode command, which simply
+enables the mode, the mode command for a minor mode can either enable
+or disable it:
+
address@hidden
address@hidden
+If you invoke the mode command directly with no prefix argument
+(either via @kbd{M-x}, or by binding it to a key and typing that key;
address@hidden Bindings}), that @dfn{toggles} the minor mode.  The minor
+mode is turned on if it was off, and turned off if it was on.
+
address@hidden
+If you invoke the mode command with a prefix argument, the minor mode
+is unconditionally turned off if that argument is zero or negative;
+otherwise, it is unconditionally turned on.
+
address@hidden
+If the mode command is called via Lisp, the minor mode is
+unconditionally turned on if the argument is omitted or @code{nil}.
+This makes it easy to turn on a minor mode from a major mode's mode
+hook (@pxref{Major Modes}).  A address@hidden argument is handled like
+an interactive prefix argument, as described above.
address@hidden itemize
 
   Most minor modes also have a @dfn{mode variable}, with the same name
 as the mode command.  Its value is address@hidden if the mode is
-enabled, and @code{nil} if it is disabled.  In some minor modes---but
-not all---the value of the variable alone determines whether the mode
-is active: the mode command works simply by setting the variable, and
-changing the value of the variable has the same effect as calling the
-mode command.  Because not all minor modes work this way, we recommend
-that you avoid changing the mode variables directly; use the mode
-commands instead.
+enabled, and @code{nil} if it is disabled.  In general, you should not
+try to enable or disable the mode by changing the value of the mode
+variable directly in Lisp; you should run the mode command instead.
+However, setting the mode variable through the Customize interface
+(@pxref{Easy Customization}) will always properly enable or disable
+the mode, since Customize automatically runs the mode command for you.
 
   The following is a list of some buffer-local minor modes:
 
@@ -189,11 +249,8 @@
 wrapped at word boundaries.  @xref{Visual Line Mode}.
 @end itemize
 
-  Here are some useful global minor modes.  Since Line Number mode and
-Transient Mark mode can be enabled or disabled just by setting the
-value of the minor mode variable, you @emph{can} set them differently
-for particular buffers, by explicitly making the corresponding
-variable local in those buffers.  @xref{Locals}.
address@hidden
+And here are some useful global minor modes:
 
 @itemize @bullet
 @item
@@ -261,22 +318,27 @@
 
 @noindent
 tells Emacs to use Lisp mode.  Note how the semicolon is used to make
-Lisp treat this line as a comment.  Alternatively, you could write
+Lisp treat this line as a comment.  You could equivalently write
 
 @example
 ; -*- mode: Lisp;-*-
 @end example
 
 @noindent
-The latter format allows you to specify local variables as well, like
-this:
+You can also use file-local variables to specify buffer-local minor
+modes, by using @code{eval} specifications.  For example, this first
+nonblank line puts the buffer in Lisp mode and enables Auto-Fill mode:
 
 @example
-; -*- mode: Lisp; tab-width: 4; -*-
+; -*- mode: Lisp; eval: (auto-fill-mode 1); -*-
 @end example
 
-  If a file variable specifies a buffer-local minor mode, Emacs
-enables that minor mode in the buffer.
address@hidden
+Note, however, that it is usually inappropriate to enable minor modes
+this way, since most minor modes represent individual user
+preferences.  If you personally want to use a minor mode for a
+particular file type, it is better to enable the minor mode via a
+major mode hook (@pxref{Major Modes}).
 
 @vindex interpreter-mode-alist
   Second, if there is no file variable specifying a major mode, Emacs
@@ -310,9 +372,9 @@
 
 @noindent
 where @var{regexp} is a regular expression (@pxref{Regexps}), and
address@hidden is a Lisp function that toggles a major mode.  If
-the text at the beginning of the file matches @var{regexp}, Emacs
-chooses the major mode specified by @var{mode-function}.
address@hidden is a major mode command.  If the text at the
+beginning of the file matches @var{regexp}, Emacs chooses the major
+mode specified by @var{mode-function}.
 
 Alternatively, an element of @code{magic-mode-alist} may have the form
 
@@ -323,7 +385,7 @@
 @noindent
 where @var{match-function} is a Lisp function that is called at the
 beginning of the buffer; if the function returns address@hidden, Emacs
-set the major mode wit @var{mode-function}.
+set the major mode with @var{mode-function}.
 
   Fourth---if Emacs still hasn't found a suitable major mode---it
 looks at the file's name.  The correspondence between file names and
@@ -370,29 +432,6 @@
 @code{magic-fallback-mode-alist} contains forms that check for image
 files, HTML/XML/SGML files, and PostScript files.
 
address@hidden major-mode
-  Once a major mode is chosen, Emacs sets the value of the variable
address@hidden to the symbol for that major mode (e.g.,
address@hidden for Text mode).  This is a per-buffer variable
-(@pxref{Locals}); its buffer-local value is set automatically, and you
-should not change it yourself.
-
-  The default value of @code{major-mode} determines the major mode to
-use for files that do not specify a major mode, and for new buffers
-created with @kbd{C-x b}.  Normally, this default value is the symbol
address@hidden, which specifies Fundamental mode.  You can
-change it via the Customization interface (@pxref{Easy
-Customization}), or by adding a line like this to your init file
-(@pxref{Init File}):
-
address@hidden
-(setq-default major-mode 'text-mode)
address@hidden smallexample
-
address@hidden
-If the default value of @code{major-mode} is @code{nil}, the major
-mode is taken from the previously current buffer.
-
 @findex normal-mode
   If you have changed the major mode of a buffer, you can return to
 the major mode Emacs would have chosen automatically, by typing


reply via email to

[Prev in Thread] Current Thread [Next in Thread]