Skip to content

Instantly share code, notes, and snippets.

@mookid
Last active March 30, 2017 09:18
Show Gist options
  • Save mookid/6c149993042d699c4e037747c46722cf to your computer and use it in GitHub Desktop.
Save mookid/6c149993042d699c4e037747c46722cf to your computer and use it in GitHub Desktop.
Untabify
;; 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
(progn
(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))
(progn
(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