LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2012, 07:01 AM   #1
tumiki
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Rep: Reputation: Disabled
[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
 
Old 12-12-2012, 11:25 AM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,061

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
You also have to set tab-width to 4, otherwise Emacs will only put a tab when you have 8 spaces of indentation.
 
Old 12-12-2012, 05:33 PM   #3
tumiki
LQ Newbie
 
Registered: Dec 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
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

Last edited by tumiki; 12-12-2012 at 05:38 PM.
 
Old 12-18-2012, 11:55 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,061

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Quote:
Originally Posted by tumiki View Post
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)?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.emacs indent question ArthurHuang Programming 4 12-31-2010 03:45 PM
emacs un-indent region jantman Linux - Software 4 12-28-2006 06:47 AM
tabs to spaces in emacs, not working in tcl mode ratm1286 Linux - Software 3 05-08-2005 06:15 PM
indent cpp file with emacs~ black Linux - Software 10 09-10-2004 01:43 AM
emacs - convert auto indent tabs to spaces? BrianK Linux - General 1 04-15-2004 11:14 PM


All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration