3

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.

1 Answer 1

3

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
    Commented Jul 29, 2019 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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