Coder Social home page Coder Social logo

indent-hints-mode's Introduction

Emacs Logo

indent-hints.el

Get some hints about whether your buffer is space- or tab-loving


License GPLv3

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.

Installation

  • 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-mode group 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-tab-loving-hook and indent-hints-mode-space-loving-hook which 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"))
    

Use

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).

Customization Documentation

indent-hints-profile-switching-enabled

Non-nil means switch between spacing profiles depending on the tab- or space-lovingness of buffers

indent-hints-tab-width

When non-nil, the tab-width to use when the tab-loving profile is enabled.

indent-hints-c-basic-offset

When non-nil, the c-basic-offset to use when the space-loving profile is enabled.

indent-hints-c-default-space-loving-style

When non-nil, the c-default-style to use when the space-loving profile is enabled.

indent-hints-c-default-tab-loving-style

When non-nil, the c-default-style to use when the tab-loving profile is enabled.

indent-hints-space-loving-modeline-indicator

Modeline indicator to use when the file is space-loving

indent-hints-tab-loving-modeline-indicator

Modeline indicator to use when the file is tab-loving

indent-hints-neither-loving-modeline-indicator

Modeline indicator to use when the file is neither-loving

Function and Macro Documentation

(ih/activate-space-loving-profile)

Activate the space-loving profile

(ih/activate-tab-loving-profile)

Activate the tab-loving profile

(ih/count-line-beginnings)

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)

(ih/update-space-loving-ratio RATIO)

Update the of space-loving-ness shown in the mode line

(ih/update-tab-loving-ratio RATIO)

Update the of tab-loving-ness shown in the mode line

(indent-hints-activate)

Activate indent-hints minor mode for this buffer, if appropriate.

(indent-hints-mode-on)

Turns on indent-hints-mode, if appropriate. This function is intended to be used with define-globalized-minor-mode

(ih/is-temp-buffer THE-BUFFER-NAME)

Returns true if given buffer name is a temp buffer (starts with " *")


Markdown README file generated by make-readme-markdown.el

indent-hints-mode's People

Contributors

mgalgs avatar

Stargazers

Jesús Martínez avatar rho avatar  avatar phenix3443 avatar stardiviner avatar Ximing avatar Carlo Bertini avatar  avatar Josh Tolle avatar Christopher Wellons avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

emacsmirror

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.