Get some hints about whether your buffer is space- or tab-loving
As the Eternal Holy War of tabs-versus-spaces rages on, even within individual projects, an emacs minor mode arises from the depths of github with the goal of easing the burden placed on the programmer of trying to maintain consistency in text files.
If you jump into a file that uses tabs for indentation, you shall continue using tabs for indentation. If you jump into a file that uses spaces for indentation, you shall continue using spaces for indentation. That's the idea.
For the impatient, here's a quick setup example (after putting indent-hints.el in your load path):
(require 'indent-hints) (add-hook 'c-mode-common-hook 'indent-hints-activate)
You should probably at least customize the indent-hints-mode group to use your preferred space/tabs setup, like so:
M-x customize-group [RET] indent-hints [RET]
You can set up some "whitespace profiles" that get selected automatically when a buffer is detected to be tab-loving or space-loving. To enable this functionality, you should customize the
indent-hints-modegroup and enable indent-hints-profile-switching-enabled, or add to your .emacs:
(setq indent-hints-profile-switching-enabled t)
You can also add your own custom functions to the hooks
indent-hints-mode-space-loving-hookwhich run after a buffer is detected to be tab-loving or space-loving, respectively.
To disable profile switching for a particular C style, add the style name to
indent-hints-ignore-c-styles, for example:
(setq indent-hints-ignore-c-styles '("linux"))
Just check out your mode-line to see whether the buffer you're visiting is space-loving or tab-loving. It also shows the ratio of space-to-tab (or tab-to-space, whichever your buffer loves) loving-ness that your current buffer exudes. Here's a "screenshot":
test.el Top -- (Emacs-Lisp \t:0.53 yas pair)--etc. etc.--
The file being visited in the "screenshot" has more tabs than spaces (53% of the lines that start with some sort of indentation start with tabs, to be exact).
Activate the space-loving profile
Activate the tab-loving profile
The real meat. Examine the first character of each line in the buffer. This can be used to determine if a buffer is space-loving or tab-loving. Returns a list of the form: (num-beginning-with-tab num-beginning-with-space num-beginning-with-something-else)
Update the of space-loving-ness shown in the mode line
Update the of tab-loving-ness shown in the mode line
Activate indent-hints minor mode for this buffer, if appropriate.
Turns on indent-hints-mode, if appropriate. This function is intended to be used with define-globalized-minor-mode
Returns true if given buffer name is a temp buffer (starts with " *")