php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

Indentation of a block nested in a function call chain

Open Fuco1 opened this issue 8 years ago • 3 comments

This is maybe not so much an issue or a bug report as a request for help. Currently when we nest function calls and then put a block inside, for example an anonymous function it indents it "that many times" as there are function calls.

I also present some other modes and how they handle it so it might be worth to behave similarly.

<?php

function() {
    foo(bar(function () {
                return 1;
            }));

    foo(bar(fux(function () {
                    return 2;
                })));
}

What I would like to have is something like

<?php

function() {
    foo(bar(function () {
        return 1;
    }));

    foo(bar(fux(function () {
        return 2;
    })));
}

This is also "compatible" with how js2-mode works

function foo() {
    foo(bar(function () {
        return 1;
    }));

    foo(bar(fux(function () {
        return 2;
    })));
}

java-mode works similarly but always indents "one step" further

class Test
{
    string foo() {
        foo(bar(new Interface () {
                return 1;
            }));

        foo(bar(fux(new Interface () {
                return 2;
            })));
    }
}

I think being consistent and not depending on the depth is a more natural way to handle the indentation even by default.

Edit: seems to be related to #251

Fuco1 avatar Feb 13 '18 15:02 Fuco1

In my environment, perhaps indentation as you expect works.

php-mode-indentation

--- PHP-MODE DEBUG BEGIN ---
PHP Mode 1.18.4 of 2018-01-30
versions: GNU Emacs 26.0.91 (build 1, x86_64-apple-darwin17.4.0, NS appkit-1561.20 Version 10.13.3 (Build 17D47))
 of 2018-02-13; PHP Mode 1.18.4 of 2018-01-30
major-mode: php-mode
minor-modes: (hi-lock-mode superword-mode subword-mode macrostep-mode edebug-mode winner-mode ido-ubiquitous-mode ido-cr+-debug-mode minibuffer-electric-default-mode helm-adaptive-mode elisp-slime-nav-mode nameless-mode ispell-minor-mode auto-complete-mode rainbow-mode paredit-mode yafolding-mode vi-tilde-fringe-mode idle-highlight-mode goto-address-prog-mode goto-address-mode copy-file-on-save-mode dmacro-mode keyfreq-autosave-mode keyfreq-mode atomic-chrome-edit-mode hamburger-menu-mode indent-guide-mode beacon-mode right-click-context-mode crux-reopen-as-root-mode ido-everywhere smooth-scroll-mode which-key-mode mc-hide-unmatched-lines-mode rectangular-region-mode multiple-cursors-mode rectangle-mark-mode dired-hide-details-mode undo-tree-visualizer-selection-mode undo-tree-mode shell-dirtrack-mode recentf-mode flymake-mode yas-minor-mode which-function-mode electric-pair-mode flycheck-mode projectile-mode compilation-minor-mode compilation-shell-minor-mode ibuffer-auto-mode editorconfig-mode helm-mode helm-popup-tip-mode helm-autoresize-mode helm--remap-mouse-mode helm--minor-mode helm-migemo-mode async-bytecomp-package-mode xref-etags-mode volatile-highlights-mode show-paren-mode nyan-mode pallet-mode package-build-minor-mode url-handler-mode cl-old-struct-compat-mode tooltip-mode eldoc-mode electric-quote-mode electric-layout-mode electric-indent-mode mouse-wheel-mode tool-bar-mode paragraph-indent-minor-mode prettify-symbols-mode use-hard-newlines menu-bar-mode file-name-shadow-mode horizontal-scroll-bar-mode jit-lock-debug-mode font-lock-mode blink-cursor-mode window-divider-mode auto-composition-mode unify-8859-on-decoding-mode unify-8859-on-encoding-mode auto-encryption-mode auto-compression-mode temp-buffer-resize-mode visible-mode buffer-read-only size-indication-mode column-number-mode line-number-mode auto-fill-function visual-line-mode transient-mark-mode next-error-follow-minor-mode completion-in-region-mode auto-save-visited-mode auto-save-mode auto-fill-mode abbrev-mode overwrite-mode view-mode hs-minor-mode)
variables: ((indent-tabs-mode nil) (tab-width 8))
custom variables: ((php-executable /usr/local/bin/php) (php-default-face default) (php-speedbar-config t) (php-mode-speedbar-open nil) (php-template-compatibility t) (php-lineup-cascaded-calls nil) (php-extra-constants nil) (php-do-not-use-semantic-imenu t) (php-site-url https://secure.php.net/) (php-manual-url ja) (php-search-url nil) (php-completion-file ) (php-manual-path ) (php-mode-hook (my/php-mode-hook)) (php-mode-pear-hook nil) (php-mode-drupal-hook nil) (php-mode-wordpress-hook nil) (php-mode-symfony2-hook nil) (php-mode-psr2-hook nil) (php-mode-force-pear nil) (php-mode-warn-if-mumamo-off t) (php-mode-coding-style pear) (php-search-documentation-browser-function nil) (php-class-suffix-when-insert ::) (php-namespace-suffix-when-insert \))
c-indentation-style: psr2
c-style-variables: ((c-offsets-alist (string . c-lineup-dont-change) (c . c-lineup-C-comments) (defun-open . 0) (defun-close . 0) (defun-block-intro . +) (class-open . 0) (class-close . 0) (inline-open . +) (inline-close . 0) (func-decl-cont . +) (knr-argdecl-intro . +) (knr-argdecl . 0) (topmost-intro . 0) (topmost-intro-cont . c-lineup-topmost-intro-cont) (annotation-top-cont . 0) (annotation-var-cont . +) (member-init-intro . +) (member-init-cont . c-lineup-multi-inher) (inher-intro . +) (inher-cont . c-lineup-multi-inher) (block-open . 0) (block-close . 0) (brace-list-open . 0) (brace-list-close . 0) (brace-list-intro . +) (brace-list-entry . c-lineup-under-anchor) (brace-entry-open . 0) (statement . 0) (statement-cont . +) (statement-block-intro . +) (statement-case-intro . +) (statement-case-open . 0) (substatement . +) (substatement-open . +) (substatement-label . 2) (case-label . 0) (access-label . -) (label . 2) (do-while-closure . 0) (else-clause . 0) (catch-clause . 0) (comment-intro c-lineup-knr-region-comment c-lineup-comment) (arglist-intro . +) (arglist-cont c-lineup-gcc-asm-reg 0) (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist) (arglist-close . +) (stream-op . c-lineup-streamop) (inclass . +) (cpp-macro . [0]) (cpp-macro-cont . +) (cpp-define-intro c-lineup-cpp-define +) (friend . 0) (objc-method-intro . [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 +) (extern-lang-open . 0) (namespace-open . 0) (module-open . 0) (composition-open . 0) (extern-lang-close . 0) (namespace-close . 0) (module-close . 0) (composition-close . 0) (inextern-lang . +) (innamespace . +) (inmodule . +) (incomposition . +) (template-args-cont c-lineup-template-args +) (inlambda . c-lineup-inexpr-block) (lambda-intro-cont . +) (inexpr-statement . +) (inexpr-class . +)) (c-label-minimum-indentation . 1) (c-backslash-max-column . 72) (c-backslash-column . 48) (c-hanging-semi&comma-criteria c-semi&comma-inside-parenlist) (c-hanging-colons-alist) (c-hanging-braces-alist (brace-list-open) (brace-entry-open) (statement-cont) (substatement-open after) (block-close . c-snug-do-while) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before) (arglist-cont-nonempty)) (c-cleanup-list scope-operator) (c-doc-comment-style (java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc)) (c-comment-prefix-regexp (pike-mode . //+!?\|\**) (awk-mode . #+) (other . //+\|\**)) (c-block-comment-prefix . * ) (c-indent-comments-syntactically-p) (c-indent-comment-alist (anchored-comment column . 0) (end-block space . 1) (cpp-end-block space . 2)) (c-comment-only-line-offset . 0) (c-basic-offset . 4) (c-basic-offset . 4) (c-offsets-alist (arglist-close . php-lineup-arglist-close) (arglist-cont first php-lineup-cascaded-calls 0) (arglist-cont-nonempty first php-lineup-cascaded-calls c-lineup-arglist) (arglist-intro . php-lineup-arglist-intro) (case-label . +) (class-open . 0) (comment-intro . 0) (inlambda . 0) (inline-open . 0) (namespace-open . 0) (lambda-intro-cont . +) (label . +) (statement-cont first php-lineup-cascaded-calls php-lineup-string-cont +) (substatement-open . 0) (topmost-intro-cont first php-lineup-cascaded-calls +)) (indent-tabs-mode) (tab-width . 8) (fill-column . 70) (require-final-newline) (show-trailing-whitespace . t) (php-style-delete-trailing-whitespace) (c-offsets-alist (statement-cont . +)) (c-indent-comments-syntactically-p . t) (fill-column . 78) (require-final-newline . t) (show-trailing-whitespace . t) (php-style-delete-trailing-whitespace . t))
--- PHP-MODE DEBUG END ---

I want to track down and solve your problem. If you have additional information please provide it.

Thank you.

zonuexe avatar Feb 14 '18 05:02 zonuexe

@zonuexe Thanks for looking into this. I've realized now I don't have the latest version of php-mode running. I will try to upgrade everything and test with bare Emacs to see what's going on. I realize I should've done that in the first place instead of wasting your time :blush:

Fuco1 avatar Feb 14 '18 09:02 Fuco1

So I've tested this in emacs -nw -q loading php-mode 1.18.3 (same as I use in my "production" emacs) and it indents as on your video. So probably I'm misconfiguring something, but I can't figure out what because I never touch anything to do with c-styles. The only thing I can think of is editorconfig-mode which does something with the styles but it seems not to be the problem because in -q it also works fine together with php-mode.

I will investigate further but for now we can assume this is a problem on my end. Sorry for the trouble :)

Fuco1 avatar Feb 14 '18 10:02 Fuco1