Emacs calls a function definition a “defun”, because defun
is the keyword¹ that starts a function definition starts in Lisp. Commands to move by defuns use the modifiers Ctrl+Alt:
C-M-a
and C-M-e
to move to the beginning/end of the current function definition;
C-M-h
to select the current function definition.
This is somewhat similar, but not strictly parallel, to M-a
and M-e
to move to the beginning/end of the current sentence, and M-h
to select the current paragraph.
The exact behavior of these commands depend on the programming language. The default rule is that a defun starts with a line with 0 indentation, but many programming language modes change this, either by tuning the way the default function works or by binding the usual keyboard shortcuts to a different function.
On a related note, Emacs calls a subexpression a “sexp”. Generally a sexp is delimited by balanced parentheses, brackets or braces, or is a single identifer. Again the exact rules depend on the programming language. The main commands for sexps are:
C-M-b
and C-M-f
to move back/forward to the previous/next sexp.
C-M-p
and C-M-n
to move back/forward to the previous/next expression delimited by parentheses (the exact rules depend on the language, but typically this stops in fewer places than C-M-b
and C-M-f
).
C-M-u
(M-x backward-up-list
) and M-x up-list
(no default binding) to move out of the surrounding parentheses/brackets/braces.
C-M-SPC
or C-M-@
to select the following sexp.
¹ Not a keyword, strictly speaking, but close enough.