• Login
Community
  • Login

How to wrap selection by strings on both ends?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 4 Posters 944 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.
  • P
    pepr
    last edited by Nov 9, 2024, 12:43 PM

    For document editing, I need to wrap the selected part of the text by special quotes (UNICODE characters that are used in Czech for quoting), like this:

    „this is the text to be quoted“

    Having this is the text to be quoted, I wan to select it, and to start something named do do the quoting. Say, I wan to name it as uv.

    I remember from some editor (in the past, I do not remember the editor) that it could be done like

    xxx #this is the text to be quoted#uv xxx

    In other words, the text was marked by # (or something like that), the second one was followed by the name of the macro, and started by some hot-key.

    Is anything like that possible in the Notepad++ editor?

    Thanks,
    Petr

    M M 2 Replies Last reply Nov 9, 2024, 5:16 PM Reply Quote 0
    • M
      Mark Olson @pepr
      last edited by Nov 9, 2024, 5:16 PM

      @pepr

      I am having a hard time understanding what you are asking for. If you are not a native English speaker, I would recommend writing what you want in your native language, and copy-pasting it into Google Translate rather than trying to do the translation yourself. It sounds like there are two things you want:

      1. Wrap the selected text in quotes
      2. Add a # and then a name to the end of the selected text

      How to wrap the selected text in quotes

      Important: while doing steps 2-4, do not click in the text area of the Notepad++ window! If you do, your selection will change and that will become part of the macro.

      1. Go to Macro->Start Recording from the Notepad++ main menu bar
      2. Go to Search->Replace... from the main menu; the find/replace form will pop up.
      3. Set the fields of the find/replace form as follows:
        • Find what: -> (?s).*
        • Replace with: -> „${0}“
        • Wrap around -> checked
        • Search Mode -> Regular expression
        • In selection -> checked
      4. Hit the Replace button
      5. Go to Macro->Stop Recording from the Notepad++ main menu
      6. Try selecting a different area of text and run Macro->Playback from the Notepad++ main menu, and make sure that the macro does what you want
      7. Go to Macro->Save Current Recorded Macro from the NPP main menu and save your macro with a name. You can also give this macro a keyboard shortcut for ease of use later.

      How to add #uv at the end of your selected text

      1. Repeat steps 1-2 of the list above
      2. Set the fields of the find/replace form as follows:
        • Find what: -> (?s).*
        • Replace with: -> ${0}#uv
        • Wrap around -> checked
        • Search Mode -> Regular expression
        • In selection -> checked
      3. Repeat steps 4-7 of the list above

      Other notes

      For more reading on macros, see the documentation here .

      P 1 Reply Last reply Nov 10, 2024, 5:19 PM Reply Quote 4
      • P
        pepr @Mark Olson
        last edited by Nov 10, 2024, 5:19 PM

        @Mark-Olson: Thanks. The first part works exactly as I wanted. Looking at the shortcuts.xml, I can see:

                <Macro name="uv" 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="„${0}“" />
                    <Action type="3" message="1702" wParam="0" lParam="896" sParam="" />
                    <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                </Macro>
        

        For explaining the second part. The other mentioned editor used the #quoting by hashes#macro_name to ge the same effect. Some shortcut was used to tell that the thing before is the macro name, and the special character is the delimiter (instead of making a selection). It may have been the JED editor that simulates Emacs (using a different inner language). The macros were easily edited, and you could use even more delimiters to wrap the parts, say, by more complex LaTeX macros with more arguments. I am not using it more than 20 years; so, I am not sure whether JED was the one.

        1 Reply Last reply Reply Quote 2
        • M
          mkupper @pepr
          last edited by Nov 12, 2024, 1:28 AM

          @pepr, one minor comment on

          „this is the text to be quoted“

          I see that for the opening quote you used U+201E DOUBLE LOW-9 QUOTATION MARK. I expected you to use U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK for the closing quote. Instead you used U+201C LEFT DOUBLE QUOTATION MARK.

          The difference is

          • „this is the text to be quoted‟ using U+201F
          • „this is the text to be quoted“ using U+201C

          If you intended to use U+201F then the line in your shortcuts.xml would look like

          <Action type="3" message="1602" wParam="0" lParam="0" sParam="„${0}‟" />
          

          The second part that you desire likely could be done in Notepad++. @Mark-Olson already provided you with a hint on how to do it by showing you a search replace that takes the current selection and inserts a „ in front of it and appends a ‟ at the end of it.

          If instead you want to type

          xxx #this is the text to be quoted#uv xxx
          

          You then run this regular expression search/replace:
          ** Search: #([^#]+)#uv
          Replace: „${1}‟ **

          That will replace the #...#uv style marks in your text with „...‟.

          If you want to be able to use several styles of quotes using #xx or other things besides #uv then it’s still possible though gets far messier do to it with a single search/replace.

          P 1 Reply Last reply Nov 12, 2024, 9:43 AM Reply Quote 2
          • P
            pepr @mkupper
            last edited by Nov 12, 2024, 9:43 AM

            @mkupper: Well, the Czech typography uses the double quotes also known as 99 and 66 (because of the shape) — the 99 low, and 66 up. See the image cut from somewhere:

            65daf3e7-2493-4676-a899-a71e42c6e07e-obrazek.png

            Thanks for the hint for using the regular expression with # as marks. I was not thinking about that possibility.

            @anyone: The macro recording and playback in Notepad++ is fine for simple things, in my opinion. However, it is difficult to modify the macros (through editing shortcuts.xml). Is there any plugin that implements some alternative approach to the macros?

            A 1 Reply Last reply Nov 12, 2024, 12:07 PM Reply Quote 1
            • A
              Alan Kilborn @pepr
              last edited by Nov 12, 2024, 12:07 PM

              @pepr said in How to wrap selection by strings on both ends?:

              Is there any plugin that implements some alternative approach to the macros?

              There’s SCRIPTING.

              P 1 Reply Last reply Nov 12, 2024, 4:01 PM Reply Quote 2
              • P
                pepr @Alan Kilborn
                last edited by Nov 12, 2024, 4:01 PM

                @Alan-Kilborn: Thanks a lot! Being fluent with Python, I have installed the PythonScript, and I am learning first steps.

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