Formatting Java Source Code in Emacs
When you wish to reindent several lines of Java code which have been altered or moved to a different level in the parenthesis structure, you have several commands available.
C-M-q
Reindent all the lines within one parenthetical grouping
(indent-sexp).
C-M-\
Reindent all lines in the region (indent-region).
C-u TAB
Shift an entire parenthetical grouping rigidly sideways so that its first line
is properly indented.
M-x indent-code-rigidly
Shift all the lines in the region rigidly sideways, but do not alter lines that
start inside comments and strings.
C-x h
Mark the whole current buffer