Loading ...
Sorry, an error occurred while loading the content.

331Re: Smart/intelligent text formatting

Expand Messages
  • rpdooling
    Sep 28, 2005
    • 0 Attachment
      Alan,

      Only thing I see in yours is that I seemed to get errors if I didn't
      put all of the options in one line, including the ignore one.

      -----begin autoformat perl script-----
      #!perl -w

      use strict;
      use Text::Autoformat;
      my $rawtext;

      # while (<DATA>) {
      while (<>) {

      $rawtext = "$rawtext$_";

      }

      # If you ever want to change the margins, etc.
      # my $formatted = autoformat($rawtext, {left=>20, right=>60, all=>1});
      # If you don't have the "all=>1" then it does only one
      # line at a time.

      my $formatted = autoformat($rawtext, {all=>1, ignore=>qr/(\^)/});

      # my $formatted = autoformat $rawtext;

      print "$formatted\n";

      # print "\n$rawtext\n";
      # the following will join all of the lines.
      # should be able to put the RegExp from the add blank
      # lines clip in here.
      #$formatted =~ s/\n+/ /g;
      #print "$formatted\n";

      #to autoformat notetab clip code, open the autoformat.pm
      #module, find the "quotechar" line and add a ";" to the
      #characters recognized as starting a comment or quote line.

      #for help with autoformat type "perldoc Text::Autoformat at the
      #command prompt d:\perl>perldoc Text::AutoFormat



      --- In ntb-scripts@yahoogroups.com, "acummingsus" <acummingsus@g...>
      wrote:
      > Hi Rick,
      >
      > That's great to know! Thanks. I'd be interested your entire script
      > unless there's nothing more that's new in it outside of what you've
      > already shared here.
      >
      > I cannot get the ignore option to work in Linux. I've tried over 7
      > different ways, all to no avail.
      >
      > In Linux, I read from a file (I had tried unsuccessfully so far to map
      > relevant command to a key in the Vim editor). Also I don't yet savvy
      > enough on the Kate editor to create a "tool" (macro making use of
      > external program).
      >
      > my junkr.txt file has 5 or 6 paragraphs. 2 paragraphs have word
      verbatim
      >
      > Each of those 2 para has a really long line.
      >
      > It always formats all para to 72 character line length. I thought it
      > supposed to ignore, not format those 2 para. But it does.
      >
      > (PS I haven't tried the ignore option on Windows yet). I'll boot Win
      > on another day, not today.
      >
      > Do you see anything, problem? Here it is for Linux:
      >
      > #!/usr/bin/perl -w
      >
      > use strict;
      > use Text::Autoformat;
      > my $orig = '/home/al/junkr.txt';
      > my $rawtext;
      > # AC 080205
      > {
      > local( $/ ) ; # change input record separator to file slurp
      > open(OLD, "<", $orig) or die "cant open $orig: $!";
      > $rawtext = <OLD> # slurp entirety of file into $rawtext
      > }
      > # my $formatted = autoformat $rawtext;
      > # my $formatted = autoformat($rawtext, {left=>20, right=>60, all=>1});
      > # my $formatted = autoformat($rawtext, {ignore => qr/original/i,
      all=>1});
      >
      > my $formatted = autoformat $rawtext, { all=>1, ignore=>qr/verbatim/ };
      >
      > # $formatted =~ s/\n+/ /g; # join lines if desire to
      >
      > print "$formatted\n";
      > # print autoformat { all => 1, ignore => qr/verbatim/i }, $rawtext;
      > print "# ============ re formatted is above and raw orig is below
      > ==========";
      > print "\n$rawtext\n";
      > # end
      >
      > Alan.
      >
      > --- In ntb-scripts@yahoogroups.com, "rpdooling" <rpdooling@y...> wrote:
      > > Alan,
      > >
      > > Damian Conway, the guy who wrote the autoformat module wrote me back.
      > > Just open the autoformat.pm module and change the line
      > >
      > > my $quotechar = qq{[!#%=|:]};
      > >
      > > to:
      > >
      > > my $quotechar = qq{[!#%=|:;]};
      > >
      > > by adding the ";" and poof, it's a great
      > > clipcode autoformatter.
      > >
      > > Be sure to add in the script itself a line that tells the module to
      > > ignore clip code lines starting with "^"
      > >
      > > My line looks like:
      > >
      > > my $formatted = autoformat($rawtext, {all=>1, ignore=>qr/(\^)/});
      > >
      > > If anybody wants to whole script I'll post it later.
      > >
      > > I hope I didn't double post. Yahoo locked up in the middle of the
      last.
      > >
      > > Rick
      > >
      > > --- In ntb-scripts@yahoogroups.com, "acummingsus" <acummingsus@g...>
      > > wrote:
      > [ snip ]
    • Show all 19 messages in this topic