.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Text::FindIndent 3pm" .TH Text::FindIndent 3pm "2023-07-01" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Text::FindIndent \- Heuristically determine the indent style .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 10 \& use Text::FindIndent; \& my $indentation_type = Text::FindIndent\->parse($text, skip_pod => 1); \& if ($indentation_type =~ /^s(\ed+)/) { \& print "Indentation with $1 spaces\en"; \& } \& elsif ($indentation_type =~ /^t(\ed+)/) { \& print "Indentation with tabs, a tab should indent by $1 characters\en"; \& } \& elsif ($indentation_type =~ /^m(\ed+)/) { \& print "Indentation with $1 characters in tab/space mixed mode\en"; \& } \& else { \& print "Indentation style unknown\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a module that attempts to intuit the underlying indent \*(L"policy\*(R" for a text file (most likely a source code file). .SH "METHODS" .IX Header "METHODS" .SS "parse" .IX Subsection "parse" The class method \f(CW\*(C`parse\*(C'\fR 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). .PP Returns a letter followed by a number. If the letter is \f(CW\*(C`s\*(C'\fR, then the text is most likely indented with spaces. The number indicates the number of spaces used for indentation. A \f(CW\*(C`t\*(C'\fR indicates tabs. The number after the \&\f(CW\*(C`t\*(C'\fR indicates the number characters each level of indentation corresponds to. A \f(CW\*(C`u\*(C'\fR indicates that the indenation style could not be determined. Finally, an \f(CW\*(C`m\*(C'\fR 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.) .PP The function supports parsing of \f(CW\*(C`vim\*(C'\fR \fImodelines\fR. Those settings override the heuristics. The modeline's options that are recognized are \f(CW\*(C`sts\*(C'\fR/\f(CW\*(C`softtabstob\*(C'\fR, \f(CW\*(C`et\*(C'\fR/\f(CW\*(C`noet\*(C'\fR/\f(CW\*(C`expandtabs\*(C'\fR/\f(CW\*(C`noexpandtabs\*(C'\fR, and \f(CW\*(C`ts\*(C'\fR/\f(CW\*(C`tabstop\*(C'\fR. .PP Similarly, parsing of \f(CW\*(C`emacs\*(C'\fR \fILocal Variables\fR is somewhat supported. \&\f(CW\*(C`parse\*(C'\fR use explicit settings to override the heuristics but uses style settings only as a fallback. The following options are recognized: \&\f(CW\*(C`tab\-width\*(C'\fR, \f(CW\*(C`indent\-tabs\-mode\*(C'\fR, \f(CW\*(C`c\-basic\-offset\*(C'\fR, and \f(CW\*(C`style\*(C'\fR. .PP There is one named option that you can pass to \f(CW\*(C`parse()\*(C'\fR: \f(CW\*(C`skip_pod\*(C'\fR. When set to true, any section of \s-1POD\s0 (see perlpod) will be ignored for indentation finding. This is because verbatim paragraphs and examples embedded in \s-1POD\s0 or quite often indented differently from normal Perl code around the \s-1POD\s0 section. Defaults to false. Example: .PP .Vb 1 \& my $mode = Text::FindIndent\->parse(\e$text, skip_pod => 1); .Ve .SS "to_vim_commands" .IX Subsection "to_vim_commands" A class method that converts the output of \f(CW\*(C`parse(\e$text)\*(C'\fR into a series of vi(m) commands that will configure vim to use the detected indentation setting. Returns zero (failure) or more lines of text that are suitable for passing to \&\f(CW\*(C`VIM::DoCommand()\*(C'\fR one by one. .PP As a convenience, if the argument to \f(CW\*(C`to_vim_commands\*(C'\fR doesn't look like the output of \f(CW\*(C`parse\*(C'\fR, it is redirected to \f(CW\*(C`parse\*(C'\fR first. .PP To use this, you can put the following line in your \fI.vimrc\fR if your vim has Perl support. Suggestions on how to do this in a more elegant way are welcome. The code should be on one line but is broken up for displaying: .PP .Vb 2 \& map :perl use Text::FindIndent;VIM::DoCommand($_) for \& Text::FindIndent\->to_vim_commands(join "\en", $curbuf\->Get(1..$curbuf\->Count())); .Ve .PP (Patches to implement the equivalent for emacs would be welcome as well.) .SH "SUPPORT" .IX Header "SUPPORT" Bugs should be reported via the \s-1CPAN\s0 bug tracker at .PP .PP For other issues, contact the author. .SH "AUTHOR" .IX Header "AUTHOR" Steffen Mueller .PP Adam Kennedy .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2008 \- 2010 Steffen Mueller. .PP Copyright 2008 \- 2010 Adam Kennedy, .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \&\s-1LICENSE\s0 file included with this module.