tags:

views:

1067

answers:

3
+1  Q: 

php mode for emacs

I'm having trouble with my php code not indenting correctly...

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 tired googling for similar things and tried adding the following to my .emacs, but it 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))))
+1  A: 

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

From what I understand, PHP mode is built on top of c mode, so it inherits its customizations.

Jonathan Arkell
A: 

Try with this:

(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)))
troelskn
+1  A: 

Customize c-default-style variable. Add this to your .emacs file:

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

Description of bsd style.

Pavel Chuchuva