Macro to select current paragraph

Macro to select current paragraph

23
Basic UserBasic User
23

    Aug 23, 2007#1

    I miss a general feature in UltraEdit: the possibility of automatically selecting a paragraph. I know it's a feature related to standard writing, not to code writing, but I am using the program for my needs and I would like to customize it as far as possible.
    I have written a macro with this syntax but it's not perfect at all. Sometimes, the first character in the paragraph is not selected and sometimes the selection goes to the previous and the next carriage return. Any suggestion?
    This is my poor macro:
    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    Find Up "^p"
    Find RegExp "[a-z]"
    EndSelect
    StartSelect
    Find Select "^p"
    End of my macro. Thank you in advance.

    6,606548
    Grand MasterGrand Master
    6,606548

      Aug 24, 2007#2

      Are your paragraphs always single lines which means do you write long lines with soft word wrap enabled to be able to read it?
      Best regards from an UC/UE/UES for Windows user from Austria

      23
      Basic UserBasic User
      23

        Aug 24, 2007#3

        Yes, because I am using UltraEdit as a text editor.

        6,606548
        Grand MasterGrand Master
        6,606548

          Aug 24, 2007#4

          Here is the macro which needs macro property Continue if a Find with Replace not found or Continue if search string not found enabled.

          ColumnModeOff
          HexOff
          Find Up "^p"
          IfFound
          Key HOME
          IfColNumGt 1
          Key HOME
          EndIf
          Else
          Top
          EndIf
          Loop
          IfEof
          ExitLoop
          EndIf
          IfCharIs 13
          Key DOWN ARROW
          Else
          IfCharIs 10
          Key DOWN ARROW
          Else
          ExitLoop
          EndIf
          EndIf
          EndLoop
          StartSelect
          Find Select "^p"
          IfSel
          Else
          SelectToBottom
          EndIf


          And here is the macro again in UEM syntax with indentations and comments - see Macro examples and reference for beginners and experts.

          Code: Select all

          ColumnModeOff
          HexOff
          //  Search upwards for a DOS line termination.
          Find Up "^p"
          /*! If found, unselect it. The cursor is already on start of the next line.
              Key LEFT ARROW followed by Key RIGHT ARROW cannot be used to unselect
              the line termination because this could be an empty line and so the
              cursor could be moved with right arrow to next line, but not with left
              arrow back to previous line depending on the configuration settings.
              So a Key HOME is used. But when configuration setting >Home Key always
              Goto column 1< is not enabled, the cursor could be moved with first
              HOME to first non-white space character. So use HOME again when this
              happens. A simple unselect command would be fine. !*/
          IfFound
              Key HOME
              IfColNumGt 1
                  Key HOME
              EndIf
          Else
          //  No line termination found upwards - set cursor to top of the file.
              Top
          EndIf
          /*! Empty lines should be ignored. So when the character at start of the
              line is a carriage return (decimal code 13) or a line-feed (dec. 10)
              move the cursor in column 1 down until a different character is found
              or end of file is reached. At end of file nothing is selected. !*/
          Loop
              IfEof
                  ExitLoop
              EndIf
              IfCharIs 13
                  Key DOWN ARROW
              Else
                  IfCharIs 10
                      Key DOWN ARROW
                  Else
                      ExitLoop
                  EndIf
              EndIf
          EndLoop
          /*! Select now everything to next DOS line termination or to end of
              file if the cursor is on start of a string at the end of the file. !*/
          StartSelect
          Find Select "^p"
          IfSel
          Else
              SelectToBottom
          EndIf
          Best regards from an UC/UE/UES for Windows user from Austria

          23
          Basic UserBasic User
          23

            Aug 26, 2007#5

            Your macro works beautifully and it's perfect for my purpose. Thank you very much!
            Best regards from Galiza (Spain)!