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

Help with clip programming

Expand Messages
  • John Shotsky
    I ve found myself stuck on what should have been a fairly simple task. I want to add parentheses around one or more lines.) Or it could be brackets or any
    Message 1 of 8 , May 5, 2010
    • 0 Attachment
      I've found myself stuck on what should have been a fairly simple task.

      I want to add parentheses around one or more lines.) Or it could be brackets or any other character.
      The user will either place the cursor in the line if it is a single line, or will select at least a
      part of all the lines if multiline. The goal is to expand either case to the beginning and end of
      the lines, then place parens around the whole thing. There is no punctuation or other definable
      object other than the selection itself to work with.

      So, for case 1:

      This is one line. User places cursor anywhere in this line and clicks clip.
      Result:
      (This is one line. User places cursor in this line and clicks clip.)

      Case 2: Multiple lines, note that parens may be within the lines.

      This is one line. User places cursor in this line drags to the last line.
      This is another line.
      This is another line. User drags from first line into this line. (And it has this paren phrase in
      it.)

      Result:
      (This is one line. User places cursor in this line drags to the last line.
      This is another line.
      This is another line. User drags from first line into this line. (And it has this paren phrase in
      it.))

      I've tried using the token "^&". I've used '^!Select Lines' to extend the selection to the beginning
      and ends of the lines. That works.

      What the problem seems to be is that once the selection has been extended, the ^& token is not
      expanded to include the new selection. And since I don't know how many lines are involved, I can't
      determine how to find the beginning and ends of the new selection. I have found things that 'almost'
      work, but the existing parens cause a problem, so I need a different solution. I was thinking I
      could place the entire thing into a variable, but I can't seem to get the whole selection into a
      variable, only the token and the parens, but the rest of the selection is missed.

      Any ideas?
      Thanks!
      John



      [Non-text portions of this message have been removed]
    • diodeom
      ... Have you considered ^!Select Paragraphs?
      Message 2 of 8 , May 5, 2010
      • 0 Attachment
        "John Shotsky" <jshotsky@...> wrote:
        >
        > I've found myself stuck on what should have been a fairly simple task.
        >

        Have you considered ^!Select Paragraphs?
      • diodeom
        ... An example: ^!Select Paragraphs ^!IfMatch ^[^ r]++ R ^$GetSelection$ Next Else Skip ^!Select -2 ^!SetClipboard ^$GetSelection$ ^!InsertText
        Message 3 of 8 , May 5, 2010
        • 0 Attachment
          > Have you considered ^!Select Paragraphs?
          >

          An example:

          ^!Select Paragraphs
          ^!IfMatch "^[^\r]++\R" "^$GetSelection$" Next Else Skip
          ^!Select -2
          ^!SetClipboard ^$GetSelection$
          ^!InsertText *^$GetClipboard$*
        • John Shotsky
          Yes, same result as ^!Select Lines. When the parens are involved, it throws a Regex error and fails. The selection looks good with both. How do I place parens
          Message 4 of 8 , May 5, 2010
          • 0 Attachment
            Yes, same result as ^!Select Lines. When the parens are involved, it throws a Regex error and fails.

            The selection looks good with both. How do I place parens around the whole selection, not just the
            token?

            Regards,
            John

            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of diodeom
            Sent: 05 May, 2010 12:54 PM
            To: ntb-clips@yahoogroups.com
            Subject: [Clip] Re: Help with clip programming


            "John Shotsky" <jshotsky@...> wrote:
            >
            > I've found myself stuck on what should have been a fairly simple task.
            >

            Have you considered ^!Select Paragraphs?



            [Non-text portions of this message have been removed]
          • diodeom
            It looks like ^& refers only to the original selection, not the one extended with ^!SelectLines (or -Paragraphs). Have you tried, as in my sample, to
            Message 5 of 8 , May 5, 2010
            • 0 Attachment
              It looks like ^& refers only to the "original" selection, not the one extended with ^!SelectLines (or -Paragraphs). Have you tried, as in my sample, to explicitly ^$GetSelection$ and store it either in Clipboard or as a variable? (It does the job for me.) Would you post your code?

              "John Shotsky" <jshotsky@...> wrote:
              >
              > Yes, same result as ^!Select Lines. When the parens are involved, it throws a Regex error and fails.
              >
              > The selection looks good with both. How do I place parens around the whole selection, not just the
              > token?
              >
              > Regards,
              > John
              >
            • John Shotsky
              I got a version to work. One problem is that I was using RS for options on the replace, which means the parens in the variable were not escaped. Removing the R
              Message 6 of 8 , May 5, 2010
              • 0 Attachment
                I got a version to work. One problem is that I was using RS for options on the replace, which means
                the parens in the variable were not escaped. Removing the R fixed that regex error.

                The other problem was that the trailing CR is included in the GetSelection which causes the closing
                paren to be on the next line. Instead of manipulating the variable, I just fixed it post replace.

                Thanks for the assist!
                Regards,
                John

                From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of diodeom
                Sent: 05 May, 2010 01:18 PM
                To: ntb-clips@yahoogroups.com
                Subject: [Clip] Re: Help with clip programming


                > Have you considered ^!Select Paragraphs?
                >

                An example:

                ^!Select Paragraphs
                ^!IfMatch "^[^\r]++\R" "^$GetSelection$" Next Else Skip
                ^!Select -2
                ^!SetClipboard ^$GetSelection$
                ^!InsertText *^$GetClipboard$*



                [Non-text portions of this message have been removed]
              • diodeom
                ... Yes, sir. (To overcome this, I proposed probably overly complex conditional shrinking of the selection from its end by these very two offending CRLF
                Message 7 of 8 , May 5, 2010
                • 0 Attachment
                  "John Shotsky" <jshotsky@...> wrote:
                  > ...
                  > The other problem was that the trailing CR is included
                  > in the GetSelection which causes the closing paren to
                  > be on the next line. Instead of manipulating the
                  > variable, I just fixed it post replace.
                  >

                  Yes, sir. (To overcome this, I proposed probably overly complex conditional shrinking of the selection from its end by these very two offending CRLF characters, ^!Select -2.)

                  And sorry for the following (oopsie!) redundancy:

                  > ^!SetClipboard ^$GetSelection$
                  > ^!InsertText (^$GetClipboard$)

                  There ain't no need to "store" nothin. It could just read:
                  ^!InsertText (^$GetSelection$)
                • John Shotsky
                  I always learn something. Thanks, I added the: ^!Select -2 And now it works better. After rereading the help, I understand how it works, but it never dawned on
                  Message 8 of 8 , May 5, 2010
                  • 0 Attachment
                    I always learn something. Thanks, I added the:
                    ^!Select -2
                    And now it works better.
                    After rereading the help, I understand how it works, but it never dawned on me during my
                    experimentation.

                    I have a 'My Notes' clip in my main library. I add notes that clarify how to do things there. It is
                    just a NoteTab text file stored in the Documents folder, but it is called up by a clip. I usually
                    have it as one of my open documents so I can add to it when necessary. This deserves to go there.

                    Regards,
                    John

                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of diodeom
                    Sent: 05 May, 2010 02:33 PM
                    To: ntb-clips@yahoogroups.com
                    Subject: [Clip] Re: Help with clip programming


                    "John Shotsky" <jshotsky@...> wrote:
                    > ...
                    > The other problem was that the trailing CR is included
                    > in the GetSelection which causes the closing paren to
                    > be on the next line. Instead of manipulating the
                    > variable, I just fixed it post replace.
                    >

                    Yes, sir. (To overcome this, I proposed probably overly complex conditional shrinking of the
                    selection from its end by these very two offending CRLF characters, ^!Select -2.)

                    And sorry for the following (oopsie!) redundancy:

                    > ^!SetClipboard ^$GetSelection$
                    > ^!InsertText (^$GetClipboard$)

                    There ain't no need to "store" nothin. It could just read:
                    ^!InsertText (^$GetSelection$)



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