How can I setup emacs to change space to TAB character for indent? [duplicate]

Posted on

Problem :

I am writing code for Linux kernel driver.

The coding standard said

The first rule that everyone needs to follow is to use the Tab character rather than spaces, to indent code. Also, the Tab character should represent eight spaces. Following along with the eight-character Tab indentation, the code should not flow past the 80 character line limit on the right of the screen.

Can you please tell me how can I change to use TAB character to space in emacs for indenting?

And use a eight character tab indentation?

Solution :

(setq indent-tabs-mode t)
(setq tab-stop-list (number-sequence 8 200 8))
(setq tab-width 8)
(setq indent-line-function 'insert-tab)

To make it mode specific you can do something like this (just substitute michael-special-mode-hook with whatever mode you are using to write your code):

(add-hook 'michael-special-mode-hook (lambda ()
  (setq indent-tabs-mode t)
  (setq tab-stop-list (number-sequence 8 200 8))
  (setq tab-width 8)
  (setq indent-line-function 'insert-tab) ))

Leave a Reply

Your email address will not be published. Required fields are marked *