views:

159

answers:

3

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...

  1. When I hit the TAB Key, and when I always hit the TAB key, I want 4 SPACES inserted.
  2. 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.

A: 

You can use M-x untabify to convert all tabs to spaces.

Well in that case you can set the value of indent-tabs-mode to nil for your php minor mode.

You may also find the wiki: http://www.fnal.gov/docs/products/emacs/emacs/emacs_23.html#SEC185 and Jamie Zawinski's post: http://www.jwz.org/doc/tabs-vs-spaces.html to be informative.

chollida
OK, good to know. But I want this to be a permanent setting for when I edit files in PHP and other modes.
Urda
+3  A: 

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)
Andrew Stein
OK, that didn't help in php mode (still 2) and for general editing it used 8 spaces.
Urda
Added a line on how to change to 4 spaces in general editing. Php mode probably has its own setting for this.
Andrew Stein
You have a syntax error. I would assume it is `(setq-default tab-width 4)` And that did not help at all. And yes I am making sure EMACS is taking the new configuration each time I try it.
Urda
For modes based off the C mode, you can use the `c-basic-offset` variable to determine how many columns to indent. Try `(setq-default c-basic-offset 4)`
jamessan
Oh, I didn't know that PHP is based on C mode -- should have guessed. I will add it to my answer. Thanks jamessan.
Andrew Stein
Still no good. See updates
Urda
...re-install Emacs corrected the problem. Your stuff works.
Urda
A: 

This is what I've done.

;;;; Tab settings ;;;;
;Tab width is 3
(setq tab-width 3)
(setq-default tab-width 3) ;;going to force it. yessir.
;Use spaces always.
(setq-default indent-tabs-mode nil)
;Jump by 3.
(setq c-basic-offset 3)
;this defaulted to 4 and had to be reset to 3. the prior settings did not override it. Lame.
(setq perl-indent-level 3)
;Tab stop list out to col 60
;Manually set by x3
(setq tab-stop-list '(3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60))
Paul Nathan
Why do you have 2 `(setq-default tab-width 3)` in a row?
Gabe
Excessive stupidity. Why do you ask?
Paul Nathan