Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force spaces instead of tabs regardless of major mode?

Tags:

emacs

I want all tabs to be 4 spaces. I have the following in .emacs

(setq-default indent-tabs-mode nil)
(setq c-basic-indent 4)
(setq tab-width 4)

But this gets overwritten by some of the major mode themes that I can use. Is there a way to force this issue through my .emacs file?

like image 400
David Avatar asked May 05 '11 17:05

David


2 Answers

Try this to overwrite whatever any major mode overwrites:

(add-hook 'after-change-major-mode-hook 
          '(lambda () 
             (setq-default indent-tabs-mode nil)
             (setq c-basic-indent 4)
             (setq tab-width 4)))

Note though that major modes that aren't based on c-mode are not likely to care about c-basic-indent and may potentially use their own, mode-specific indentation variables. In such cases, there's no way around configuring these variables manually.

like image 188
Thomas Avatar answered Oct 31 '22 14:10

Thomas


Declare a default C indentation style, rather than declaring specific style parameters.

(setq c-default-style "k&r2")  ;; or whatever your preference is
(set-default 'indent-tabs-mode nil)
like image 31
Gilles 'SO- stop being evil' Avatar answered Oct 31 '22 14:10

Gilles 'SO- stop being evil'