/usr/share/perl5/Text/FindIndent.pm is in libtext-findindent-perl 0.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | package Text::FindIndent;
# -*- mode: Perl -*-
# Emacs mode is necessary for https://github.com/github/linguist/issues/2458
use 5.00503;
use strict;
use vars qw{$VERSION};
BEGIN {
$VERSION = '0.11';
}
use constant MAX_LINES => 500;
sub parse {
my $class = shift;
my $text = shift;
my %opts = @_;
my $textref = ref($text) ? $text : \$text; # accept references, too
my $skip_pod = $opts{skip_pod};
my $first_level_indent_only = $opts{first_level_indent_only}?1:0;
my %modeline_settings;
my %indentdiffs;
my $lines = 0;
my $prev_indent = undef;
my $skip = 0;
my $in_pod = 0;
# Do we have emacs smart comments?
$class->_check_emacs_local_variables_at_file_end($textref, \%modeline_settings);
if (exists $modeline_settings{softtabstop} and exists $modeline_settings{usetabs}) {
$modeline_settings{mixedmode} = $modeline_settings{usetabs}
if not defined $modeline_settings{mixedmode};
return(
($modeline_settings{mixedmode} ? "m" : "s")
. $modeline_settings{softtabstop}
);
}
elsif (exists $modeline_settings{tabstop} and $modeline_settings{usetabs}) {
return( ($modeline_settings{mixedmode} ? "m" : "t") . $modeline_settings{tabstop} );
}
elsif (exists $modeline_settings{tabstop} and exists $modeline_settings{usetabs}) {
return( "s" . $modeline_settings{tabstop} );
}
my $next_line_braces_pos_plus_1;
my $prev_indent_type = undef;
while ($$textref =~ /\G([ \t]*)([^\r\n]*)[\r\n]+/cgs) {
my $ws = $1;
my $rest = $2;
my $fullline = "$ws$rest";
$lines++;
# check emacs start line stuff with some slack (shebang)
my $changed_modelines;
if ($lines < 3) {
$changed_modelines = $class->_check_emacs_local_variables_first_line($fullline, \%modeline_settings);
}
# Do we have emacs smart comments?
# ==> Done once at start
#$class->_check_emacs_local_variables($fullline, \%modeline_settings);
# Do we have vim smart comments?
if ($class->_check_vim_modeline($fullline, \%modeline_settings) || $changed_modelines) {
if (exists $modeline_settings{softtabstop} and exists $modeline_settings{usetabs}) {
$modeline_settings{mixedmode} = $modeline_settings{usetabs}
if not defined $modeline_settings{mixedmode};
return(
($modeline_settings{mixedmode} ? "m" : "s")
. $modeline_settings{softtabstop}
);
}
elsif (exists $modeline_settings{tabstop} and $modeline_settings{usetabs}) {
return( ($modeline_settings{mixedmode} ? "m" : "t") . $modeline_settings{tabstop} );
}
elsif (exists $modeline_settings{tabstop} and exists $modeline_settings{usetabs}) {
return( "s" . $modeline_settings{tabstop} );
}
}
if ($lines > MAX_LINES) {
next;
}
if ($skip) {
$skip--;
next;
}
if ($skip_pod and $ws eq '' and substr($rest, 0, 1) eq '=') {
if (not $in_pod and $rest =~ /^=(?:head\d|over|item|back|pod|begin|for|end)/ ) {
$in_pod = 1;
}
elsif ($in_pod and $rest =~ /^=cut/) {
$in_pod = 0;
}
}
next if $in_pod or $rest eq '';
if ($ws eq '') {
$prev_indent = $ws;
next;
}
# skip next line if the last char is a backslash.
# Doesn't matter for Perl, but let's be generous!
$skip = 1 if $rest =~ /\\$/;
# skip single-line comments
next if $rest =~ /^(?:#|\/\/|\/\*)/; # TODO: parse /* ... */!
if ($next_line_braces_pos_plus_1) {
if ($next_line_braces_pos_plus_1==_length_with_tabs_converted($ws)) {
next;
}
$next_line_braces_pos_plus_1=0;
} else {
if ($rest =~ /=> \{$/) { #handle case where hash keys and values are indented by braces pos + 1
$next_line_braces_pos_plus_1=_length_with_tabs_converted($ws)+length($rest);
}
}
if ($first_level_indent_only and $prev_indent ne '') {
next;
}
if ($prev_indent eq $ws) {
if ($prev_indent_type) {
$indentdiffs{$prev_indent_type}+=0.01;
#coefficient is not based on data, so change if you think it should be different
}
next;
}
# prefix-matching higher indentation level
if ($ws =~ /^\Q$prev_indent\E(.+)$/) {
my $diff = $1;
my $indent_type=_analyse_indent_diff($diff);
$indentdiffs{$indent_type}++;
$prev_indent_type=$indent_type;
$prev_indent = $ws;
next;
}
# prefix-matching lower indentation level
if ($prev_indent =~ /^\Q$ws\E(.+)$/) {
my $diff = $1;
#_grok_indent_diff($diff, \%indentdiffs);
my $indent_type=_analyse_indent_diff($diff);
$indentdiffs{$indent_type}++;
$prev_indent_type=$indent_type;
$prev_indent = $ws;
next;
}
# at this point, we're desperate!
my $prev_spaces = $prev_indent;
$prev_spaces =~ s/[ ]{0,7}\t/ /g;
my $spaces = $ws;
$spaces =~ s/[ ]{0,7}\t/ /g;
my $len_diff = length($spaces) - length($prev_spaces);
if ($len_diff) {
$len_diff = abs($len_diff);
$indentdiffs{"m$len_diff"}++;
}
$prev_indent = $ws;
} # end while lines
# nothing found
return 'u' if not keys %indentdiffs;
my $max = 0;
my $maxkey = undef;
while (my ($key, $value) = each %indentdiffs) {
$maxkey = $key, $max = $value if $value > $max;
}
if ($maxkey =~ /^s(\d+)$/) {
my $mixedkey = "m" . $1;
my $mixed = $indentdiffs{$mixedkey};
if (defined($mixed) and $mixed >= $max * 0.2) {
$maxkey = $mixedkey;
}
}
# fallback to emacs styles which are guesses only
foreach my $key (qw(softtabstop tabstop usetabs)) {
if (not exists $modeline_settings{$key}
and exists $modeline_settings{"style_$key"}) {
$modeline_settings{$key} = $modeline_settings{"style_$key"};
}
}
if (exists $modeline_settings{softtabstop}) {
$maxkey =~ s/\d+/$modeline_settings{softtabstop}/;
}
elsif (exists $modeline_settings{tabstop}) {
$maxkey =~ s/\d+/$modeline_settings{tabstop}/;
}
if (exists $modeline_settings{usetabs}) {
if ($modeline_settings{usetabs}) {
$maxkey =~ s/^(.)(\d+)$/$1 eq 'u' ? "t8" : ($2 == 8 ? "t8" : "m$2")/e;
}
else {
$maxkey =~ s/^./m/;
}
}
# mixedmode explicitly asked for
if ($modeline_settings{mixedmode}) {
$maxkey =~ s/^./m/;
}
return $maxkey;
}
sub _length_with_tabs_converted {
my $str=shift;
my $tablen=shift || 8;
$str =~ s/( +)$//;
my $trailing_spaces = $1||'';
$str =~ s/ +//g; # assume the spaces are all contained in tabs!
return length($str)*$tablen+length($trailing_spaces);
}
sub _grok_indent_diff {
my $diff = shift;
my $indentdiffs = shift;
if ($diff =~ /^ +$/) {
$indentdiffs->{"s" . length($diff)}++;
}
elsif ($diff =~ /^\t+$/) {
$indentdiffs->{"t8"}++; # we can't infer what a tab means. Or rather, we need smarter code to do it
}
else { # mixed!
$indentdiffs->{"m" . _length_with_tabs_converted($diff)}++;
}
}
sub _analyse_indent_diff {
my $diff = shift;
if ($diff =~ /^ +$/) {
return "s" . length($diff);
}
elsif ($diff =~ /^\t+$/) {
return "t8"; # we can't infer what a tab means. Or rather, we need smarter code to do it
}
else { # mixed!
return "m" . _length_with_tabs_converted($diff);
}
}
{
# the vim modeline regexes
my $VimTag = qr/(?:ex|vim?(?:[<=>]\d+)?):/;
my $OptionArg = qr/[^\s\\]*(?:\\[\s\\][^\s\\]*)*/;
my $VimOption = qr/
\w+(?:=)?$OptionArg
/xo;
my $VimModeLineStart = qr/(?:^|\s+)$VimTag/o;
# while technically, we match against $VimModeLineStart before,
# IF there is a vim modeline, we don't need to optimize
my $VimModelineTypeOne = qr/
$VimModeLineStart
\s*
($VimOption
(?:
(?:\s*:\s*|\s+)
$VimOption
)*
)
\s*$
/xo;
my $VimModelineTypeTwo = qr/
$VimModeLineStart
\s*
set?\s+
($VimOption
(?:\s+$VimOption)*
)
\s*
:
/xo;
sub _check_vim_modeline {
my $class = shift;
my $line = shift;
my $settings = shift;
# Quoting the vim docs:
# There are two forms of modelines. The first form:
# [text]{white}{vi:|vim:|ex:}[white]{options}
#
#[text] any text or empty
#{white} at least one blank character (<Space> or <Tab>)
#{vi:|vim:|ex:} the string "vi:", "vim:" or "ex:"
#[white] optional white space
#{options} a list of option settings, separated with white space or ':',
# where each part between ':' is the argument for a ":set"
# command (can be empty)
#
#Example:
# vi:noai:sw=3 ts=6 ~
# The second form (this is compatible with some versions of Vi):
#
# [text]{white}{vi:|vim:|ex:}[white]se[t] {options}:[text]
#
#[text] any text or empty
#{white} at least one blank character (<Space> or <Tab>)
#{vi:|vim:|ex:} the string "vi:", "vim:" or "ex:"
#[white] optional white space
#se[t] the string "set " or "se " (note the space)
#{options} a list of options, separated with white space, which is the
# argument for a ":set" command
#: a colon
#[text] any text or empty
#
#Example:
# /* vim: set ai tw=75: */ ~
#
my @options;
return if $line !~ $VimModeLineStart;
if ($line =~ $VimModelineTypeOne) {
push @options, split /(?!<\\)[:\s]+/, $1;
}
elsif ($line =~ $VimModelineTypeTwo) {
push @options, split /(?!<\\)\s+/, $1;
}
else {
return;
}
return if not @options;
my $changed = 0;
foreach (@options) {
/s(?:ts|ofttabstop)=(\d+)/i and $settings->{softtabstop} = $1, $changed = 1, next;
/t(?:s|abstop)=(\d+)/i and $settings->{tabstop} = $1, $changed = 1, next;
/((?:no)?)(?:expandtab|et)/i and $settings->{usetabs} = (defined $1 and $1 =~ /no/i ? 1 : 0), $changed = 1, next;
}
return $changed;
}
}
{
# lookup for emacs tab modes
my %tabmodelookup = (
t => sub {
$_[0]->{mixedmode} = 1;
$_[0]->{usetabs} = 1;
},
nil => sub {
delete $_[0]->{mixedmode};
$_[0]->{usetabs} = 0;
},
);
# lookup for emacs styles
my %stylelookup = (
kr => sub {
$_[0]->{style_softtabstop} = 4;
$_[0]->{style_tabstop} = 8;
$_[0]->{style_usetabs} = 1;
},
linux => sub {
$_[0]->{style_softtabstop} = 8;
$_[0]->{style_tabstop} = 8;
$_[0]->{style_usetabs} = 1;
},
'gnu' => sub {
$_[0]->{style_softtabstop} = 2;
$_[0]->{style_tabstop} = 8;
$_[0]->{style_usetabs} = 1;
},
'bsd' => sub {
$_[0]->{style_softtabstop} = 4;
$_[0]->{style_tabstop} = 8;
$_[0]->{style_usetabs} = 1;
},
'ellemtel' => sub {
$_[0]->{style_softtabstop} = 3;
$_[0]->{style_tabstop} = 3;
$_[0]->{style_usetabs} = 0;
},
'java' => sub {
$_[0]->{style_softtabstop} = 4;
$_[0]->{style_tabstop} = 8;
},
);
$stylelookup{'k&r'} = $stylelookup{kr};
$stylelookup{'bsd'} = $stylelookup{kr};
$stylelookup{'whitesmith'} = $stylelookup{kr};
$stylelookup{'stroustrup'} = $stylelookup{kr};
my $FirstLineVar = qr/[^\s:]+/;
my $FirstLineValue = qr/[^;]+/; # dumb
my $FirstLinePair = qr/\s*$FirstLineVar\s*:\s*$FirstLineValue;/o;
my $FirstLineRegexp = qr/-\*-\s*mode:\s*[^\s;]+;\s*($FirstLinePair+)\s*-\*-/o;
sub _check_emacs_local_variables_first_line {
my $class = shift;
my $line = shift;
my $settings = shift;
# on first line (second if there is a shebang):
# -*- mode: $MODENAME; $VARNAME: $VALUE; ... -*-
# ($FOO is not a literal)
# Example with a Lisp comment:
# ;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-
my $changed = 0;
if ($line =~ $FirstLineRegexp) {
my @pairs = split /\s*;\s*/, $1;
foreach my $pair (@pairs) {
my ($key, $value) = split /\s*:\s*/, $pair, 2;
if ($key eq 'tab-width') {
$settings->{tabstop} = $value;# FIXME: check var
$changed = 1;
}
elsif ($key eq 'indent-tabs-mode') {
$tabmodelookup{$value}->($settings), $changed = 1 if defined $tabmodelookup{$value};
}
elsif ($key eq 'c-basic-offset') {
$settings->{tabstop} ||= $value; # tab-width takes precedence!?
$changed = 1;
}
elsif ($key eq 'style') { # this is quite questionable practice...
$stylelookup{$value}->($settings), $changed = 1 if defined $stylelookup{$value};
}
}
}
# do this only as a LAST resort!
#$settings->{tabstop} = $settings->{style_tabstop} if not exists $settings->{tabstop};
#$settings->{softtabstop} = $settings->{style_softtabstop} if not exists $settings->{softtabstop};
#$settings->{usetabs} = $settings->{style_usetabs} if not exists $settings->{usetabs};
return $changed;
}
sub _check_emacs_local_variables {
my $class = shift;
my $line = shift;
my $settings = shift;
# A local variables list goes near the end of the file, in the last page.[...]
# The local variables list starts with a line containing the string `Local Variables:',
# and ends with a line containing the string `End:'. In between come the variable names
# and values, one set per line, as `variable: value'. The values are not evaluated;
# they are used literally. If a file has both a local variables list and a `-*-'
# line, Emacs processes everything in the `-*-' line first, and everything in the
# local variables list afterward.
#
# Here is an example of a local variables list:
#
# ;; Local Variables: **
# ;; mode:lisp **
# ;; comment-column:0 **
# ;; comment-start: ";; " **
# ;; comment-end:"**" **
# ;; End: **
#
# Each line starts with the prefix `;; ' and each line ends with the suffix ` **'.
# Emacs recognizes these as the prefix and suffix based on the first line of the
# list, by finding them surrounding the magic string `Local Variables:'; then it
# automatically discards them from the other lines of the list.
#
# The usual reason for using a prefix and/or suffix is to embed the local variables
# list in a comment, so it won't confuse other programs that the file is intended as
# input for. The example above is for a language where comment lines start with `;; '
# and end with `**'; the local values for comment-start and comment-end customize the
# rest of Emacs for this unusual syntax. Don't use a prefix (or a suffix) if you don't need one.
#
#
# Can it be any more annoying to parse? --Steffen
if ($settings->{in_local_variables_section}) {
my $prefix = $settings->{local_variable_prefix};
$prefix = '' if not defined $prefix;
$prefix = quotemeta($prefix);
my $suffix = $settings->{local_variable_suffix};
$suffix = '' if not defined $suffix;
$suffix = quotemeta($suffix);
if ($line =~ /^\s*$prefix\s*([^\s:]+):\s*(.+)$suffix\s*$/) {
my $key = $1;
my $value = $2;
$value =~ s/\s+$//;
if ($key eq 'tab-width') {
$settings->{tabstop} = $value;
}
elsif ($key eq 'indent-tabs-mode') {
$tabmodelookup{$value}->($settings) if defined $tabmodelookup{$value};
}
elsif ($key eq 'c-basic-offset') {
$settings->{tabstop} ||= $value; # tab-width takes precedence!?
}
elsif ($key eq 'style') { # this is quite questionable practice...
$stylelookup{$value}->($settings) if defined $stylelookup{$value};
}
} # end if variable line
else {
delete $settings->{in_local_variables_section};
delete $settings->{local_variable_prefix};
delete $settings->{local_variable_suffix};
}
}
elsif ($line =~ /^\s*(\S*)\s*Local Variables:\s*(\S*)\s*$/) {
$settings->{local_variable_prefix} = $1;
$settings->{local_variable_suffix} = $2;
$settings->{in_local_variables_section} = 1;
}
}
sub _check_emacs_local_variables_at_file_end {
my $class = shift;
my $textref = shift;
my $settings = shift;
my $len = length($$textref);
my $start = $len-3000;
$start = 0 if $start < 0;
my $text = substr($$textref, $start);
while ($text =~ /\G[ \t]*([^\r\n]*)[\r\n]+/cgs) {
$class->_check_emacs_local_variables($1, $settings);
}
return;
}
} # end lexical block for emacs lookups
sub to_vim_commands {
my $indent = shift;
$indent = shift if $indent eq __PACKAGE__;
$indent = __PACKAGE__->parse($indent) if ref($indent) or length($indent) > 5;
my @cmd;
if ( $indent =~ /^t(\d+)/ ) {
my $chars = $1;
push @cmd, ":set shiftwidth=$chars";
push @cmd, ":set tabstop=$chars";
push @cmd, ":set softtabstop=0";
push @cmd, ":set noexpandtab";
} elsif ( $indent =~ /^s(\d+)/ ) {
my $spaces = $1;
push @cmd, ":set shiftwidth=$spaces";
push @cmd, ":set tabstop=8";
push @cmd, ":set softtabstop=$spaces";
push @cmd, ':set expandtab';
} elsif ( $indent =~ /^m(\d+)/ ) {
my $spaces = $1;
push @cmd, ":set shiftwidth=$spaces";
push @cmd, ":set tabstop=8";
push @cmd, ":set softtabstop=$spaces";
push @cmd, ':set noexpandtab';
}
return @cmd;
}
1;
__END__
=pod
=head1 NAME
Text::FindIndent - Heuristically determine the indent style
=head1 SYNOPSIS
use Text::FindIndent;
my $indentation_type = Text::FindIndent->parse($text, skip_pod => 1);
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";
}
=head1 DESCRIPTION
This is a module that attempts to intuit the underlying
indent "policy" for a text file (most likely a source code file).
=head1 METHODS
=head2 parse
The class method C<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 C<s>, then the
text is most likely indented with spaces. The number indicates the number
of spaces used for indentation. A C<t> indicates tabs. The number after the
C<t> indicates the number characters each level of indentation corresponds to.
A C<u> indicates that the
indenation style could not be determined.
Finally, an C<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 C<vim> I<modelines>. Those settings
override the heuristics. The modeline's options that are recognized
are C<sts>/C<softtabstob>, C<et>/C<noet>/C<expandtabs>/C<noexpandtabs>,
and C<ts>/C<tabstop>.
Similarly, parsing of C<emacs> I<Local Variables> is somewhat supported.
C<parse> use explicit settings to override the heuristics but uses style settings
only as a fallback. The following options are recognized:
C<tab-width>, C<indent-tabs-mode>, C<c-basic-offset>, and C<style>.
There is one named option that you can pass to C<parse()>: C<skip_pod>.
When set to true, any section of POD (see L<perlpod>) will be ignored for
indentation finding. This is because verbatim paragraphs and examples
embedded in POD or quite often indented differently from normal Perl code
around the POD section. Defaults to false. Example:
my $mode = Text::FindIndent->parse(\$text, skip_pod => 1);
=head2 to_vim_commands
A class method that converts the output of C<parse(\$text)>
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
C<VIM::DoCommand()> one by one.
As a convenience, if the argument to C<to_vim_commands> doesn't look
like the output of C<parse>, it is redirected to C<parse> first.
To use this, you can put the following line in your F<.vimrc> 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:
map <F5> <Esc> :perl use Text::FindIndent;VIM::DoCommand($_) for
Text::FindIndent->to_vim_commands(join "\n", $curbuf->Get(1..$curbuf->Count()));<CR>
(Patches to implement the equivalent for emacs would be welcome as well.)
=head1 SUPPORT
Bugs should be reported via the CPAN bug tracker at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-FindIndent>
For other issues, contact the author.
=head1 AUTHOR
Steffen Mueller E<lt>smueller@cpan.orgE<gt>
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright 2008 - 2010 Steffen Mueller.
Copyright 2008 - 2010 Adam Kennedy,
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.
=cut
|