php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

2 blanks indentation

Open dmelch opened this issue 5 years ago • 8 comments

Sorry if this is a stupid question but is it possible to custamize php-mode so that it uses two blanks (instead of four blanks) of identation for indenting blocks? My php-code is already formatted in this way and it would like to keep the indentation.

Many thanks in advance,

Dirk

dmelch avatar Nov 06 '20 08:11 dmelch

@dmelch

An easy way is to add the following code in the php-mode-hook of the Emacs initialization file.

(setq tab-width 2)

For example:

(add-hook 'php-mode-hook
          (lambda()
            (setq tab-width 2))

It is more recommended to set it with EditorConfig. See https://editorconfig.org/ and editorconfig-emacs.

zonuexe avatar Nov 08 '20 20:11 zonuexe

Hallo zonuexe

thank you for your help but unfortunately it didn't help, there are still 4 blanks used for indentation when using php-mode.

Dirk

dmelch avatar Nov 09 '20 07:11 dmelch

I think c-basic-offset may be the variable you need to set?

Don't have time to check now, but wanted to mention it before I forget I saw this thread.

NateEag avatar Nov 10 '20 19:11 NateEag

@NateEag

thank you very much that worked for me! I put

(add-hook 'php-mode-hook (lambda() (c-basic-offset 2))

in my .emacs file

Dirk

dmelch avatar Nov 11 '20 07:11 dmelch

sorry, this is correct:

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

Dirk

dmelch avatar Nov 11 '20 07:11 dmelch

Awesome. Glad I could help.

NateEag avatar Nov 11 '20 16:11 NateEag

@zonuexe Think it'd be worth it if I could find a few minutes to expand the documentation to mention c-basic-offset in the coding style section?

NateEag avatar Nov 11 '20 19:11 NateEag

Yes I think that's a good idea!

dmelch avatar Nov 12 '20 08:11 dmelch