Commit ec7ae032 authored by Chong Yidong's avatar Chong Yidong
Browse files

Updates to Programs chapter of Emacs manual.

* programs.texi (Program Modes): Mention modes that are not
included with Emacs.  Fix references to other manuals for tex.
Add index entry for backward-delete-char-untabify.  Mention
prog-mode-hook.
(Which Function): Use "global minor mode" terminology.
(Basic Indent, Multi-line Indent): Refer to previous descriptions
in Indentation chapter to avoid duplication.
(Expressions): Copyedit.
(Matching): Document Electric Pair mode.

* ack.texi (Acknowledgments):
* rmail.texi (Movemail, Other Mailbox Formats):
* frames.texi (Frames): Don't capitalize "Unix".
parent 6d5eb5b0
2011-12-04 Chong Yidong <cyd@gnu.org>
* programs.texi (Program Modes): Mention modes that are not
included with Emacs. Fix references to other manuals for tex.
Add index entry for backward-delete-char-untabify. Mention
prog-mode-hook.
(Which Function): Use "global minor mode" terminology.
(Basic Indent, Multi-line Indent): Refer to previous descriptions
in Indentation chapter to avoid duplication.
(Expressions): Copyedit.
(Matching): Document Electric Pair mode.
* ack.texi (Acknowledgments):
* rmail.texi (Movemail, Other Mailbox Formats):
* frames.texi (Frames): Don't capitalize "Unix".
2011-12-04 Chong Yidong <cyd@gnu.org> 2011-12-04 Chong Yidong <cyd@gnu.org>
* text.texi (Nroff Mode): Mention what nroff is. * text.texi (Nroff Mode): Mention what nroff is.
......
...@@ -1272,8 +1272,8 @@ Colin Walters wrote Ibuffer, an enhanced buffer menu. ...@@ -1272,8 +1272,8 @@ Colin Walters wrote Ibuffer, an enhanced buffer menu.
Barry Warsaw wrote @file{assoc.el}, a set of utility functions for Barry Warsaw wrote @file{assoc.el}, a set of utility functions for
working with association lists; @file{cc-mode.el}, a mode for editing working with association lists; @file{cc-mode.el}, a mode for editing
C, C@t{++}, and Java code, based on earlier work by Dave Detlefs, C, C@t{++}, and Java code, based on earlier work by Dave Detlefs,
Stewart Clamen, and Richard Stallman; @file{elp.el}, a profiler Stewart Clamen, and Richard Stallman; @file{elp.el}, a profiler for
for Emacs Lisp programs; @file{man.el}, a mode for reading UNIX manual Emacs Lisp programs; @file{man.el}, a mode for reading Unix manual
pages; @file{regi.el}, providing an AWK-like functionality for use in pages; @file{regi.el}, providing an AWK-like functionality for use in
lisp programs; @file{reporter.el}, providing customizable bug lisp programs; @file{reporter.el}, providing customizable bug
reporting for lisp packages; and @file{supercite.el}, a minor mode for reporting for lisp packages; and @file{supercite.el}, a minor mode for
......
...@@ -32,7 +32,7 @@ unavailable. However, it is still possible to create multiple ...@@ -32,7 +32,7 @@ unavailable. However, it is still possible to create multiple
``frames'' on text-only terminals; such frames are displayed one at a ``frames'' on text-only terminals; such frames are displayed one at a
time, filling the entire terminal screen (@pxref{Non-Window time, filling the entire terminal screen (@pxref{Non-Window
Terminals}). It is also possible to use the mouse on some text-only Terminals}). It is also possible to use the mouse on some text-only
terminals (@pxref{Text-Only Mouse}, for doing so on GNU and UNIX terminals (@pxref{Text-Only Mouse}, for doing so on GNU and Unix
systems; and systems; and
@iftex @iftex
@pxref{MS-DOS Mouse,,,emacs-xtra,Specialized Emacs Features}, @pxref{MS-DOS Mouse,,,emacs-xtra,Specialized Emacs Features},
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
@cindex C editing @cindex C editing
@cindex program editing @cindex program editing
Emacs provides many features to facilitate editing programs. Some This chapter describes Emacs features for facilitating editing
of these features can programs. Some of these features can:
@itemize @bullet @itemize @bullet
@item @item
...@@ -25,8 +25,6 @@ Insert, kill or align comments (@pxref{Comments}). ...@@ -25,8 +25,6 @@ Insert, kill or align comments (@pxref{Comments}).
Highlight program syntax (@pxref{Font Lock}). Highlight program syntax (@pxref{Font Lock}).
@end itemize @end itemize
This chapter describes these features and many more.
@menu @menu
* Program Modes:: Major modes for editing programs. * Program Modes:: Major modes for editing programs.
* Defuns:: Commands to operate on major top-level parts * Defuns:: Commands to operate on major top-level parts
...@@ -52,21 +50,14 @@ Highlight program syntax (@pxref{Font Lock}). ...@@ -52,21 +50,14 @@ Highlight program syntax (@pxref{Font Lock}).
@section Major Modes for Programming Languages @section Major Modes for Programming Languages
@cindex modes for programming languages @cindex modes for programming languages
Emacs has specialized major modes for various programming languages. Emacs has specialized major modes (@pxref{Major Modes}) for many
@xref{Major Modes}. A programming language major mode typically programming languages. A programming language mode typically
specifies the syntax of expressions, the customary rules for specifies the syntax of expressions, the customary rules for
indentation, how to do syntax highlighting for the language, and how indentation, how to do syntax highlighting for the language, and how
to find the beginning or end of a function definition. It often to find the beginning or end of a function definition. It often has
customizes or provides facilities for compiling and debugging programs features for compiling and debugging programs as well. The major mode
as well. for each language is named after the language; for instance, the major
mode for the C programming language is @code{c-mode}.
Ideally, Emacs should provide a major mode for each programming
language that you might want to edit; if it doesn't have a mode for
your favorite language, you can contribute one. But often the mode
for one language can serve for other syntactically similar languages.
The major mode for language @var{l} is called @code{@var{l}-mode},
and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}.
@xref{Choosing Modes}.
@cindex Perl mode @cindex Perl mode
@cindex Icon mode @cindex Icon mode
...@@ -89,40 +80,32 @@ and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}. ...@@ -89,40 +80,32 @@ and you can select it by typing @kbd{M-x @var{l}-mode @key{RET}}.
@cindex Conf mode @cindex Conf mode
@cindex DNS mode @cindex DNS mode
@cindex Javascript mode @cindex Javascript mode
The existing programming language major modes include Lisp, Scheme Emacs has programming language modes for Lisp, Scheme, the
(a variant of Lisp) and the Scheme-based DSSSL expression language, Scheme-based DSSSL expression language, Ada, ASM, AWK, C, C++, Delphi,
Ada, ASM, AWK, C, C++, Delphi (Object Pascal), Fortran, Icon, IDL Fortran, Icon, IDL (CORBA), IDLWAVE, Java, Javascript, Metafont
(CORBA), IDLWAVE, Java, Javascript, Metafont (@TeX{}'s companion for (@TeX{}'s companion for font creation), Modula2, Objective-C, Octave,
font creation), Modula2, Objective-C, Octave, Pascal, Perl, Pike, Pascal, Perl, Pike, PostScript, Prolog, Python, Ruby, Simula, Tcl, and
PostScript, Prolog, Python, Ruby, Simula, Tcl, and VHDL. An VHDL. An alternative mode for Perl is called CPerl mode. Modes are
alternative mode for Perl is called CPerl mode. Modes are available also available for the scripting languages of the common GNU and Unix
for the scripting languages of the common GNU and Unix shells, VMS shells, VMS DCL, and MS-DOS/MS-Windows @samp{BAT} files, and for
DCL, and MS-DOS/MS-Windows @samp{BAT} files. There are also major makefiles, DNS master files, and various sorts of configuration files.
modes for editing makefiles, DNS master files, and various sorts of
configuration files. Ideally, Emacs should have a major mode for each programming
language that you might want to edit. If it doesn't have a mode for
your favorite language, the mode might be implemented in a package not
distributed with Emacs (@pxref{Packages}); or you can contribute one.
@kindex DEL @r{(programming modes)} @kindex DEL @r{(programming modes)}
@findex c-electric-backspace @findex c-electric-backspace
@findex backward-delete-char-untabify
In most programming languages, indentation should vary from line to In most programming languages, indentation should vary from line to
line to illustrate the structure of the program. So the major modes line to illustrate the structure of the program. Therefore, in most
for programming languages arrange for @key{TAB} to update the programming language modes, typing @key{TAB} updates the indentation
indentation of the current line (@pxref{Program Indent}). They also of the current line (@pxref{Program Indent}). Furthermore, @key{DEL}
rebind @key{DEL} to treat a tab as if it were the equivalent number of is usually bound to @code{backward-delete-char-untabify}, which
spaces; this lets you delete one column of indentation without deletes backward treating each tab as if it were the equivalent number
worrying whether the whitespace consists of spaces or tabs. Use of spaces, so that you can delete one column of indentation without
@kbd{C-b C-d} to delete a tab character before point, in these modes. worrying whether the whitespace consists of spaces or tabs.
Separate manuals are available for the modes for Ada (@pxref{Top, , Ada
Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba IDL/Pike/AWK
(@pxref{Top, , CC Mode, ccmode, CC Mode}) and the IDLWAVE modes
(@pxref{Top, , IDLWAVE, idlwave, IDLWAVE User Manual}). For Fortran
mode, see
@iftex
@ref{Fortran,,, emacs-xtra, Specialized Emacs Features}.
@end iftex
@ifnottex
@ref{Fortran}.
@end ifnottex
@cindex mode hook @cindex mode hook
@vindex c-mode-hook @vindex c-mode-hook
...@@ -130,13 +113,24 @@ mode, see ...@@ -130,13 +113,24 @@ mode, see
@vindex emacs-lisp-mode-hook @vindex emacs-lisp-mode-hook
@vindex lisp-interaction-mode-hook @vindex lisp-interaction-mode-hook
@vindex scheme-mode-hook @vindex scheme-mode-hook
Turning on a major mode runs a normal hook called the @dfn{mode Entering a programming language mode runs the custom Lisp functions
hook}, which is the value of a Lisp variable. Each major mode has a specified in the hook variable @code{prog-mode-hook}, followed by
mode hook, and the hook's name is always made from the mode command's those specified in the mode's own mode hook (@pxref{Major Modes}).
name by adding @samp{-hook}. For example, turning on C mode runs the For instance, entering C mode runs the hooks @code{prog-mode-hook} and
hook @code{c-mode-hook}, while turning on Lisp mode runs the hook @code{c-mode-hook}. @xref{Hooks}, for information about hooks.
@code{lisp-mode-hook}. The purpose of the mode hook is to give you a
place to set up customizations for that major mode. @xref{Hooks}. @ifinfo
Separate manuals are available for the modes for Ada (@pxref{Top,,
Ada Mode, ada-mode, Ada Mode}), C/C++/Objective C/Java/Corba
IDL/Pike/AWK (@pxref{Top, , CC Mode, ccmode, CC Mode}), and IDLWAVE
(@pxref{Top,, IDLWAVE, idlwave, IDLWAVE User Manual}).
@end ifinfo
@ifnotinfo
The Emacs distribution contains Info manuals for the major modes for
Ada, C/C++/Objective C/Java/Corba IDL/Pike/AWK, and IDLWAVE. For
Fortran mode, see the ``Fortran'' section in the Info version of the
Emacs manual, which is not included in this printed version.
@end ifnotinfo
@node Defuns @node Defuns
@section Top-Level Definitions, or Defuns @section Top-Level Definitions, or Defuns
...@@ -328,20 +322,19 @@ The Speedbar can also use it (@pxref{Speedbar}). ...@@ -328,20 +322,19 @@ The Speedbar can also use it (@pxref{Speedbar}).
@subsection Which Function Mode @subsection Which Function Mode
@cindex current function name in mode line @cindex current function name in mode line
Which Function mode is a minor mode that displays the current Which Function mode is a global minor mode (@pxref{Minor Modes})
function name in the mode line, updating it as you move around in a which displays the current function name in the mode line, updating it
buffer. as you move around in a buffer.
@findex which-function-mode @findex which-function-mode
@vindex which-func-modes @vindex which-func-modes
To either enable or disable Which Function mode, use the command To either enable or disable Which Function mode, use the command
@kbd{M-x which-function-mode}. This command applies to all buffers, @kbd{M-x which-function-mode}. Although Which Function mode is a
both existing ones and those yet to be created. However, it takes global minor mode, it takes effect only in certain major modes: those
effect only in certain major modes, those listed in the value of listed in the variable @code{which-func-modes}. If the value of
@code{which-func-modes}. If the value of @code{which-func-modes} is @code{which-func-modes} is @code{t} rather than a list of modes, then
@code{t} rather than a list of modes, then Which Function mode applies Which Function mode applies to all major modes that know how to
to all major modes that know how to support it---in other words, all support it---in other words, all the major modes that support Imenu.
the major modes that support Imenu.
@node Program Indent @node Program Indent
@section Indentation for Programs @section Indentation for Programs
...@@ -352,6 +345,10 @@ reindent it as you change it. Emacs has commands to indent either a ...@@ -352,6 +345,10 @@ reindent it as you change it. Emacs has commands to indent either a
single line, a specified number of lines, or all of the lines inside a single line, a specified number of lines, or all of the lines inside a
single parenthetical grouping. single parenthetical grouping.
@xref{Indentation}, for general information about indentation. This
section describes indentation features specific to programming
language modes.
@menu @menu
* Basic Indent:: Indenting a single line. * Basic Indent:: Indenting a single line.
* Multi-line Indent:: Commands to reindent many lines at once. * Multi-line Indent:: Commands to reindent many lines at once.
...@@ -361,18 +358,15 @@ single parenthetical grouping. ...@@ -361,18 +358,15 @@ single parenthetical grouping.
@end menu @end menu
@cindex pretty-printer @cindex pretty-printer
Emacs also provides a Lisp pretty-printer in the library @code{pp}. Emacs also provides a Lisp pretty-printer in the @code{pp} package,
This program reformats a Lisp object with indentation chosen to look nice. which reformats Lisp objects with nice-looking indentation.
@node Basic Indent @node Basic Indent
@subsection Basic Program Indentation Commands @subsection Basic Program Indentation Commands
The basic indentation commands indent a single line according to the
usual conventions of the language you are editing.
@table @kbd @table @kbd
@item @key{TAB} @item @key{TAB}
Adjust indentation of current line. Adjust indentation of current line (@code{indent-for-tab-command}).
@item C-j @item C-j
Insert a newline, then adjust indentation of following line Insert a newline, then adjust indentation of following line
(@code{newline-and-indent}). (@code{newline-and-indent}).
...@@ -382,65 +376,50 @@ Insert a newline, then adjust indentation of following line ...@@ -382,65 +376,50 @@ Insert a newline, then adjust indentation of following line
@findex c-indent-command @findex c-indent-command
@findex indent-line-function @findex indent-line-function
@findex indent-for-tab-command @findex indent-for-tab-command
The basic indentation command is @key{TAB}. In any The basic indentation command is @key{TAB}
programming-language major mode, @key{TAB} gives the current line the (@code{indent-for-tab-command}), which was documented in
correct indentation as determined from the previous lines. It does @ref{Indentation}. In programming language modes, @key{TAB} indents
this by inserting or deleting whitespace at the beginning of the the current line, based on the indentation and syntactic content of
current line. If point was inside the whitespace at the beginning of the preceding lines; if the region is active, @key{TAB} indents each
the line, @key{TAB} puts it at the end of that whitespace; otherwise, line within the region, not just the current line.
@key{TAB} keeps point fixed with respect to the characters around it.
If the region is active (@pxref{Mark}), @key{TAB} indents every line
within the region instead of just the current line. The function that
@key{TAB} runs depends on the major mode; for instance, it is
@code{c-indent-line-or-region} in C mode. Each function is aware of
the syntax and conventions for its particular language.
Use @kbd{C-q @key{TAB}} to insert a tab character at point.
@kindex C-j @r{(indenting source code)} @kindex C-j @r{(indenting source code)}
@findex newline-and-indent @findex newline-and-indent
When entering lines of new code, use @kbd{C-j} The command @kbd{C-j} (@code{newline-and-indent}), which was
(@code{newline-and-indent}), which inserts a newline and then adjusts documented in @ref{Indentation Commands}, does the same as @key{RET}
indentation after it. (It also deletes any trailing whitespace which followed by @key{TAB}: it inserts a new line, then adjusts the line's
remains before the new newline.) For instance, @kbd{C-j} at the end indentation.
of a line creates a blank line with appropriate indentation. In
programming language modes, it is equivalent to @key{RET} @key{TAB}. When indenting a line that starts within a parenthetical grouping,
Emacs usually places the start of the line under the preceding line
When Emacs indents a line that starts within a parenthetical within the group, or under the text after the parenthesis. If you
grouping, it usually places the start of the line under the preceding manually give one of these lines a nonstandard indentation (e.g.@: for
line within the group, or under the text after the parenthesis. If aesthetic purposes), the lines below will follow it.
you manually give one of these lines a nonstandard indentation, the
lines below will tend to follow it. This behavior is convenient in The indentation commands for most programming language modes assume
cases where you have overridden the standard result of @key{TAB} that a open-parenthesis, open-brace or other opening delimiter at the
indentation (e.g., for aesthetic purposes). left margin is the start of a function. If the code you are editing
violates this assumption---even if the delimiters occur in strings or
Many programming-language modes assume that an open-parenthesis, comments---you must set @code{open-paren-in-column-0-is-defun-start}
open-brace or other opening delimiter at the left margin is the start to @code{nil} for indentation to work properly. @xref{Left Margin
of a function. This assumption speeds up indentation commands. If
the text you are editing contains opening delimiters in column zero
that aren't the beginning of a functions---even if these delimiters
occur inside strings or comments---then you must set
@code{open-paren-in-column-0-is-defun-start}. @xref{Left Margin
Paren}. Paren}.
Normally, Emacs indents lines using an ``optimal'' mix of tab and
space characters. If you want Emacs to use spaces only, set
@code{indent-tabs-mode} (@pxref{Just Spaces}).
@node Multi-line Indent @node Multi-line Indent
@subsection Indenting Several Lines @subsection Indenting Several Lines
Sometimes, you may want to reindent several lines of code at a time. Sometimes, you may want to reindent several lines of code at a time.
One way to do this is to use the mark; when the mark is active and the One way to do this is to use the mark; when the mark is active and the
region is non-empty, @key{TAB} indents every line within the region. region is non-empty, @key{TAB} indents every line in the region.
In addition, Emacs provides several other commands for indenting large Alternatively, the command @kbd{C-M-\} (@code{indent-region}) indents
chunks of code: every line in the region, whether or not the mark is active
(@pxref{Indentation Commands}).
In addition, Emacs provides the following commands for indenting
large chunks of code:
@table @kbd @table @kbd
@item C-M-q @item C-M-q
Reindent all the lines within one parenthetical grouping. Reindent all the lines within one parenthetical grouping.
@item C-M-\
Reindent all lines in the region (@code{indent-region}).
@item C-u @key{TAB} @item C-u @key{TAB}
Shift an entire parenthetical grouping rigidly sideways so that its Shift an entire parenthetical grouping rigidly sideways so that its
first line is properly indented. first line is properly indented.
...@@ -454,18 +433,13 @@ lines that start inside comments and strings. ...@@ -454,18 +433,13 @@ lines that start inside comments and strings.
To reindent the contents of a single parenthetical grouping, To reindent the contents of a single parenthetical grouping,
position point before the beginning of the grouping and type position point before the beginning of the grouping and type
@kbd{C-M-q}. This changes the relative indentation within the @kbd{C-M-q}. This changes the relative indentation within the
grouping, without affecting its overall indentation (i.e., the grouping, without affecting its overall indentation (i.e.@: the
indentation of the line where the grouping starts). The function that indentation of the line where the grouping starts). The function that
@kbd{C-M-q} runs depends on the major mode; it is @kbd{C-M-q} runs depends on the major mode; it is
@code{indent-pp-sexp} in Lisp mode, @code{c-indent-exp} in C mode, @code{indent-pp-sexp} in Lisp mode, @code{c-indent-exp} in C mode,
etc. To correct the overall indentation as well, type @key{TAB} etc. To correct the overall indentation as well, type @key{TAB}
first. first.
@kbd{C-M-\} (@code{indent-region}) applies @key{TAB} to the region.
This is useful when Transient Mark mode is disabled (@pxref{Disabled
Transient Mark}), because in that case @key{TAB} does not act on the
region.
@kindex C-u TAB @kindex C-u TAB
If you like the relative indentation within a grouping but not the If you like the relative indentation within a grouping but not the
indentation of its first line, move point to that first line and type indentation of its first line, move point to that first line and type
...@@ -516,9 +490,9 @@ expression. ...@@ -516,9 +490,9 @@ expression.
@cindex @code{lisp-indent-function} property @cindex @code{lisp-indent-function} property
You can override the standard pattern in various ways for individual You can override the standard pattern in various ways for individual
functions, according to the @code{lisp-indent-function} property of functions, according to the @code{lisp-indent-function} property of
the function name. Normally you would use this for macro definitions the function name. This is normally done for macro definitions, using
and specify it using the @code{declare} construct (@pxref{Defining the @code{declare} construct. @xref{Defining Macros,,, elisp, the
Macros,,, elisp, the Emacs Lisp Reference Manual}). Emacs Lisp Reference Manual}.
@node C Indent @node C Indent
@subsection Commands for C Indentation @subsection Commands for C Indentation
...@@ -664,9 +638,13 @@ parentheses and unbalanced string quotes in the buffer. ...@@ -664,9 +638,13 @@ parentheses and unbalanced string quotes in the buffer.
@cindex sexp @cindex sexp
@cindex expression @cindex expression
@cindex balanced expression @cindex balanced expression
These commands deal with balanced expressions, also called Each programming language mode has its own definition of a
@dfn{sexps}@footnote{The word ``sexp'' is used to refer to an @dfn{balanced expression}. Balanced expressions typically include
expression in Lisp.}. individual symbols, numbers, and string constants, as well as pieces
of code enclosed in a matching pair of delimiters. The following
commands deal with balanced expressions (in Emacs, such expressions
are referred to internally as @dfn{sexps}@footnote{The word ``sexp''
is used to refer to an expression in Lisp.}).
@table @kbd @table @kbd
@item C-M-f @item C-M-f
...@@ -682,90 +660,71 @@ Transpose expressions (@code{transpose-sexps}). ...@@ -682,90 +660,71 @@ Transpose expressions (@code{transpose-sexps}).
Put mark after following expression (@code{mark-sexp}). Put mark after following expression (@code{mark-sexp}).
@end table @end table
Each programming language major mode customizes the definition of
balanced expressions to suit that language. Balanced expressions
typically include symbols, numbers, and string constants, as well as
any pair of matching delimiters and their contents. Some languages
have obscure forms of expression syntax that nobody has bothered to
implement in Emacs.
@cindex Control-Meta
By convention, the keys for these commands are all Control-Meta
characters. They usually act on expressions just as the corresponding
Meta characters act on words. For instance, the command @kbd{C-M-b}
moves backward over a balanced expression, just as @kbd{M-b} moves
back over a word.
@kindex C-M-f @kindex C-M-f
@kindex C-M-b @kindex C-M-b
@findex forward-sexp @findex forward-sexp
@findex backward-sexp @findex backward-sexp
To move forward over a balanced expression, use @kbd{C-M-f} To move forward over a balanced expression, use @kbd{C-M-f}
(@code{forward-sexp}). If the first significant character after point (@code{forward-sexp}). If the first significant character after point
is an opening delimiter (@samp{(} in Lisp; @samp{(}, @samp{[} or is an opening delimiter (e.g.@: @samp{(}, @samp{[} or @samp{@{} in C),
@samp{@{} in C), @kbd{C-M-f} moves past the matching closing this command moves past the matching closing delimiter. If the
delimiter. If the character begins a symbol, string, or number, character begins a symbol, string, or number, the command moves over
@kbd{C-M-f} moves over that. that.
The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a The command @kbd{C-M-b} (@code{backward-sexp}) moves backward over a
balanced expression. The detailed rules are like those above for balanced expression---like @kbd{C-M-f}, but in the reverse direction.
@kbd{C-M-f}, but with directions reversed. If there are prefix If the expression is preceded by any prefix characters (single-quote,
characters (single-quote, backquote and comma, in Lisp) preceding the backquote and comma, in Lisp), the command moves back over them as
expression, @kbd{C-M-b} moves back over them as well. The balanced well.
expression commands move across comments as if they were whitespace,
in most modes. @kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation
the specified number of times; with a negative argument means to move
@kbd{C-M-f} or @kbd{C-M-b} with an argument repeats that operation the in the opposite direction. In most modes, these two commands move
specified number of times; with a negative argument, it moves in the across comments as if they were whitespace. Note that their keys,
opposite direction. @kbd{C-M-f} and @kbd{C-M-b}, are analogous to @kbd{C-f} and @kbd{C-b},
which move by characters (@pxref{Moving Point}), and @kbd{M-f} and
@kbd{M-b}, which move by words (@pxref{Words}).
@cindex killing expressions @cindex killing expressions
@kindex C-M-k @kindex C-M-k
@findex kill-sexp @findex kill-sexp
Killing a whole balanced expression can be done with @kbd{C-M-k} To kill a whole balanced expression, type @kbd{C-M-k}
(@code{kill-sexp}). @kbd{C-M-k} kills the characters that @kbd{C-M-f} (@code{kill-sexp}). This kills the text that @kbd{C-M-f} would move
would move over. over.
@cindex transposition of expressions @cindex transposition of expressions
@kindex C-M-t @kindex C-M-t
@findex transpose-sexps @findex transpose-sexps
A somewhat random-sounding command which is nevertheless handy is @kbd{C-M-t} (@code{transpose-sexps}) switches the positions of the
@kbd{C-M-t} (@code{transpose-sexps}), which drags the previous previous balanced expression and the next one. It is analogous to the
balanced expression across the next one. An argument serves as a @kbd{C-t} command, which transposes characters (@pxref{Transpose}).
repeat count, moving the previous expression over that many following An argument to @kbd{C-M-t} serves as a repeat count, moving the
ones. A negative argument drags the previous balanced expression previous expression over that many following ones. A negative
backwards across those before it (thus canceling out the effect of argument moves the previous balanced expression backwards across those
@kbd{C-M-t} with a positive argument). An argument of zero, rather before it. An argument of zero, rather than doing nothing, transposes
than doing nothing, transposes the balanced expressions ending at or the balanced expressions ending at or after point and the mark.
after point and the mark.
@kindex C-M-@@ @kindex C-M-@@
@kindex C-M-@key{SPC} @kindex C-M-@key{SPC}
@findex mark-sexp @findex mark-sexp
To operate on balanced expressions with an operation which acts on To operate on balanced expressions with a command which acts on the
the region, use the command @kbd{C-M-@key{SPC}} (@code{mark-sexp}). region, type @kbd{C-M-@key{SPC}} (@code{mark-sexp}). This sets the
This sets the mark at the same place that @kbd{C-M-f} would move to. mark where @kbd{C-M-f} would move to. While the mark is active, each
@xref{Marking Objects}, for more information about this command. successive call to this command extends the region by shifting the
mark by one expression. Positive or negative numeric arguments move
@kbd{C-M-@key{SPC}} treats the mark forward or backward by the specified number of expressions.
numeric arguments in the same way as @kbd{C-M-f}; in particular, a The alias @kbd{C-M-@@} is equivalent to @kbd{C-M-@key{SPC}}.
negative argument puts the mark at the beginning of the previous @xref{Marking Objects}, for more information about this and related
balanced expression. The alias @kbd{C-M-@@} is equivalent to commands.
@kbd{C-M-@key{SPC}}. While the mark is active, each successive use of
@kbd{C-M-@key{SPC}} extends the region by shifting the mark by one
sexp.
In languages that use infix operators, such as C, it is not possible In languages that use infix operators, such as C, it is not possible
to recognize all balanced expressions as such because there can be to recognize all balanced expressions because there can be multiple
multiple possibilities at a given position. For example, C mode does possibilities at a given position. For example, C mode does not treat
not treat @samp{foo + bar} as a single expression, even though it @samp{foo + bar} as a single expression, even though it @emph{is} one
@emph{is} one C expression; instead, it recognizes @samp{foo} as one C expression; instead, it recognizes @samp{foo} as one expression and
expression and @samp{bar} as another, with the @samp{+} as punctuation @samp{bar} as another, with the @samp{+} as punctuation between them.
between them. Both @samp{foo + bar} and @samp{foo} are legitimate However, C mode recognizes @samp{(foo + bar)} as a single expression,
choices for ``the expression following point'' when point is at the because of the parentheses.
@samp{f}, so the expression commands must perforce choose one or the
other to operate on. Note that @samp{(foo + bar)} is recognized as a
single expression in C mode, because of the parentheses.
@node Moving by Parens @node Moving by Parens
@subsection Moving in the Parenthesis Structure @subsection Moving in the Parenthesis Structure
...@@ -776,19 +735,18 @@ single expression in C mode, because of the parentheses. ...@@ -776,19 +735,18 @@ single expression in C mode, because of the parentheses.
@cindex braces, moving across @cindex braces, moving across
@cindex list commands @cindex list commands
The Emacs commands for handling parenthetical groupings see nothing The following commands move over groupings delimited by parentheses
except parentheses (or whatever characters must balance in the (or whatever else serves as delimiters in the language you are working
language you are working with). They ignore strings and comments with). They ignore strings and comments, including any parentheses
(including any parentheses within them) and ignore parentheses quoted within them, and also ignore parentheses that are ``quoted'' with an
by an escape character. They are mainly intended for editing escape character. These commands are mainly intended for editing
programs, but can be useful for editing any text that has parentheses. programs, but can be useful for editing any text containing
They are sometimes called ``list'' commands because in Lisp these parentheses. They are referred to internally as ``list'' commands
groupings are lists. because in Lisp these groupings are lists.
These commands assume that the starting point is not inside a string These commands assume that the starting point is not inside a string
or a comment. Sometimes you can invoke them usefully from one of or a comment. If you invoke them from inside a string or comment, the
these places (for example, when you have a parenthesised clause in a results are unreliable.
comment) but this is unreliable.