LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [Emacs] (setq indent-tabs-mode t) not working (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bemacs%5D-setq-indent-tabs-mode-t-not-working-4175441112/)

tumiki 12-12-2012 06:01 AM

[Emacs] (setq indent-tabs-mode t) not working
 
Hello Group,

version: emacs23 23.2+1-7

I am trying to get Emacs to write a TAB instead of spaces when hitting the [tab] key. I have my .emacs configured as follows.

Code:


;; C-mode
(defun my-c-mode-hook ()
    (setq c-basic-offset 4)
    (setq indent-tabs-mode t)
    (local-set-key (kbd "RET") 'newline-and-indent))

(add-hook 'c-mode-hook 'my-c-mode-hook)

While in c-mode, Emacs inserts 4 spaces when hitting the [tab] key. Is there anything else that needs to be added on the configuration?

Regards,
Tumiki

ntubski 12-12-2012 10:25 AM

You also have to set tab-width to 4, otherwise Emacs will only put a tab when you have 8 spaces of indentation.

tumiki 12-12-2012 04:33 PM

Hello ntubski,

Thank you for your reply. I added that statement on my .emacs but Emacs still writes 4 four spaces.

Code:

;; C-mode
(defun my-c-mode-hook ()
    (setq  tab-width 4)
    (setq c-basic-offset 4)
    (setq indent-tabs-mode t)
    (local-set-key (kbd "RET") 'newline-and-indent))

(add-hook 'c-mode-hook 'my-c-mode-hook)

; I also tried
; (add-hook 'c-mode-common-hook 'my-c-mode-hook)

Regards,
Tumiki

ntubski 12-18-2012 10:55 AM

Quote:

Originally Posted by tumiki (Post 4848043)
I added that statement on my .emacs but Emacs still writes 4 four spaces.

I can't reproduce your problem. Maybe you have other things in your .emacs that affect these settings? Did you remember to apply the settings after adding them (either by evaluating the code & re-entering C mode, or restarting Emacs)?


All times are GMT -5. The time now is 12:34 AM.