GNU Info

Info Node: (emacs)Moving by Defuns

(emacs)Moving by Defuns


Next: Imenu Prev: Left Margin Paren Up: Defuns
Enter node , (file) or (file)node

Moving by Defuns
----------------

   These commands move point or set up the region based on top-level
major definitions, also called "defuns".

`C-M-a'
     Move to beginning of current or preceding defun
     (`beginning-of-defun').

`C-M-e'
     Move to end of current or following defun (`end-of-defun').

`C-M-h'
     Put region around whole current or following defun (`mark-defun').

   The commands to move to the beginning and end of the current defun
are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').  If
you repeat one of these commands, or use a positive numeric argument,
each repetition moves to the next defun in the direction of motion.

   `C-M-a' with a negative argument -N moves forward N times to the
next beginning of a defun.  This is not exactly the same place that
`C-M-e' with argument N would move to; the end of this defun is not
usually exactly the same place as the beginning of the following defun.
(Whitespace, comments, and perhaps declarations can separate them.)
Likewise, `C-M-e' with a negative argument moves back to an end of a
defun, which is not quite the same as `C-M-a' with a positive argument.

   To operate on the current defun, use `C-M-h' (`mark-defun') which
puts point at the beginning and mark at the end of the current defun.
This is the easiest way to get ready to kill the defun in order to move
it to a different place in the file.  If you use the command while
point is between defuns, it uses the following defun.

   In C mode, `C-M-h' runs the function `c-mark-function', which is
almost the same as `mark-defun'; the difference is that it backs up
over the argument declarations, function name and returned data type so
that the entire C function is inside the region.  This is an example of
how major modes adjust the standard key bindings so that they do their
standard jobs in a way better fitting a particular language.  Other
major modes may replace any or all of these key bindings for that
purpose.


automatically generated by info2www version 1.2.2.9