PHP Mode for Emacs

I am having problems with the wrong indentation of my php code ...

I would like my code to look like this

if (foo)
{
    print "i am indented";
}

but it always looks like this:

if (foo)
  {
    print "i am not indented correctly";
  }

I got tired of Google for things like this and tried to add the following to my .emacs, but that didn't work at all.

Any thoughts?

 (add-hook 'php-mode-hook
          (function (lambda ()
                      ;; GNU style
                      (setq php-indent-level 4
                            php-continued-statement-offset 4
                            php-continued-brace-offset 0
                            php-brace-offset 0
                            php-brace-imaginary-offset 0
                            php-label-offset -4))))
+5
source share
3 answers

Set c-default style variable. Add this to the .emacs file:

(setq c-default-style "bsd"
      c-basic-offset 4)

Bsd style description .

+12
source

Set the c-default-style variable. You either want your "Other" mode (or "php", if available) to be set to "bsd", or you can set the hte style in all modes to bsd.

, , PHP- c, .

+1

:

(defun my-build-tab-stop-list (width)
  (let ((num-tab-stops (/ 80 width))
        (counter 1)
        (ls nil))
    (while (<= counter num-tab-stops)
      (setq ls (cons (* width counter) ls))
      (setq counter (1+ counter)))
    (nreverse ls)))

(add-hook 'c-mode-common-hook
      #'(lambda ()
          ;; You an remove this, if you don't want fixed tab-stop-widths
          (set (make-local-variable 'tab-stop-list)
               (my-build-tab-stop-list tab-width))
          (setq c-basic-offset tab-width)
          (c-set-offset 'defun-block-intro tab-width)
          (c-set-offset 'arglist-intro tab-width)
          (c-set-offset 'arglist-close 0)
          (c-set-offset 'defun-close 0)
          (setq abbrev-mode nil)))
+1

All Articles