views:

396

answers:

3

I typically code my PHP with one level of indentation after the initial <?php, but I'm having trouble finding a setting for this in Emacs with php-mode.

To be clear, here's what Emacs is doing:

<?php
echo "Hello.";

if (something)
    do_something();

And here's how I usually code:

<?php
    echo "Hello.";

    if (something)
        do_something();

Emacs version 23 (straight from CVS), php-mode 1.5.0.

A: 

php-mode derives from c-mode, so I think all you need is:

(setq-default indent-tabs-mode nil)
(setq standard-indent 2)
(setq default-tab-width 2)
(add-hook 'c-mode-common-hook
  #'(lambda ()
    (setq c-basic-offset tab-width)))

If that's not what you meant, maybe you are looking for tab-stop-list?

troelskn
Nope, don't think that'll work. That just sets the tab settings, I don't see anything in there for the initial indent level. (I also ran it in Emacs and nothing has changed except for my tab widths.)
Alex Suraci
+1  A: 

I don't have a php-mode, but in c-modes, M-x c-set-offset can help. - it'll allow you to customize the offset for a syntactic element, and it shows you what element was used for the current line.

Cheeso
Almost got it by setting topmost-intro to 4, but unfortunately the indents everything over 4 spaces, including the `<?php`.
Alex Suraci
Ah - You may have to use M-x c-set-offset in different syntax elements, to get the other settings required.
Cheeso
Hm, is there a way to get the syntax element of the item under the point?
Alex Suraci
in cc-mode and csharp-mode and java-mode, I use M-x c-set-offset.
Cheeso
@Alex: anywhere in the source code typing `M-x c-set-offset` allows you to set the syntax element of item under the point. In your case, you need to change 'topmost-intro'.
Török Gábor
A: 

Found a solution, I think:

(c-set-offset 'topmost-intro 4)
(c-set-offset 'cpp-macro -4)

Seems to be working. topmost-intro sets everything, and as far as I can tell cpp-macro only sets the <?php tags.

Thanks to Cheeso for the hint which led me to the answer.

Alex Suraci