Skip navigation

I know this is subjective, but it didn’t feel right being overridden by the editor rules on how the code should look. For quite a while until recently could only partially deactivate the mechanism that automatically handles indentation (there are dozens of functions and variables involved). Luckily I came across a hack that allows to turn off all syntactic indentation that happens within a mode.

; I don't want emacs making changes I can't control in regards of the indentation.
; This is a hairy issue but I want php to be just a major mode with syntax coloring and bracket balancing.

; to use PHP mode,
(autoload 'php-mode "php-mode" "PHP editing mode" t)
(add-to-list 'auto-mode-alist '("\\.php3\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode))

(add-hook 'php-mode-hook
          '(lambda ()
             (define-key php-mode-map (kbd "C-c C-c") 'comment-or-uncomment-region)
             (setq tab-width 4)
             (highlight-regexp "<\\?php" 'hi-blue)              
             (highlight-regexp "\\?>" 'hi-blue)))

(defun my-php-setup ()
  (local-set-key (kbd "TAB") 'tab-to-tab-stop)
  (local-set-key (kbd "{") 'self-insert-command) ; support for "{" needed
  (local-set-key (kbd "}") 'self-insert-command)
  (local-set-key (kbd ":") 'self-insert-command)
  (local-set-key (kbd ";") 'self-insert-command))

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


One Comment

  1. If you want to disable the electric mode which is what does the auto indentation after pressing the {}:; do this:

    (setq-default c-electric-flag nil)

One Trackback/Pingback

  1. […] Nachopp’s Blog rants about emacs, gnu tools, web programming and stuff like that About « customizing emacs, deactivate automatic indentation […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: