home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Editores / Perl5 / perl / lib / site / auto / Tk / Text / PrevPara.al < prev    next >
Encoding:
Text File  |  1997-08-10  |  949 b   |  37 lines

  1. # NOTE: Derived from ..\blib\lib\Tk\Text.pm.  Changes made here will be lost.
  2. package Tk::Text;
  3.  
  4. # PrevPara --
  5. # Returns the index of the beginning of the paragraph just before a given
  6. # position in the text (the beginning of a paragraph is the first non-blank
  7. # character after a blank line).
  8. #
  9. # Arguments:
  10. # w - The text window in which the cursor is to move.
  11. # pos - Position at which to start search.
  12. sub PrevPara
  13. {
  14.  my $w = shift;
  15.  my $pos = shift;
  16.  $pos = $w->index("$pos linestart");
  17.  while (1)
  18.   {
  19.    if ($w->get("$pos - 1 line") eq "\n" && $w->get($pos) ne "\n" || $pos eq "1.0" )
  20.     {
  21.      my $string = $w->get($pos,"$pos lineend");
  22.      if ($string =~ /^(\s)+/)
  23.       {
  24.        my $off = length($1);
  25.        $pos = $w->index("$pos + $off chars")
  26.       }
  27.      if ($w->compare($pos,"!=","insert") || $pos eq "1.0")
  28.       {
  29.        return $pos;
  30.       }
  31.     }
  32.    $pos = $w->index("$pos - 1 line")
  33.   }
  34. }
  35.  
  36. 1;
  37.