In php-mode – and in many others I believe – indentation of an expression spreading over several lines is computed relative to the starting column of the expression rather than the column of the first non-blank character of the line where the expression starts.
This is displayed by the following snippet, where the return
keyword is indented four columns counting from the a
starting the array_map(…)
expression:
<?php
function weights($volumes, $density)
{
$weights = array_map(function ($volume) {
return $volume * $density;
}, $volumes);
return $weights;
}
I must follow another indentation style, where the return
keyword is indented four columns counting from the $
of $weights
which is the first non-blank character of the line where the array_map
expression starts.
<?php
function weights($volumes, $density)
{
$weights = array_map(function ($volume) {
return $volume * $density;
}, $volumes);
return $weights;
}
How can I configure Emacs and the c-mode to use this second style? I could not find any reference to this behaviour on the emacs-wiki.
The indentation settings in use are the following:
(c-add-style "my-php-style"
'("gnu"
(c-basic-offset . 4)
(c-offsets-alist
(arglist-cont . 0)
(arglist-intro . +)
(block-close . 0)
(defun-block-intro . +)
(defun-close . 0)
(defun-open . 0)
(statement . 0)
(statement-block-intro . +)
(topmost-intro . 0)
(access-label . -)
(annotation-top-cont . 0)
(annotation-var-cont . +)
(arglist-close . c-lineup-arglist-operators)
(arglist-cont-nonempty . c-lineup-math)
(block-open . 0)
(brace-entry-open . 0)
(brace-list-close . 0)
(brace-list-entry . 0)
(brace-list-intro . +)
(brace-list-open . +)
(c . c-lineup-C-comments)
(case-label . +)
(catch-clause . 0)
(class-close . 0)
(class-open . 0)
(comment-intro . c-lineup-comment)
(composition-close . 0)
(composition-open . 0)
(cpp-define-intro c-lineup-cpp-define +)
(cpp-macro . -1000)
(cpp-macro-cont . +)
(do-while-closure . 0)
(else-clause . 0)
(extern-lang-close . 0)
(extern-lang-open . 0)
(friend . 0)
(func-decl-cont . +)
(inclass . +)
(incomposition . +)
(inexpr-class . +)
(inexpr-statement . +)
(inextern-lang . +)
(inher-cont . c-lineup-multi-inher)
(inher-intro . +)
(inlambda . c-lineup-inexpr-block)
(inline-close . 0)
(inline-open . 0)
(inmodule . +)
(innamespace . +)
(knr-argdecl . 0)
(knr-argdecl-intro . 5)
(label . 0)
(lambda-intro-cont . +)
(member-init-cont . c-lineup-multi-inher)
(member-init-intro . +)
(module-close . 0)
(module-open . 0)
(namespace-close . 0)
(namespace-open . 0)
(objc-method-args-cont . c-lineup-ObjC-method-args)
(objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +)
(objc-method-intro .
[0])
(statement-case-intro . +)
(statement-case-open . +)
(statement-cont . +)
(stream-op . c-lineup-streamop)
(string . -1000)
(substatement . +)
(substatement-label . 0)
(substatement-open . +)
(template-args-cont c-lineup-template-args +)
(topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont))))