简体   繁体   中英

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))))

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

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

Description of bsd style .

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.

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM