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

Re: [Clip] Block Sorting

Expand Messages
  • Art Kocsis
    Hi Ray, Short answer: Do now. Long answer: Other posters have already beat me to the punch to use the join/split commands to solve your problem. I use that
    Message 1 of 13 , Mar 6, 2011
    • 0 Attachment
      Hi Ray,

      Short answer: Do now.

      Long answer:

      Other posters have already beat me to the punch to use the join/split
      commands to solve your problem. I use that technique quite frequently.

      Since I like to keep my original formatting, I add a unique temporary
      character (such as %, &, #, etc) to the end of each non-empty line before
      executing the join command and put two of these characters at the end
      of the last line in each group. After sorting, the original formatting is
      easily
      restored by simply replacing each temporary character with a CRLF. This
      also restores the empty line between groups.

      Although it is pretty simple to do manually, a clip makes it even simpler so
      why not dash off a quick clip? Answer: there is no such thing as a quick clip!

      Not wanting to publish a clip that was not robust and did not handle abnormal
      conditions, I ran into three problems:
      - Multiple separator lines
      - Oddities of high-bit characters
      - Real life demands on my time

      RegEx to the rescue for the first problem!

      The second problem comes from wanting to use a temp character that would
      have a very low probability of appearing in the document and a difference in
      "mindset" between me and Notetab. To me high-bit characters such as thorn
      (alt 0254) are special characters similar to &, #, etc but to Notetab they are
      regular characters, i.e., they are word characters. So it is not a bug in
      NT after
      all that it can find a @ in @@ but cannot find a þ in þþ without the T option!

      The third problem is self explanatory.

      Interestingly, it turns out that I had written a clip to do this very thing
      over two
      years ago and forgot about it. I was pleased to see that I have made a bit of
      progress in my coding, especially in the use of RegEx.

      To the curious, I avoid "GoTos" unless absolutely necessary as it makes for
      much more readable and error-free code.
      ##################### Code follows: ###################
      Sort Groups

      ;Clip to sort (ascending), 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 lines
      ;
      ;Note: This clip will affect either preselected text only
      ; or the entire document if no text is preselected
      ;Note: the temporary character "þ" (Thorn, ANSI 254 = ALT 0254),
      ; must not occur at any place in the selected text.
      ;Note: "þ" is a word character, hence requires the "T" ^!Find option
      ; #, @, $, %, etc are non-word chars & do not require the T option
      ;Note: If you want to keep the group spacing for all groups, make sure
      ; you include the CRLF on the last line

      ;Rev History
      ;03-06-11 Created Clip

      ^!StatusShow Running Group Sort
      ^!SetScreenUpdate Off
      ;^!SetDebug On

      ^!Set %SlctSz%=^$GetSelSize$
      ^!If ^%SlctSz%=0 ^!Jump Doc_Start
      ^!Find "þ" HST

      ^!IfError Safe
      ^!Continue Error: Text to be sorted contains internal test character "þ",
      exiting clip
      ^!Goto End

      :Safe
      ^!If ^%SlctSz%>0 ^!Replace "^P" >> "þ" AISTH
      ^!If ^%SlctSz%>0 ^!Replace "þ{2,}" >> "þ\r\n" AIRSTH
      ^!If ^%SlctSz%=0 ^!Replace "^P" >> "þ" AISTW
      ^!If ^%SlctSz%=0 ^!Replace "þ{2,}" >> "þ\r\n" AIRSTW
      ^!Toolbar Sort Ascending
      ^!Replace "þ" >> "^P" AISTH
      ^!If ^%SlctSz%=0 ^!Jump Doc_Start

      ^!Continue Align Left or Cancel?
      ^!Toolbar Left Align

      ^!SetDebug Off
      ##################### Code complete ##################

      Namaste', Art

      At 03/02/2011 11:26, Ray wrote:
      >To All,
      >
      >My question: Do we have any clips in the Fookes libraries that would sort
      >multi-line blocks of text based on a unique key sequence such as I have
      >described?
    • Ray Shapp
      Hello Art, That s a major piece of work. I ll definitely use it. Many thanks! Ray Shapp ... [Non-text portions of this message have been removed]
      Message 2 of 13 , Mar 7, 2011
      • 0 Attachment
        Hello Art,

        That's a major piece of work. I'll definitely use it.

        Many thanks!

        Ray Shapp


        On Sun, Mar 6, 2011 at 2:55 PM, Art Kocsis <artkns@...> wrote:

        >
        >
        > Hi Ray,
        >
        > Short answer: Do now.
        >
        > Long answer:
        >
        > Other posters have already beat me to the punch to use the join/split
        > commands to solve your problem. I use that technique quite frequently.
        >
        > Since I like to keep my original formatting, I add a unique temporary
        > character (such as %, &, #, etc) to the end of each non-empty line before
        > executing the join command and put two of these characters at the end
        > of the last line in each group. After sorting, the original formatting is
        > easily
        > restored by simply replacing each temporary character with a CRLF. This
        > also restores the empty line between groups.
        >
        > Although it is pretty simple to do manually, a clip makes it even simpler
        > so
        > why not dash off a quick clip? Answer: there is no such thing as a quick
        > clip!
        >
        > Not wanting to publish a clip that was not robust and did not handle
        > abnormal
        > conditions, I ran into three problems:
        > - Multiple separator lines
        > - Oddities of high-bit characters
        > - Real life demands on my time
        >
        > RegEx to the rescue for the first problem!
        >
        > The second problem comes from wanting to use a temp character that would
        > have a very low probability of appearing in the document and a difference
        > in
        > "mindset" between me and Notetab. To me high-bit characters such as thorn
        > (alt 0254) are special characters similar to &, #, etc but to Notetab they
        > are
        > regular characters, i.e., they are word characters. So it is not a bug in
        > NT after
        > all that it can find a @ in @@ but cannot find a � in �� without the T
        > option!
        >
        > The third problem is self explanatory.
        >
        > Interestingly, it turns out that I had written a clip to do this very thing
        >
        > over two
        > years ago and forgot about it. I was pleased to see that I have made a bit
        > of
        > progress in my coding, especially in the use of RegEx.
        >
        > To the curious, I avoid "GoTos" unless absolutely necessary as it makes for
        > much more readable and error-free code.
        > ##################### Code follows: ###################
        > Sort Groups
        >
        > ;Clip to sort (ascending), 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 lines
        > ;
        > ;Note: This clip will affect either preselected text only
        > ; or the entire document if no text is preselected
        > ;Note: the temporary character "�" (Thorn, ANSI 254 = ALT 0254),
        > ; must not occur at any place in the selected text.
        > ;Note: "�" is a word character, hence requires the "T" ^!Find option
        > ; #, @, $, %, etc are non-word chars & do not require the T option
        > ;Note: If you want to keep the group spacing for all groups, make sure
        > ; you include the CRLF on the last line
        >
        > ;Rev History
        > ;03-06-11 Created Clip
        >
        > ^!StatusShow Running Group Sort
        > ^!SetScreenUpdate Off
        > ;^!SetDebug On
        >
        > ^!Set %SlctSz%=^$GetSelSize$
        > ^!If ^%SlctSz%=0 ^!Jump Doc_Start
        > ^!Find "�" HST
        >
        > ^!IfError Safe
        > ^!Continue Error: Text to be sorted contains internal test character "�",
        > exiting clip
        > ^!Goto End
        >
        > :Safe
        > ^!If ^%SlctSz%>0 ^!Replace "^P" >> "�" AISTH
        > ^!If ^%SlctSz%>0 ^!Replace "�{2,}" >> "�\r\n" AIRSTH
        > ^!If ^%SlctSz%=0 ^!Replace "^P" >> "�" AISTW
        > ^!If ^%SlctSz%=0 ^!Replace "�{2,}" >> "�\r\n" AIRSTW
        > ^!Toolbar Sort Ascending
        > ^!Replace "�" >> "^P" AISTH
        > ^!If ^%SlctSz%=0 ^!Jump Doc_Start
        >
        > ^!Continue Align Left or Cancel?
        > ^!Toolbar Left Align
        >
        > ^!SetDebug Off
        > ##################### Code complete ##################
        >
        > Namaste', Art
        >
        > At 03/02/2011 11:26, Ray wrote:
        > >To All,
        >
        > >
        > >My question: Do we have any clips in the Fookes libraries that would sort
        > >multi-line blocks of text based on a unique key sequence such as I have
        > >described?
        >
        >
        >


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.