开发者

In emacs, how to properly indent nested functions

In PHP code, I am currently using the following C indentation style:

(defconst my-c-style
  '((c-offsets-alist . ((arglist-close . 0)
                        (substatement-open . 0)
                        (case-label . +)))))

The problem is whe开发者_开发技巧n I nest functions (or arrays). I want automatic indentation to format the following way:

myFunc(array(
    'arg1' => $val1,
    'arg2' => $val2,
    'arg3' => $val3,
    'arg4' => $val4,
));

But instead, what I get is:

myFunc(array(
           'arg1' => $val1,
           'arg2' => $val2,
           'arg3' => $val3,
           'arg4' => $val4,
       ));

The code inside always lines up with the 'a' from array. Is there a way to resolve this by modifying my C style? Currently I have to manually line up the closing parenthisis.


Try what is suggested here if you are using the PHP-Mode.


Current php-mode releases as available via MELPA will out-of-the-box indent to your liking; I tried wordpress, pear, php and drupal indentation modes -- every one did what you want (drupal using 2 spaces per indentation step).

You can configure the indentation style either by setting php-mode-coding-style in your config, or try them out interactivly by calling c-set-style in a php-mode buffer, normaly bound to C-c .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜