In emacs, how do I align closing parentheses with the start of the opening line?

Solution 1:

  • For the many modes derived from CC Mode (for example, c-mode, java-mode, php-mode), customise c-offsets-alist so that arglist-close is set to c-lineup-close-paren.
  • For cperl-mode, customise cperl-indent-parens-as-block to true.
  • For cperl-mode, GNU Emacs 24.3+, set cperl-close-paren-offset to the negative of cperl-indent-level
  • For perl-mode in GNU emacs 24.3 and greater, customise perl-indent-parens-as-block to true.
  • For python-mode, this behaviour is found in GNU emacs 24.3 and greater.

You can customise a variable by typing M-x customize-variable. Alternatively, add the following lines to your ~/.emacs:

(add-to-list 'c-offsets-alist '(arglist-close . c-lineup-close-paren))
(setq cperl-indent-parens-as-block t)
(setq perl-indent-parens-as-block t)