I'm currently using whitespace-cleanup
in my save hook. Using indent-tabs-mode
, I'm able to save files without any tabs.
All is well, I don't want tabs in my files. But.
Makefiles do need tabs. That is my problem. How do I change my settings for makefile-mode?
I tried to setq
either indent-tabs-mode
(the doc says it becomes buffer-local) or whitespace-style
, it does not work.
OK, my bad. Files were loaded before changing the mode.
The following code works fine, provided it is loaded in the .emacs before opening any file (I have my own project manager which re-opens last files).
(defun my-tabs-makefile-hook ()
(setq indent-tabs-mode t))
(add-hook 'makefile-mode-hook 'my-tabs-makefile-hook)
I've had the same problem, and it seems that this is a bug in Emacs (as of 24.2). Try this, using the following .emacs
:
(setq-default indent-tabs-mode nil)
(add-hook 'after-save-hook 'whitespace-cleanup)
If you open a file, save it, and then open a Makefile, you'll have the problem you described. But if you open a Makefile first, save it, and then open another type of file, you'll have the opposite problem: 8 spaces will be replaced by tabs.
The problem is that indent-tabs-mode
is buffer-local, but in whitespace.el
it is set to a regular variable called whitespace-indent-tabs-mode
. Hence, the first value that's seen is the one that counts.
Here's another workaround that solves some other problems too. 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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With