Different tab indent settings in different modes

I am currently using whitespace-cleanup in my save cache. Using indent-tabs-mode , I can save files without any tabs.

All is well, I do not need tabs in my files. But.

Make files need tabs. It is my problem. How to change my settings for makefile mode?

I tried setq either indent-tabs-mode (the document says it is becoming a buffer) or whitespace-style , it does not work.

+7
source share
3 answers

I had the same problem and it seems like this is a bug in Emacs (starting from 24.2). Try this using the following .emacs :

 (setq-default indent-tabs-mode nil) (add-hook 'after-save-hook 'whitespace-cleanup) 

If you open the file, save it and open the Makefile, you will have the problem that you described. But if you open the Makefile first, save it and then open another type of file, you will have the opposite problem: 8 spaces will be replaced by tabs.

The problem is that indent-tabs-mode is a local buffer, but in whitespace.el it is set to a regular variable called whitespace-indent-tabs-mode . Therefore, the first meaning that sees is that which is considered.

Here is another workaround that solves other problems as well. Add this to your .emacs :

 (defadvice whitespace-cleanup (around whitespace-cleanup-indent-tab activate) "Fix whitespace-cleanup indent-tabs-mode bug" (let ((whitespace-indent-tabs-mode indent-tabs-mode) (whitespace-tab-width tab-width)) ad-do-it)) 
+2
source

Good, my bad. Files were uploaded before the mode change.

The following code works fine if it is loaded into .emacs before opening any file (I have my own project manager that reopens the latest files).

 (defun my-tabs-makefile-hook () (setq indent-tabs-mode t)) (add-hook 'makefile-mode-hook 'my-tabs-makefile-hook) 
+3
source

The best solution I've found for spaces is ethan-wspace . It clears any gaps that you yourself have lured, but left the other gaps intact.

It works for tabs in makefiles and avoids the messy scatter problem, where there are many different lines that are just whitespace variables.

0
source

All Articles