java - How to auto-format code in Emacs just like in Netbeans IDE -


i new emacs , know if can auto-format code variety of languages (java, c++, html, latex) auto-format option in netbeans ide.

i know

  • whether feature built-in
  • can download el file option
  • how customize preferences of auto-format (tab-length, lines between functions, braces in new line or in same line, etc) in netbeans.

(versions: emacs-24 on ubuntu-12.04 / os-x-10.9)

you find if called indent. indeed, there many interactive functions start indent. find them m-x indent tab. can find documentation c-h ?, if try c-h d ret indent ret search in functions' documentation, or m-x apropos ret foo ret find them.

the following built in , work different languages (just tried elisp, python , javascript):

  • m-x indent-region formats selected region,
  • indent-sexp formats current expression

there no global option configure indentation, need dive in each mode's options. there options (setq html-tab-width 4).

edit: hints: (setq tab-width 8), (setq c-set-style "k&r"), (setq c-basic-offset 8) , emacs' built in c-mode or gnu indent can switch styles: https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html#choosing-a-style or https://www.gnu.org/software/indent/manual/indent.html#sec4