Community
    • Login

    Macro to add symbol before and after text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 6 Posters 857 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.
    • EkopalypseE
      Ekopalypse @JP A.
      last edited by Ekopalypse

      @JP-A said in Macro to add symbol before and after text:

      „this type of quotation marks“

      record a macro by keyboard actions like

      ctrl+x
      alt+0132
      ctrl+v
      alt+0148

      Alan KilbornA 1 Reply Last reply Reply Quote 4
      • Alan KilbornA
        Alan Kilborn @Ekopalypse
        last edited by

        @Ekopalypse said in Macro to add symbol before and after text:

        record a macro by keyboard actions like

        Potential downsides:

        • destroys clipboard contents
        • doesn’t work for those without numeric keypad on their keyboard (and yes, there are those of us for which a keyboard with a numeric keyboard is a hinderance; thus mine):

        074bcbd7-c967-4923-8aa0-fad5d50dc965-image.png

        1 Reply Last reply Reply Quote 4
        • JP A.J
          JP A.
          last edited by

          What a cool forum!

          Thank you for your suggestions. I love Ekopalypse’s approach for the simplicity, but Alan is right about the clipboard issue. And I use the clipboard a ton. So I’ve tried Alan’s solution and it works beautifully.

          Thank you!

          1 Reply Last reply Reply Quote 1
          • mathlete2M
            mathlete2 @Alan Kilborn
            last edited by

            @Alan-Kilborn thanks for the solution! I was able to use it to create the following macro for markup coding that I will be doing frequently (among others):

                    <Macro name="bold" Ctrl="yes" Alt="no" Shift="no" Key="66">
                        <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="**${0}**" />
                        <Action type="3" message="1702" wParam="0" lParam="898" sParam="" />
                        <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                    </Macro>
            

            Unfortunately, when I do a multi-select, only the last selection is modified by the macro. Is there a way to modify the macro code to support multiple selections? For example, in the sentence I want this, this, and this to be modified., I want to be able to Ctrl+double-click each this, apply the shortcut once, and have all 3 changed to **this** (i.e. I want **this**, **this**, and **this** to be modified.).

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • TroshinDVT
              TroshinDV
              last edited by

              https://github.com/trdm/jn-npp-scripts
              trdmBrackets.js
              alt text

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @TroshinDV
                last edited by PeterJones

                @TroshinDV ,

                What does your screenshot add to the conversation? With no explanation in the text of your post, it is very hard to tell what you are trying to say. While the old saying is that “a picture is worth 1000 words”, I don’t think that’s true when there is no context given to the picture.

                It looks like you were showing an alternative to using the built-in macro language, which is fine (but unnecessary, since the OP had a solution already, which doesn’t require external installs)… but explaining that this is an alternative solution will help.

                Does your trdmBrackets.js script address the OP’s additional request of wanting to handle multi-selection? Your example screenshot only shows a single selection, and you didn’t explain, so we cannot know.

                TroshinDVT 1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @mathlete2
                  last edited by

                  @mathlete2 ,

                  The problem with trying to do an “in-selection” search-and-replace in a multi-selection region is that the search-and-replace engine navigates through the matches by changing the selection… which would break the multi-selection.

                  In fact, if you try to do a multi-selection region and then run Search > Replace, you will see that the “☐ In Selection” checkbox is greyed out, so that you cannot use it. A multi-selection is a different beast than a normal selection, and there are some things that don’t work the same.

                  It might be that you have to go deeper into one of the scripting languages (like the jN-NPP that @TroshinDV uses, or the PythonScript that many of the regulars use)… Looking through the scintilla docs, I found “Multiple Selection and Virtual Space” – these messages should all have corresponding methods in the PythonScript editor object (or equivalent in other scripting plugins). So I pieced together this script which does multi-selection replacement, where it doesn’t matter what the contents of the multi-selection are: it will just surround them by the **:

                  # encoding=utf-8
                  """in response to https://community.notepad-plus-plus.org/topic/21446/ multi-selection request
                  
                  the comments show my debug code, or alternative methods
                  
                  this will loop through all N sections of the multi-selection
                  for each section:
                  * find the start and end locations
                  * grab the original text from that section
                  * replace the original by surrounding it with **
                  
                  Notes:
                  * it allows a single undo for the whole group of replacements, but if you do UNDO,
                      it will clear the multi-selection
                  * at the end of the replacement, the multi-selection goes down to a zero-length
                      selection at the start of each of the original words;
                          shift+arrows or shift+ctrl+arrow will allow you to extend the multi-selection again
                  
                  """
                  
                  from Npp import *
                  
                  editor.beginUndoAction()
                  
                  for mSel in range(editor.getSelections()):
                      selStart = editor.getSelectionNStart(mSel)
                      selEnd = editor.getSelectionNEnd(mSel)
                      orig = editor.getTextRange(selStart, selEnd)
                      #console.write("loop #{}: {}..{} = \"{}\"\n".format(mSel,selStart,selEnd,orig))
                      txt = "**" + orig + "**"
                      editor.replace(orig,txt,0,selStart,selEnd)
                  
                  
                  
                  editor.endUndoAction()
                  
                  mathlete2M 1 Reply Last reply Reply Quote 2
                  • mathlete2M
                    mathlete2 @PeterJones
                    last edited by

                    @PeterJones thanks for putting that together! Unfortunately, I’m not familiar with how to work such scripts into NP++. Where is this documented?

                    PeterJonesP TroshinDVT 2 Replies Last reply Reply Quote 0
                    • PeterJonesP
                      PeterJones @mathlete2
                      last edited by PeterJones

                      @mathlete2 ,

                      PythonScript is a plugin, which you install through Plugins > Plugins Admin interface.

                      It comes with its own documentation available thru the Plugins > PythonScript > Context-help menu entry

                      This post gives a run-through for how to get the script into the plugin, and how to run the script

                      1 Reply Last reply Reply Quote 2
                      • TroshinDVT
                        TroshinDV @PeterJones
                        last edited by

                        @PeterJones said in Macro to add symbol before and after text:

                        What does your screenshot add to the conversation?

                        I hinted a person that there is another solution. If he became interested, he would ask. And his silence indicates a lack of interest.
                        Я намекнул человеку что есть и другое решение. Если бы он заинтересовался, он бы спросил. А его молчание указывает на отсутствие интереса.

                        1 Reply Last reply Reply Quote 0
                        • TroshinDVT
                          TroshinDV @mathlete2
                          last edited by TroshinDV

                          @mathlete2 said in Macro to add symbol before and after text:

                          @PeterJones thanks for putting that together! Unfortunately, I’m not familiar with how to work such scripts into NP++. Where is this documented?

                          https://github.com/sieukrem/jn-npp-plugin
                          My developments are based on this plugin.

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