0

php-mode is not indenting delimiter:

<?php
// Not indenting PHP delimiter

if (true) {
    echo 'foo';
}

How to indent delimiter?

<?php
    // Indenting PHP delimiter

    if (true) {
        echo 'foo';
    }

I tryed:

(defun my-php-indent-setup ()
  (c-set-offset 'cpp-macro '+))

(add-hook 'php-mode-hook 'my-php-indent-setup)

But does nothing, and if I do it manually C-c C-o RET cpp-macro RET + RET it doesn't exactly do what I expected. I also tryed topmost-intro instead cpp-macro, but neither do what I expected.

1 Answer 1

1

This worked for me:

(defun my-php-indent-setup ()
    (c-set-offset 'topmost-intro '+) ; Does not affect <?php (but affects ?>)
    (c-set-offset 'inclass 0))       ; Gets the inside of class{} back to normal

(add-hook 'php-mode-hook 'my-php-indent-setup)

Note that the closing tag ?> will not be indented in the same level as <?php does, for example:

<?php
    // Indenting PHP delimiter

    if (true) {
        echo 'foo';
    }

    ?>

Anyways some PHP coding standards recommend to not include ?> in pure PHP files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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