2

GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) PHP-Mode: https://github.com/emacs-php/php-mode, Version: 1.21.1

I customized c-basic-offset to 2.

When I open a php-File, php-mode is automatically invoked (by (add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode)) in .emacs) and c-basic-offset is set to 4. By C-h v c-basic-offset I can clearly see: 2 is recognized as global customization but the buffer-local setting is 4. Obviously, php-mode is doing this.

How can I alter this behaviour? Either, php-mode invocation does not touch c-basic-offset? Or, after loading php-mode a hook sets it back to 2.

Every attempt from my side failed so far.

2

This code in .emacs did the job:

(add-hook 'php-mode-hook
      (lambda ()
        (make-local-variable 'c-basic-offset)
        (setq c-basic-offset 2)))

I failed previously because I tried to change the global c-basic-offset. That didn't help as the local variable generated in php-mode took precedence (I think).

1
  • 1
    You most likely have the setq-local macro available to you to simplify that code. It's also better to use named functions in hooks rather than lambdas (easier to inspect, remove, modify, etc).
    – phils
    Jul 29 '19 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.