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

Re: [Clip] REGEX to Sort "Blocks" Ascending

Expand Messages
  • Art Kocsis
    Corl Here is a clip that only operates on selected text. Don s
    Message 1 of 30 , Nov 20, 2008
    • 0 Attachment
      <Sorry if this is a duplication. I sent it two days ago but it never
      showed up on the list.>

      Corl

      Here is a clip that only operates on selected text. Don's might work if
      you replaced his "W" with an "H" in his "Replace statements but see
      below about error checking. However, using the "Join Lines" generalizes
      this clip to work with any number of lines in any "block", makes it
      independent of "WordWrap" status and insensitive to the number
      of blank lines between "blocks". It also might be slightly quicker.
      Since ^!Replace ignores the "H" option entirely, and the Menu and
      toolbar commands are very inconsistent in their operation when no
      text is selected, an error check is required to avoid destroying your
      file should you execute the clip with no selection. If you want to
      process the entire file you need to select all (CNTL A) first.

      This clip does not use RegEx but unless you are processing huge
      files you won't see a real time difference and staying with NoteTab
      clip commands makes it far less obtuse and not subject to the ever
      changing RegEx syntax.

      BTW, I would suggest using the word "group" instead of "block".
      "Block" is used very specifically in NoteTab to refer to a rectangular
      selection and "paragraph" is text terminated by a carriage return.

      ################# Clip Text Start #######################
      ;Clip to sort (ascending), selected groups of lines of text,
      ; each group consisting of one or more lines with each line
      ; terminated by an EOL, and each group of lines separated by
      ; one or more blank (empty) lines. [Art Kocsis, 11-18-08]

      ^!SetDebug Off
      ^!Set %sRow%=^$Calc(^$GetRowEnd$ - ^$GetRowStart$)$
      ^!If ^%sRow% > 0 Skip_2
      ^!Continue Error Condition: Trivial or no selection. Ending child clip...
      ^!Goto END

      ^!Replace "^P" >> "|^P" AHS
      ^!Replace "^P|" >> "^P" AHS
      ^!Toolbar Join Lines
      ^!Menu Modify/Lines/Sort/Ascending
      ^!Replace "|" >> "^P" AHS
      ^!Toolbar Left Align
      ################# Clip Text End #######################

      It would have been nice to be able to use the Toolbar "Replace"
      command instead of the clip "Replace" command since it defaults
      to the entire file when no selection is made. However, the help file
      is of no use and all I get is "syntax error" for all the variations of
      syntax of which I could think.

      ^!Toolbar "Replace Text" "^P" >> "|^P" AS
      ^!Toolbar "Replace Text" "^P|" "^P" AS
      ^!Toolbar Join Lines
      ^!Menu Modify/Lines/Sort/Ascending
      ^!Toolbar Replace Text "|" >> "^P" AS
      ^!Toolbar Left Align

      Anybody have any knowledge or ideas for correct syntax?

      Namaste', Art

      At 11/18/2008 03:58 PM, you wrote:
      >Hi Don,
      >
      >I tried this and it turned off word wrap and took off the last letter
      >of the third line, but it never sorted the blocks.
      >
      >I never thought to mention that I'm working in is an .olt outline
      >file, but this clip ripped through the entire file doing it's thing
      >to everything. I'm looking for it to do it's thing only to what I've
      >selected.
      >
      >Thanks,
      >Corl
      >
      >--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, "Don
      >- HtmlFixIt.com" <don@...>
      >wrote:
      > >
      > > I'll let someone else perfect the regex, but I believe these six
      >lines
      > > do it:
      > > ^!SetWordWrap Off
      > > ^!Replace "(.*)\r\n(.*)\r\n(htt.*)[^\r\n]" >> "$1|$2|$3|" RAWS
      > > ^!Replace "^P^P" >> "^P" ACIWS
      > > ^!MENU Modify/Lines/Sort/Ascending
      > > ^!Replace "|^P" >> "^P^P" ACIWS
      > > ^!Replace "|" >> "^P" ACIWS
    • corl_deluna
      Hi Art, Very nice. Thanks for reposting. I like this clip because: 1) It works independent of the number of lines in the groups (thanks for the pointer). 2)
      Message 2 of 30 , Nov 20, 2008
      • 0 Attachment
        Hi Art,

        Very nice. Thanks for reposting.

        I like this clip because:

        1) It works independent of the number of lines in the "groups"
        (thanks for the pointer).

        2) I can modify it with relative ease. I added one command line to
        get the double spacing between groups:

        ################# Clip Text Start #######################
        ;Clip to sort (ascending), selected groups of lines of text,
        ;each group consisting of one or more lines with each line
        ;terminated by an EOL, and each group of lines separated by
        ;one or more blank (empty) lines. [Art Kocsis, 11-18-08]

        ^!SetDebug Off
        ^!Set %sRow%=^$Calc(^$GetRowEnd$ - ^$GetRowStart$)$
        ^!If ^%sRow% > 0 Skip_2
        ^!Continue Error Condition: Trivial or no selection. Ending child
        clip...
        ^!Goto END

        ^!Replace "^P" >> "|^P" AHS
        ^!Replace "^P|" >> "^P" AHS
        ^!Toolbar Join Lines
        ^!Menu Modify/Lines/Sort/Ascending
        ^!Replace "|" >> "^P" AHS
        ^!Replace "^P^P" >> "^P^P^P" AHS
        ^!Toolbar Left Align
        ################# Clip Text End #######################

        What is the AHS about? I couldn't find it in the clip script help.

        With gratitude, Namaste,
        Corl


        > <Sorry if this is a duplication. I sent it two days ago but it never
        > showed up on the list.>

        > Here is a clip that only operates on selected text. Don's might
        work if
        > you replaced his "W" with an "H" in his "Replace statements but see
        > below about error checking. However, using the "Join Lines"
        generalizes
        > this clip to work with any number of lines in any "block", makes it
        > independent of "WordWrap" status and insensitive to the number
        > of blank lines between "blocks". It also might be slightly quicker.
        > Since ^!Replace ignores the "H" option entirely, and the Menu and
        > toolbar commands are very inconsistent in their operation when no
        > text is selected, an error check is required to avoid destroying
        your
        > file should you execute the clip with no selection. If you want to
        > process the entire file you need to select all (CNTL A) first.
      • Don - HtmlFixIt.com
        A is all marked occurences H is highlighted only S is silent All listed in help under Find/Replace Text section in Help with Clip Programming. I use that
        Message 3 of 30 , Nov 21, 2008
        • 0 Attachment
          A is all marked occurences
          H is highlighted only
          S is silent

          All listed in help under Find/Replace Text section in Help with Clip
          Programming. I use that section often.

          I use pipes often but I had links with pipes the other day, so you may
          want to go to Julie's character.


          > ^!Replace "|" >> "^P" AHS
          > ^!Replace "^P^P" >> "^P^P^P" AH
          >
          > What is the AHS about? I couldn't find it in the clip script help.
          >
        • Alec Burgess
          corl_deluna (corl@earthlink.net) wrote (in part) (on 2008-11-21 at ... Where did you look? :-) On Find / Replace Text in Clip Script help ... A is an option
          Message 4 of 30 , Nov 21, 2008
          • 0 Attachment
            corl_deluna (corl@...) wrote (in part) (on 2008-11-21 at
            02:36):
            > What is the AHS about? I couldn't find it in the clip script help.
            Where did you look? :-)
            On Find / Replace Text in Clip Script help ...
            A is an option for Replace only (replace all occurrences not just first)
            H, S are options available for both Find and Replace,
            H=replace in selected range (if any) otherwise entire file
            S=silent - don't throw a popup warning if no replacements made.

            --
            Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)




            [Non-text portions of this message have been removed]
          • corl_deluna
            Thanks Don & Alec. I searched for it as a term. Hadn t thought to look under the Replace text entry. As plain as the nose on my face when I know what I m
            Message 5 of 30 , Nov 21, 2008
            • 0 Attachment
              Thanks Don & Alec.

              I searched for it as a term. Hadn't thought to look under the Replace
              text entry. As plain as the nose on my face when I know what I'm
              looking for, but hard to see when I'm looking elsewhere.

              Thanks,
              Corl

              --- In ntb-clips@yahoogroups.com, Alec Burgess <buralex@...> wrote:
              >
              > corl_deluna (corl@...) wrote (in part) (on 2008-11-21 at
              > 02:36):
              > > What is the AHS about? I couldn't find it in the clip script
              help.
              > Where did you look? :-)
              > On Find / Replace Text in Clip Script help ...
              > A is an option for Replace only (replace all occurrences not just
              first)
              > H, S are options available for both Find and Replace,
              > H=replace in selected range (if any) otherwise entire file
              > S=silent - don't throw a popup warning if no replacements made.
            • Art Kocsis
              Hi Corl, You re welcome. You might want to incorporate the improvements suggested by Flo, namely: using an even less common character than | and using the
              Message 6 of 30 , Nov 21, 2008
              • 0 Attachment
                Hi Corl,

                You're welcome.

                You might want to incorporate the improvements suggested by Flo,
                namely: using an even less common character than "|" and using the
                ^$GetSelSize$ command (too many commands to remember them all!).

                One could make this clip even more robust by testing the selection for
                the existence of the character and exiting or trying another character if
                found, but it is probably not worth the effort.

                ################# Clip Text Start #######################
                ;Clip to sort (ascending), selected groups of lines of text,
                ; each group consisting of one or more lines with each line
                ; terminated by an EOL, and each group of lines separated by
                ; one or more blank (empty) lines. [Art Kocsis, 11-20-08]
                ;Note: the dummy character "þ" (Thorn, ANSI 254), must not
                ; occur at any place in the selected text.

                ^!If ^$GetSelSize$ > 0 Skip_2
                ^!Continue Error Condition: No selection. Ending child clip...
                ^!Goto END

                ^!Replace "^P" >> "þ^P" AHS
                ^!Replace "^Pþ" >> "^P" AHS
                ^!Toolbar Join Lines
                ^!Menu Modify/Lines/Sort/Ascending
                ^!Replace "þ" >> "^P" AHS
                ^!Replace "^P^P" >> "^P^P^P" AHS
                ^!Toolbar Left Align
                ################# Clip Text End #######################

                At 11/20/2008 11:36 PM, you wrote:
                >Hi Art,
                >Very nice. Thanks for reposting.
                >I like this clip because:
                >1) It works independent of the number of lines in the "groups"
                >(thanks for the pointer).
                >2) I can modify it with relative ease. I added one command line to
                >get the double spacing between groups:
                >################# Clip Text Start #######################
                >;Clip to sort (ascending), selected groups of lines of text,
                >;each group consisting of one or more lines with each line
                >;terminated by an EOL, and each group of lines separated by
                >;one or more blank (empty) lines. [Art Kocsis, 11-18-08]
                >
                >^!SetDebug Off
                >^!Set %sRow%=^$Calc(^$GetRowEnd$ - ^$GetRowStart$)$
                >^!If ^%sRow% > 0 Skip_2
                >^!Continue Error Condition: Trivial or no selection. Ending child
                >clip...
                >^!Goto END
                >
                >^!Replace "^P" >> "|^P" AHS
                >^!Replace "^P|" >> "^P" AHS
                >^!Toolbar Join Lines
                >^!Menu Modify/Lines/Sort/Ascending
                >^!Replace "|" >> "^P" AHS
                >^!Replace "^P^P" >> "^P^P^P" AHS
                >^!Toolbar Left Align
                >################# Clip Text End #######################
                >What is the AHS about? I couldn't find it in the clip script help.
                >With gratitude, Namaste,
                >Corl
              • Don - HtmlFixIt.com
                Oddly I just did this for a different clip I wrote ... you have to be careful what special characters you use if you then use a regex search with the variable
                Message 7 of 30 , Nov 21, 2008
                • 0 Attachment
                  Oddly I just did this for a different clip I wrote ... you have to be
                  careful what special characters you use if you then use a regex search
                  with the variable in it as some special characters have meaning other
                  than literal in the regex.

                  ; find an odd character we can use for processing
                  ; the odd character cannot appear in the file
                  ^!SetArray
                  %odd_character_delimiter%="|";"`";"{";"}";"+";"*";"&";"%";"@";"!";"'"
                  ^!Set %odd_character_count%="0"

                  ; let's find an odd character not in the file ...
                  :Loop_Odd_Character
                  ^!Inc %odd_character_count%
                  ^!If "^%odd_character_count%" > "^%odd_character_delimiter0%" ERROR
                  ^!Find "^%odd_character_delimiter^%odd_character_count%%" CIWS
                  ; if this special character is in file loop again
                  ^!IfError NEXT ELSE Loop_Odd_Character

                  ; replace all paragraphs with special character
                  ^!Replace "^P" >> "^%odd_character_delimiter^%odd_character_count%%" ACIWS

                  And so forth.


                  Art Kocsis wrote:
                  > Hi Corl,
                  >
                  > You're welcome.
                  >
                  > You might want to incorporate the improvements suggested by Flo,
                  > namely: using an even less common character than "|" and using the
                  > ^$GetSelSize$ command (too many commands to remember them all!).
                  >
                  > One could make this clip even more robust by testing the selection for
                  > the existence of the character and exiting or trying another character if
                  > found, but it is probably not worth the effort.
                  >
                  > ################# Clip Text Start #######################
                  > ;Clip to sort (ascending), selected groups of lines of text,
                  > ; each group consisting of one or more lines with each line
                  > ; terminated by an EOL, and each group of lines separated by
                  > ; one or more blank (empty) lines. [Art Kocsis, 11-20-08]
                  > ;Note: the dummy character "þ" (Thorn, ANSI 254), must not
                  > ; occur at any place in the selected text.
                  >
                  > ^!If ^$GetSelSize$ > 0 Skip_2
                  > ^!Continue Error Condition: No selection. Ending child clip...
                  > ^!Goto END
                  >
                  > ^!Replace "^P" >> "þ^P" AHS
                  > ^!Replace "^Pþ" >> "^P" AHS
                  > ^!Toolbar Join Lines
                  > ^!Menu Modify/Lines/Sort/Ascending
                  > ^!Replace "þ" >> "^P" AHS
                  > ^!Replace "^P^P" >> "^P^P^P" AHS
                  > ^!Toolbar Left Align
                  > ################# Clip Text End #######################
                  >
                  > At 11/20/2008 11:36 PM, you wrote:
                  >> Hi Art,
                  >> Very nice. Thanks for reposting.
                  >> I like this clip because:
                  >> 1) It works independent of the number of lines in the "groups"
                  >> (thanks for the pointer).
                  >> 2) I can modify it with relative ease. I added one command line to
                  >> get the double spacing between groups:
                  >> ################# Clip Text Start #######################
                  >> ;Clip to sort (ascending), selected groups of lines of text,
                  >> ;each group consisting of one or more lines with each line
                  >> ;terminated by an EOL, and each group of lines separated by
                  >> ;one or more blank (empty) lines. [Art Kocsis, 11-18-08]
                  >>
                  >> ^!SetDebug Off
                  >> ^!Set %sRow%=^$Calc(^$GetRowEnd$ - ^$GetRowStart$)$
                  >> ^!If ^%sRow% > 0 Skip_2
                  >> ^!Continue Error Condition: Trivial or no selection. Ending child
                  >> clip...
                  >> ^!Goto END
                  >>
                  >> ^!Replace "^P" >> "|^P" AHS
                  >> ^!Replace "^P|" >> "^P" AHS
                  >> ^!Toolbar Join Lines
                  >> ^!Menu Modify/Lines/Sort/Ascending
                  >> ^!Replace "|" >> "^P" AHS
                  >> ^!Replace "^P^P" >> "^P^P^P" AHS
                  >> ^!Toolbar Left Align
                  >> ################# Clip Text End #######################
                  >> What is the AHS about? I couldn't find it in the clip script help.
                  >> With gratitude, Namaste,
                  >> Corl
                  >
                  >
                  > ------------------------------------
                  >
                  > Fookes Software: http://www.fookes.com/
                  > NoteTab website: http://www.notetab.com/
                  > NoteTab Discussion Lists: http://www.notetab.com/groups.php
                  >
                  > ***
                  > Yahoo! Groups Links
                  >
                  >
                  >
                  >
                • Art Kocsis
                  Hi Don, Well, I was right about one thing - it would not have been worth it - for me. It would have taken me many hours to design, write & debug your script.
                  Message 8 of 30 , Nov 22, 2008
                  • 0 Attachment
                    Hi Don,

                    Well, I was right about one thing - it would not have been worth it - for me.
                    It would have taken me many hours to design, write & debug your script.
                    And it would have been quite different and probably not as efficient. But I
                    will save yours for possible future use. Thanks.

                    I don't remember if I have ever used arrays so I had to them up to see what
                    was going on. That's one of the benefits of this list - one can actually learn
                    something! <g>

                    Namaste', Art

                    At 11/21/2008 05:48 PM, you wrote:
                    >Oddly I just did this for a different clip I wrote ... you have to be
                    >careful what special characters you use if you then use a regex search
                    >with the variable in it as some special characters have meaning other
                    >than literal in the regex.
                    >
                    >; find an odd character we can use for processing
                    >; the odd character cannot appear in the file
                    >^!SetArray
                    >%odd_character_delimiter%="|";"`";"{";"}";"+";"*";"&";"%";"@";"!";"'"
                    >^!Set %odd_character_count%="0"
                    >
                    >; let's find an odd character not in the file ...
                    >:Loop_Odd_Character
                    >^!Inc %odd_character_count%
                    >^!If "^%odd_character_count%" > "^%odd_character_delimiter0%" ERROR
                    >^!Find "^%odd_character_delimiter^%odd_character_count%%" CIWS
                    >; if this special character is in file loop again
                    >^!IfError NEXT ELSE Loop_Odd_Character
                    >
                    >; replace all paragraphs with special character
                    >^!Replace "^P" >> "^%odd_character_delimiter^%odd_character_count%%" ACIWS
                    >
                    >And so forth.
                    >
                    >Art Kocsis wrote:
                    ><snip>
                    > > One could make this clip even more robust by testing the selection for
                    > > the existence of the character and exiting or trying another character if
                    > > found, but it is probably not worth the effort.
                  Your message has been successfully submitted and would be delivered to recipients shortly.