0

I need to indent my code with (add-hook 'php-mode-hook 'php-enable-symfony2-coding-style) but using tabs for indenting (and spaces for aligning, see https://www.emacswiki.org/emacs/SmartTabs). Apparently the coding styles of php-mode overrides emacs tab settings, because I have the next code in my emacs init file, but the spacebar indenting prevails nonetheless:

(setq tab-always-indent 'complete)
(setq-default indent-tabs-mode t)
(setq indent-tabs-mode t)
(setq tab-width 4)

Tabs were working before using php-mode.

Example of the indentation I use:

// Indenting with tabs
if (false
    || true
    || true
) {
    $hi = [
        'la',
        'do' => 5,
    ];

    $foo
        -> mi(
            54,
            57
        )

        -> fa()
    ;
} else {
    $lala =
        (new lala)
            -> hey()
            -> ho()
    ;

    $sup = work([
        'it' => 1,
        'faster' => 6,
    ]);

    // Aligning with spaces
    $a··· = 1;
    $ab·· = 2;
    $abcd = 4;
}

I am using (add-hook 'php-mode-hook 'php-enable-symfony2-coding-style) because it is the most similar amongst the php-mode available styles. Maybe I should turn off php-mode indentation and use other indentation?

1

Ok I was leaning how php-mode handles indentation, and also I looked into php-mode.el:

The problem was that (add-hook 'php-mode-hook 'php-enable-symfony2-coding-style) sets:

(setq indent-tabs-mode nil
        fill-column 78
        c-indent-comments-syntactically-p t
        require-final-newline t)

... before (c-set-style "symfony2"), so it is overriding how you configured indent-tabs-mode before.

To solve the problem, you can just discard php-enable-symfony2-coding-style and use:

(add-hook 'php-mode-hook '(lambda ()
                            (setq tab-width 4
                                  indent-tabs-mode t)
                            (c-set-style "symfony2")
                            ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.