Community
    • Login

    How to achieve <bold>selection</bold>?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    macroselectionmessage boxaction
    10 Posts 3 Posters 8.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • liuruiqi1993L
      liuruiqi1993
      last edited by

      I wish when I press Ctrl + Shift + B, what I select will change into <bold>selection</bold>.
      And I have failed a hundred times. I really have no idea what to do now.
      Here is what I wrote,a Frankenstein.

      <Macro name=“<bold>” Ctrl=“yes” Alt=“no” Shift=“yes” Key=“66”>
      <Action type=“1” message=“2287” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“1” message=“2190” wParam=“0” lParam=“0” sParam=“” />
      <Action type=“3” message=“2001” wParam=“0” lParam=“0” sParam=“<bold>” />
      </Macro>

      All help is appreciated… Thanks!

      Scott SumnerS 1 Reply Last reply Reply Quote 1
      • Scott SumnerS
        Scott Sumner @liuruiqi1993
        last edited by

        @liuruiqi1993

        So if you select the text Notepad++ and you invoke a macro you want that text to change into <bold>Notepad++</bold> ?

        For that I would record a macro consisting of one step, a replace-all operation.

        Details:

        Select some text to act upon.
        Invoke the Replace dialog (Ctrl+h).
        Set Find-what zone to: (?s).+
        Set Find-what zone to: <bold>$0</bold>
        Tick In selection checkbox
        Set Search mode to Regular Expression

        Start macro recording.
        Press the Replace All button.
        Stop macro recording.
        Save macro, assign keycombo.

        Scott SumnerS 1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner @Scott Sumner
          last edited by

          @Scott-Sumner

          Correction:

          Set Find-what zone to: <bold>$0</bold>

          should be:

          Set Replace-with zone to: <bold>$0</bold>

          1 Reply Last reply Reply Quote 0
          • liuruiqi1993L
            liuruiqi1993
            last edited by

            Thanks for you help.

            “So if you select the text Notepad++ and you invoke a macro you want that text to change into <bold>Notepad++</bold> ?”
            Yes, but “the text” may contain anything, letters, words, spaces, numbers, tags, symbols. I don’t think “(?s).+” is enough.

            So, I need your further help if you don’t mind. [emoji (please)]

            Scott SumnerS 1 Reply Last reply Reply Quote 1
            • Scott SumnerS
              Scott Sumner @liuruiqi1993
              last edited by

              @liuruiqi1993

              I can tell that you haven’t tried it.
              HINT: Try it…or see the Clue below…
              :-D

              Clue : The regular expression (?s).+ means “one or more characters with any value”. The $0 means whatever matched in the Find-what part, which in this case is the any-valued characters.

              1 Reply Last reply Reply Quote 1
              • liuruiqi1993L
                liuruiqi1993
                last edited by

                I tried, but it keep alert “0 occurrences were replaced.”, should I ignore it and check shortcuts.xml?

                1 Reply Last reply Reply Quote 0
                • liuruiqi1993L
                  liuruiqi1993
                  last edited by

                  And this is what I got in shortcut.xml
                  <Macro name=“test” Ctrl=“no” Alt=“no” Shift=“no” Key=“0”>
                  <Action type=“3” message=“1700” wParam=“0” lParam=“0” sParam=“” />
                  <Action type=“3” message=“1601” wParam=“0” lParam=“0” sParam=“(?s).+” />
                  <Action type=“3” message=“1625” wParam=“0” lParam=“2” sParam=“” />
                  <Action type=“3” message=“1602” wParam=“0” lParam=“0” sParam=“<bold>$0</bold>” />
                  <Action type=“3” message=“1702” wParam=“0” lParam=“640” sParam=“” />
                  <Action type=“3” message=“1701” wParam=“0” lParam=“1609” sParam=“” />
                  </Macro>

                  1 Reply Last reply Reply Quote 0
                  • guy038G
                    guy038
                    last edited by

                    Hello @liuruiqi1993, @scott-sumner and All,

                    I’ve just build the Scott’s macro, on my portable N++ v7.5.1 version. and it’s working fine, indeed :-))

                    In my shortcuts.xml file, inside the Macro section, these lines are added :

                            <Macro name="Test" Ctrl="no" Alt="no" Shift="no" Key="0">
                                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                                <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?s).+" />
                                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                                <Action type="3" message="1602" wParam="0" lParam="0" sParam="&lt;bold&gt;$0&lt;/bold&gt;" />
                                <Action type="3" message="1702" wParam="0" lParam="640" sParam="" />
                                <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                            </Macro>
                    

                    The unique difference,compared to your version, it that the line :

                                <Action type="3" message="1602" wParam="0" lParam="0" sParam="<bold>$0</bold>" />
                    

                    is written :

                                <Action type="3" message="1602" wParam="0" lParam="0" sParam="&lt;bold&gt;$0&lt;/bold&gt;" />
                    

                    I think that the later form should be the right one ! That is to say that the special characters < and >, should be coded as &lt; and &gt;, in an XML file !

                    BTW, note that, if you forget to select any range of characters, before running this macro, nothing changes, after execution. ( logical behaviour ) If it would, all the file contents would have been surrounded with the two tags <bold> and </bold> !

                    Cheers,

                    guy038

                    1 Reply Last reply Reply Quote 4
                    • liuruiqi1993L
                      liuruiqi1993
                      last edited by

                      @guy038 and @scott-sumner
                      npp.5.9.4. version, NO. Then I tried npp.7.5.3. version, Yes, it’s working now, awesome!!
                      Thank you two, you helped a lot. And merry Christmas.

                      1 Reply Last reply Reply Quote 1
                      • guy038G
                        guy038
                        last edited by

                        Hello @liuruiqi1993 and All,

                        BTW, I advice you to downgrade to the v7.5.1 version of Notepad++, because there are some encoding issues with the last two N++ versions ! See below :

                        https://notepad-plus-plus.org/community/topic/14936/update-to-7-5-3-file-encode-wrong/2


                        Now, I understand why it did,'t work with your old 5.9.4 version. Just because, since the N++ v.6.0 version, a new search engine is implemented, with the Perl Common Regular Expressions feature, of the Boost C++ regex library ! This new search engine allows you to run complicated S/R, once you’re acquainted with Regular expressions language :-))


                        For newby people, about regular expressions concept and syntax, begin with that article, in N++ Wiki :

                        http://docs.notepad-plus-plus.org/index.php/Regular_Expressions

                        In addition, you’ll find good documentation, about the Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v5.8 ), used by Notepad++, since its 6.0 version, at the TWO addresses below :

                        http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

                        http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

                        • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

                        • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part


                        You may, also, look for valuable informations, on the sites, below :

                        http://www.regular-expressions.info

                        http://www.rexegg.com

                        http://perldoc.perl.org/perlre.html

                        Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors