Skip to content

Instantly share code, notes, and snippets.

Last active Mar 30, 2017
What would you like to do?
;; I don't want to introduce tabs in my code; but I don't want to break Makefiles,
;; or to introduce diffs in third party code.
;; Here is my solution:
(defun my-untabify-buffer ()
"Untabify the current buffer, unless `my-untabify-this-buffer' is nil."
(and my-untabify-this-buffer (untabify (point-min) (point-max))))
(define-minor-mode my-untabify-mode
"Untabify buffer on save." nil " untab" nil
(if my-untabify-mode
(make-variable-buffer-local 'my-untabify-this-buffer)
(setq my-untabify-this-buffer (not (derived-mode-p 'makefile-mode)))
(add-hook 'before-save-hook 'my-untabify-buffer nil t))
(kill-local-variable 'my-untabify-this-buffer)
(remove-hook 'before-save-hook 'my-untabify-buffer t))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment