Text::FindIndent

Current version is 0.09.

Download

Distribution from this site.
CPAN site

README

NAME
    Text::FindIndent - Heuristically determine the indent style

SYNOPSIS
      use Text::FindIndent;
      my $indentation_type = Text::FindIndent->parse($text);
      if ($indentation_type =~ /^s(\d+)/) {
        print "Indentation with $1 spaces\n";
      }
      elsif ($indentation_type =~ /^t(\d+)/) {
        print "Indentation with tabs, a tab should indent by $1 characters\n";
      }
      elsif ($indentation_type =~ /^m(\d+)/) {
        print "Indentation with $1 characters in tab/space mixed mode\n";
      }
      else {
        print "Indentation style unknown\n";
      }

DESCRIPTION
    This is an experimental distribution that attempts to intuit the
    underlying indent "policy" for a text file (most likely a source code
    file).

METHODS
  parse
    The class method "parse" tries to determine the indentation style of the
    given piece of text (which must start at a new line and can be passed in
    either as a string or as a reference to a scalar containing the string).

    Returns a letter followed by a number. If the letter is "s", then the
    text is most likely indented with spaces. The number indicates the
    number of spaces used for indentation. A "t" indicates tabs. The number
    after the "t" indicates the number characters each level of indentation
    corresponds to. A "u" indicates that the indenation style could not be
    determined. Finally, an "m" followed by a number means that this many
    characters are used for each indentation level, but the indentation is
    an arbitrary number of tabs followed by 0-7 spaces. This can happen if
    your editor is stupid enough to do smart indentation/whitespace
    compression. (I.e. replaces all indentations many tabs as possible but
    leaves the rest as spaces.)

    The function supports parsing of "vim" *modelines*. Those settings
    override the heuristics. The modeline's options that are recognized are
    "sts"/"softtabstob", "et"/"noet"/"expandtabs"/"noexpandtabs", and
    "ts"/"tabstop".

    Similarly, parsing of "emacs" *Local Variables* is somewhat supported.
    "parse" use explicit settings to override the heuristics but uses style
    settings only as a fallback. The following options are recognized:
    "tab-width", "indent-tabs-mode", "c-basic-offset", and "style".

SUPPORT
    Bugs should be reported via the CPAN bug tracker at

    

    For other issues, contact the author.

AUTHOR
    Adam Kennedy , Steffen Mueller 

COPYRIGHT
    Copyright 2008 Adam Kennedy,

    Copyright 2008 Steffen Mueller.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    The full text of the license can be found in the LICENSE file included
    with this module.

	

Documentation

Text::FindIndent

Change Log

Changes for Perl extension Text-FindIndent

0.09
	- Add vim-commands output.

0.08
	- Handle case where hash keys and values are indented by braces pos + 1
	  (CHORNY)
	- Check if indent level is same on next line and slightly increase probability of
	  current indent type. Should be faster too. (CHORNY)
	- Add option 'first_level_indent_only' to check only indent where previous line
	  is empty. (CHORNY)

0.07
	- ~40% faster since 0.05

0.06 
	- ~20-25% faster

0.05 
	- "skip_pod" option to parse() for skipping POD sections.

0.04 
	- Fix the MANIFEST of the distribution

0.03 
	- Rudimentary support for emacs local variables.

0.02 
	- Rudimentary support for vim modelines.

0.01 
	- Starting initial implementation
    

(c) 2002-2010 Steffen Müller; All rights reserved.

Valid HTML 4.0!