0

My friend and I collaborate on a C++ project and we agree to use 4 whiltespaces for indentation. I am using Emacs and this is my indentation setting

(setq-default c-basic-offset 4) 

By doing this, I believe that I can use tab safely without pressing the space bar for 4 or 8 or 12 times. However, my friends (Eclipse user) and I see awkwardly indented (misaligned) code in our own code editor. Then we accuse each other for using tabs instead of 4 whitespaces.

How can I find the ground truth in our cpp file? We want to know who introduces \t to our code.

We use svn for source control and do not have a nice UI for code review. So I prefer to check this \t character locally.

Yixing Liu
  • 133
  • 6
  • Related search here on emacs.se: https://emacs.stackexchange.com/search?q=indent-tabs-mode Note, there are situations where (setq-default indent-tabs-mode nil) has not the desired effect, e.g. when smart-tabs-mode is activated by default. – Tobias Jul 06 '18 at 05:10

1 Answers1

2

First of all you should set the default value of indent-tabs-mode to nil. Either toggle it off with customize or put the following lisp code into your init file.

(setq-default indent-tabs-mode nil)

You can check for tabs in a file with M-x white-space-mode in its buffer. Tabs are indicated with » when that mode is active.

If you want to prominently highlight tabs permanently you can use the following code from emacswiki in your init file.

;; Draw tabs with the same color as trailing whitespace  
(add-hook 'font-lock-mode-hook  
      (lambda ()  
        (font-lock-add-keywords  
         nil  
         '(("\t" 0 'trailing-whitespace prepend)))))
Tobias
  • 33,167
  • 1
  • 37
  • 77