I can't find this: How do I use 4 SPACES instead of a TAB in EMACS?

elisp, emacs, php

Solution

Change the variable indent-tabs-mode to nil. You can do it interactively (for just one buffer) by `M-x set-variable`. To make it permanent (and for all buffers), put

 (setq-default indent-tabs-mode nil)

in your init file.

To make a tab do just 4 spaces in most modes, also add

 (setq-default tab-width 4)

For C based modes (like PHP) you will have to do:

(setq c-basic-offset 4)

Problem

I am making the jump to EMACS, and I can't find what I need to do in my `.emacs` file to get php-mode AND all other modes to insert 4 spaces instead of a TAB. Help? UPDATE: When I hit tab I still get 8 spaces in a plain file with the given answers. In php-mode I still get 2 spaces. Hitting tab in php mode does nothing, tab in regular EMACS adds 8 spaces. UPDATE2: This is what I have in my `.emacs`: ``` (require 'color-theme) (color-theme-calm-forest) (setq-default indent-tabs-mode nil) (setq-default tab-width 4) (setq c-basic-offset 4) ``` Still in regular files 8 spaces, and in PHP files the tabbing doesn't work, or jumps around randomly now. My php-mode is from the Ubuntu 9.10 `apt-get install php-mode` UDATE3: OK Here is what I want... - When I hit the TAB Key, and when I always hit the TAB key, I want 4 SPACES inserted. - I want the TAB key to jump to the relative position of the previous line (auto tab up to the last line, again entering in SPACES) These rules need to apply to all files but if necessary need to first and foremost apply to (text) and PHP files.

Original source