Menu

Renumeration in column selection

2010-01-07
2013-04-24
  • Andrzej Kmicic

    Andrzej Kmicic - 2010-01-07

    2010-01-05 13:32:35 CET
    This script renum all selected (warning: ONLY COLUMN SELECTION) numbers in column selection and replace with start num and step num. Order renumeration is the same as selections order.

    <?php
    $view=0;
    $docid=0;
    nppUserCommand("NPPM_ACTIVATEDOC",$view,$docid);
    // activate view=0 and first docid(document)=0
    $start = npp_input_box("Input Start Number","Start number:","10");
    $step = npp_input_box("Input Step Value","Step value:","10");
    // get start and step of renumeration
    $sel_count=scimultipleselection("SCI_GETSELECTIONS");
    // number lines in selections (valid for column selections )
    for($i=0;$i<$sel_count;$i++) { // for all selections
    $sel_start = scimultipleselection ("SCI_GETSELECTIONNSTART",$i); //get start position
    $sel_end = scimultipleselection("SCI_GETSELECTIONNEND",$i); //get stop position
    $text=sciText("SCI_GETTEXTRANGE",$sel_start,$sel_end); // get text from start to stop
    $text=preg_replace("@-?[0-9]+@",$start,$text); // replace number with new number
    scisearchreplace("SCI_SETTARGETSTART",$sel_start); // set replace start position
    scisearchreplace("SCI_SETTARGETEND",$sel_end); // set replace stop position
    scisearchreplace("SCI_REPLACETARGET",$text); // replace to new num
    $start+=$step; // increment new num by step
    }
    ?>
    
     
  • Andrzej Kmicic

    Andrzej Kmicic - 2010-01-07

    Insert new numeration in column selection.

    The script inserts the selected numbers in place. Note: works only in the column mode selection. The document must be the first document in the primary view. Selection may be zero Column. A wider selection will be replaced. The order of numbering is consistent with the direction of selection. Inserted numbers begin with the start number and are increased on a given step.

    <?php
    $view=0;
    $docid=0;
    nppUserCommand("NPPM_ACTIVATEDOC",$view,$docid);
    // activate view=0 and first docid(document)=0
    $start = npp_input_box("Input Start Number","Start number:","10");
    $step = npp_input_box("Input Step Value","Step value:","10");
    // get start and step of renumeration
    $sel_count=scimultipleselection("SCI_GETSELECTIONS");
    // number lines in selections (valid for column selections )
    for($i=0;$i<$sel_count;$i++) { // for all selections
    $sel_start = scimultipleselection("SCI_GETSELECTIONNSTART",$i); //get start position
    $sel_end = scimultipleselection("SCI_GETSELECTIONNEND",$i); //get stop position
    $text=sciText("SCI_GETTEXTRANGE",$sel_start,$sel_end); // get text from start to stop
    //$text=preg_replace("@-?[0-9]+@",$start,$text); // replace number with new number
    scisearchreplace("SCI_SETTARGETSTART",$sel_start); // set replace start position
    scisearchreplace("SCI_SETTARGETEND",$sel_end); // set replace stop position
    scisearchreplace("SCI_REPLACETARGET",$start); // replace to new num
    $start+=$step; // increment new num by step
    }
    ?>
    
     
  • Andrzej Kmicic

    Andrzej Kmicic - 2010-01-07

    Insert new date in column selection.

    The script inserts in the selection dates sequence in place. Note: works only in the column mode selection. The document must be the first document in the primary view. Selection may be zero Column. A wider selection will be replaced. The order of dates is consistent with the direction of selection. Inserted numbers begin with the start date and are increased on a given step of days.

    <?php
    $view=0;
    $docid=0;
    nppUserCommand("NPPM_ACTIVATEDOC",$view,$docid);
    // activate view=0 and first docid(document)=0
    $start = npp_input_box("Input Start Date","Start date:",date("Y-m-d"));
    $step = npp_input_box("Input Day Step Value","Day Step:","1");
    // get start and step of renumeration
    $sel_count=scimultipleselection("SCI_GETSELECTIONS");
    // number lines in selections (valid for column selections )
    for($i=0;$i<$sel_count;$i++) { // for all selections
    $sel_start = scimultipleselection("SCI_GETSELECTIONNSTART",$i); //get start position
    $sel_end = scimultipleselection("SCI_GETSELECTIONNEND",$i); //get stop position
    $text=sciText("SCI_GETTEXTRANGE",$sel_start,$sel_end); // get text from start to stop
    //$text=preg_replace("@-?[0-9]+@",$start,$text); // replace number with new number
    scisearchreplace("SCI_SETTARGETSTART",$sel_start); // set replace start position
    scisearchreplace("SCI_SETTARGETEND",$sel_end); // set replace stop position
    scisearchreplace("SCI_REPLACETARGET",$start); // replace to new num
    $start=date("Y-m-d",strtotime("$start +{$step}day")); // increment new num by step
    }
    ?>
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.