Community
    • Login

    Macro for Open, Find and Replace and Save

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    22 Posts 6 Posters 4.4k 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.
    • José Luis Montero CastellanosJ
      José Luis Montero Castellanos
      last edited by

      Good morning experts :)
      Can this thing be done using macros?

      It was very difficult to just open the file, and even less for find and replace using RegEX and then save it.

      In the user manual it looks so easy, that before the failure to execute the macro one thinks “That’s so good they don’t give so much! :¬)”

      The file I want to edit is the UDL hmgui.xml in the notepad++\UserDefineLangs folder.

      The search and replace strings:

      Search: (?s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)
      Replace: ?1\5\2\7\4\1\6\3:${12}${9}${14}${11}${8}${13}${10}

      I reviewed the documentation in Macros and Configuration of the user manual, as well as the links, to Scintilla ( Scintilla.iface.) and (menuCmdID.h,) but the truth is that it is too big for me given my capacity or experience.

      The only thing I could do was change an “a” to a “b” via macro. :)ⁿ

      Any suggestion is welcome.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @José Luis Montero Castellanos
        last edited by

        @José-Luis-Montero-Castellanos said in Macro for Open, Find and Replace and Save:

        The only thing I could do was change an “a” to a “b” via macro.

        If you can do that, then I don’t understand why you can’t make it do a more complicated replacement.

        Are you saying that your replacement isn’t correct? If so, it is hard to evaluate that since you didn’t follow the requirements for posting your find and replace expressions and put them in boxes like this. So this website mucked with them and we can’t tell with any real confidence what they actually are.

        José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 2
        • José Luis Montero CastellanosJ
          José Luis Montero Castellanos @Alan Kilborn
          last edited by José Luis Montero Castellanos

          @Alan-Kilborn
          Thanks for your reply:
          What the “context” says was that I couldn’t open and then save the file via macro and all I could do via macro was find and replace, and I did that to see how it was set to the file shorcuts.xml and take it as a guide for when I went to write the $(full_pathname) of the file.

          Now what I put in context that you points out as this is not code or a line that should be interpreted because the search and replace wasn’t the problem!. as it was open, select the file (or type its name in the box) and then save via macro.

          Have a nice day.

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @José Luis Montero Castellanos
            last edited by Alan Kilborn

            @José-Luis-Montero-Castellanos

            So your question boils down to “can I open a specific file in a macro?” as that is the first step in your described sequence. It seems that if all of the other “context” was NOT supplied in the first posting, this would have been easier to understand.

            José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 0
            • José Luis Montero CastellanosJ
              José Luis Montero Castellanos @Alan Kilborn
              last edited by

              @Alan-Kilborn
              Thanks again:
              First of all the title says Macro Open, Save, Find, Replace, And in the content Open and Save are marked as being problematic while Find and Replace as easy.

              Don’t mind if I laugh at myself :)ⁿ expressing how little I could do…

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

                Hello, @josé-luis-montero-castellanos, @aln-kilborn and all,

                @josé-luis-montero-castellanos, regarding your regex S/R :

                • SEARCH (?s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)

                • REPLACE ?1\5\2\7\4\1\6\3:${12}${9}${14}${11}${8}${13}${10}

                Why do you need the leading in-line modifier (?s), in the search part ? Do you mean that the single char . in group 2, 4, 6, 9, 11 and 13 may also represent a line-break char ( \r or \n ) ?

                I suppose not ! Then, your correct search regex is rather :

                (?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)

                where any . single char will represent a non-break char, only !


                Now, I noticed that the groups used, in replacement, for each alternative of the search regex, are in the same order ! Then, you can use, preferably, a specific feature of the Boost Regex engine, called Branch Reset

                For instance, in your regex, the numbers of each group are :

                (?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)
                Gr : 1    2  3   4  5    6  7   |8    9  10  11 12   13 14  
                

                If we use the Branch Reset feature the search regex becomes :

                (?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S))
                Gr:     1    2  3   4  5    6  7   |1    2  3   4  5    6  7
                

                Thus, your entire regex S/R can be simplified as below :

                • SEARCH (?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S))

                • REPLACE \5\2\7\4\1\6\3


                For instance, given this INPUT text :

                <St2/S4<Xt6/X
                <Xt9/XB<StD/S
                

                You would get the OUTPUT text, below :

                <Xt2/X4<St6/S
                <St9/SB<XtD/X
                

                Notes :

                • The Regular expression option must be selected

                • Preferably, tick the Wrap around option

                Best Regards,

                guy038

                José Luis Montero CastellanosJ Jaguar AsadJ 2 Replies Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @José Luis Montero Castellanos
                  last edited by

                  @José-Luis-Montero-Castellanos said in Macro for Open, Find and Replace and Save:

                  Open and Save are marked as being problematic while Find and Replace as easy.

                  In my reading of your initial post, most of your description was pretty nebulous. And like Alan and Guy, I thought your problem was with the search-and-replace.

                  Saying “it was very difficult just open the file” implies that you got it working eventually. But now you say it’s “problematic”. You still haven’t said what “problematic” means to you.

                  What the “context” says was that I couldn’t open and then save the file via macro and all I could do via macro was find and replace,

                  This is the only time you’ve been definite about your problems.

                  It would have been so much easier for us to understand you if, in the body of your post (not just the title), you had said,
                  “I tried to record a macro that opened a file, ran a search-and-replace, and save the file. But the file-open and file-save portion isn’t working”

                  As to why File Open isn’t working: the macro language only records commands that don’t require any user input (well, and search-and-replace, where it saves the user input as constants – it doesn’t ask you for the inputs when it runs). But File Open requires user input, whether it’s during the recording or during the run. So the macro language cannot implement it.

                  As to why File Save isn’t working: my guess is the File Open just made you think that File Save wasn’t working. You can record a search-and-replace-then-save just fine with the macro language. But a Save As, because it requires user input, will not work in a macro.

                  If you want features not available to the macro language – like loops, if/else, or user input (including File Open or Save As) – then you will need to move beyond the macro language, and use one of the scripting plugins (like PythonScript).

                  TL;DR Summary: “File > Open” and “File > Save As” will not work in a macro. Search-and-replace and “File > Save” do work in a macro.

                  José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 3
                  • José Luis Montero CastellanosJ
                    José Luis Montero Castellanos @PeterJones
                    last edited by

                    @PeterJones
                    Thanks for your reply:
                    If a macro can’t open a file, I have to find a different solution.
                    You already said the answer: NO! .

                    Let’s go to the title:

                    Macro for Open, Find and Replace and Save
                    

                    And after a courteous greeting, comes something essential:

                    Can this thing be done using macros?
                    

                    (Which thing? ) = “Macro for Open, Find and Replace and Save!!!” (the title) be done using macros??? (the opening sentence after the salutation, the essential preamble)

                    Answer? NO. Nothing more to say.

                    Nebulous? Maybe, I give you the credit.
                    Thank you anyway.

                    Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn @José Luis Montero Castellanos
                      last edited by

                      @José-Luis-Montero-Castellanos said in Macro for Open, Find and Replace and Save:

                      Let’s go to the title:
                      Macro for Open, Find and Replace and Save

                      And after a courteous greeting, comes something essential:
                      Can this thing be done using macros?

                      (Which thing? ) = “Macro for Open, Find and Replace and Save!!!” (the title) be done using macros??? (the opening sentence after the salutation, the essential preamble)
                      Answer? NO. Nothing more to say.
                      Nebulous? Maybe, I give you the credit.

                      Why do you persist with this when the two (perhaps three) top posters on this site, that have helped decipher the needs of many, many people asking questions for many years, judged your original post to be unclear? Can’t you just accept that it WAS unclear?

                      Do more people have to post and agree with that, before you change your attitude and stop with the refutations? Your position looks worse each time you post; sad.

                      José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 1
                      • PeterJonesP
                        PeterJones @José Luis Montero Castellanos
                        last edited by PeterJones

                        @José-Luis-Montero-Castellanos ,

                        You already said the answer: NO! .

                        The short version is no.

                        Answer? NO. Nothing more to say.

                        Actually, no, that’s not true. There was more to say, because there are alternatives. And my post where I said the unambiguous “no”, I also gave one of those alternatives.

                        Let’s go to the title: … And after a courteous greeting, comes something essential:

                        You trying to justify your phrasing or us trying to justify our interpretation or difficulty understanding is rather irrelevant at this point. It won’t help you or us going forward.

                        Going forward, understand that it’s generally considered polite to include all the essential details in the post body, not spread across the title and the body. (Titles are too small for helpers to gain any useful information, so many don’t even pay much attention to the title, assuming that all the critical information will be in the body.)

                        1 Reply Last reply Reply Quote 1
                        • José Luis Montero CastellanosJ
                          José Luis Montero Castellanos @guy038
                          last edited by José Luis Montero Castellanos

                          Hello, thank you for your support:
                          As I put it, the search and replace function or deciphering its function is not my problem, but to put each of the functions (open file, replace text and save) into a “notepad++ macro”.

                          Anyway I’m going to pass you the part where I thought to use it.

                          <Styles mode="lght">
                          	<WordsStyle name="DEFAULT"  ... fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                          	<WordsStyle name="COMMENTS" ... fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                          	<WordsStyle name="LINE COMME... fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                          	.
                          	.
                          	.
                          </Styles>                       ...
                          <Xtyles mode="dark">            ...
                          	<WordsStyle name="DEFAULT"  ... fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                          	<WordsStyle name="COMMENTS" ... fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                          	<WordsStyle name="LINE COMME... fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                          	.
                          	.
                          	.
                          </Xtyles>
                          </UserLang>
                          

                          The purpose is to change a <Style> tag and its </Style> pair to the tags, <Xtyle> and </Xtyle> by enabling the “dark mode” section and disabling the “light mode” section thinking the UDL won’t do case of the <Xtype> tag.

                          (?s) is because .* must include many lines of text along with their line breaks.
                          The other weird function is ?1 in the replacement string making it a conditional selector.
                          Well I’m studying the user manual in the RegEX section and Npp is fabulous at that.
                          I haven’t experienced your notes yet, but right now I’m getting ready to do so…
                          Cheers…

                          1 Reply Last reply Reply Quote 1
                          • José Luis Montero CastellanosJ
                            José Luis Montero Castellanos @Alan Kilborn
                            last edited by José Luis Montero Castellanos

                            @Alan-Kilborn

                             Can’t you just accept that it WAS unclear?
                            

                            I don’t want to insult your intelligence by asking you to clarify what this part of my answer means.

                            Nebulous? Maybe, I give you the credit!!!.*

                            And maybe means that anyone involved could be right. Or not?

                            Lycan ThropeL 1 Reply Last reply Reply Quote 0
                            • Lycan ThropeL
                              Lycan Thrope @José Luis Montero Castellanos
                              last edited by

                              @José-Luis-Montero-Castellanos ,

                              It’s the language, obviously. It made me wonder if you were being insulting or not, also, the way it was phrased. So let’s not make it worse by making more assumptions. :) I like your idea, so using the Python Plugin might be a good vehicle for you to try and implement it, but it has to be worth the needed learning and time to be worth it to you. We only work on stuff when not getting paid, because we are interested or passionate about it.

                              José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 0
                              • guy038G
                                guy038
                                last edited by guy038

                                Hi, @josé-luis-montero-castellanos, @alan-kilborn, @peterjones and all,

                                Ah… OK, I do understand the regex problem ;-))

                                I thought about a very simple way to achive it !

                                To verify my assumption, I made a test with the markdown._preinstalled.udl.xml file, within the UserDefineLangs folder

                                • First, I copied this file with a new name markdown._new.udl.xml, left in the UserDefineLangs folder, too

                                • I opened this new file and change the line below, accordingly :

                                    <UserLang name="Markdown (new)" ext="md markdown" udlVersion="2.1">
                                
                                • Then, before the line <Styles>, I inserted the comment line <!-- Light mode --> giving :
                                        <!-- Light mode -->
                                        <Styles>
                                
                                • I copied all the <Styles>......</styles section

                                • I pasted all these lines at the end of the markdown._new.udl.xml file

                                  • Preceded with a comment line <!-- Dark mode -->

                                  • Followed with the two final lines </userLang> and </NotepadPlus>

                                => So, the final contents of the markdown._new.udl.xml file are :

                                <!--//
                                Markdown-plus-plus is a project to support Markdown syntax in Notepad++.
                                All UDLs are carefully designed by human, rather than generated by machine.
                                
                                Want an UDL for different theme?
                                Want to change its preference?
                                Want to create your own?
                                Go get it: https://github.com/Edditoria/markdown-plus-plus
                                
                                Please read the README file for details.
                                Welcome issues and pull requests via the above link.
                                
                                Copyright (c) Edditoria. Open source under the MIT license:
                                https://github.com/Edditoria/markdown-plus-plus/blob/master/LICENSE.txt
                                //-->
                                <NotepadPlus>
                                    <UserLang name="Markdown (new)" ext="md markdown" udlVersion="2.1">
                                        <Settings>
                                            <Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" />
                                            <Prefix Keywords1="yes" Keywords2="yes" Keywords3="yes" Keywords4="yes" Keywords5="yes" Keywords6="yes" Keywords7="yes" Keywords8="no" />
                                        </Settings>
                                        <KeywordLists>
                                            <Keywords name="Comments">00# 01 02((EOL)) 03&lt;!-- 04--&gt;</Keywords>
                                            <Keywords name="Numbers, prefix1"></Keywords>
                                            <Keywords name="Numbers, prefix2"></Keywords>
                                            <Keywords name="Numbers, extras1"></Keywords>
                                            <Keywords name="Numbers, extras2"></Keywords>
                                            <Keywords name="Numbers, suffix1">.</Keywords>
                                            <Keywords name="Numbers, suffix2">.</Keywords>
                                            <Keywords name="Numbers, range"></Keywords>
                                            <Keywords name="Operators1">@ &lt; &gt; \&lt; \&gt; \\ \` \* \_ \{ \} \[ \] \( \) \# \+ \- \. \! \~ \| |:-: |:--: |:---: | :-: :--: :---: :|: |: :|</Keywords>
                                            <Keywords name="Operators2">- + :- :-- :--- :</Keywords>
                                            <Keywords name="Folders in code1, open"></Keywords>
                                            <Keywords name="Folders in code1, middle"></Keywords>
                                            <Keywords name="Folders in code1, close"></Keywords>
                                            <Keywords name="Folders in code2, open"></Keywords>
                                            <Keywords name="Folders in code2, middle"></Keywords>
                                            <Keywords name="Folders in code2, close"></Keywords>
                                            <Keywords name="Folders in comment, open"></Keywords>
                                            <Keywords name="Folders in comment, middle"></Keywords>
                                            <Keywords name="Folders in comment, close"></Keywords>
                                            <Keywords name="Keywords1">http:// (http:// https:// (https:// mailto: (mailto: ftp:// (ftp:// ftps:// (ftps:// (/ /</Keywords>
                                            <Keywords name="Keywords2">==== ----</Keywords>
                                            <Keywords name="Keywords3">*** ___</Keywords>
                                            <Keywords name="Keywords4">** __</Keywords>
                                            <Keywords name="Keywords5">* _</Keywords>
                                            <Keywords name="Keywords6">** __</Keywords>
                                            <Keywords name="Keywords7">* _</Keywords>
                                            <Keywords name="Keywords8"></Keywords>
                                            <Keywords name="Delimiters">00![ 00[ 01\ 02] 02] 03``` 03` 03~~~ 04\ 05``` 05((EOL `)) 05~~~ 06*** 07\ 08((EOL ***)) 09** 10\ 11((EOL **)) 12* 13\ 14((EOL *)) 15** 16\ 17((EOL **)) 18* 19\ 20((EOL *)) 21 22 23</Keywords>
                                        </KeywordLists>
                                        <!-- Light mode -->
                                        <Styles>
                                            <WordsStyle name="DEFAULT" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="LINE COMMENTS" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="NUMBERS" fgColor="0080FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="KEYWORDS1" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="KEYWORDS2" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="KEYWORDS3" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS4" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="KEYWORDS5" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="KEYWORDS6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS7" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS8" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="OPERATORS" fgColor="8080FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="FOLDER IN CODE1" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="FOLDER IN CODE2" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="FOLDER IN COMMENT" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="DELIMITERS1" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="DELIMITERS2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="DELIMITERS3" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS4" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="65600" />
                                            <WordsStyle name="DELIMITERS5" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="32800" />
                                            <WordsStyle name="DELIMITERS6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS7" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS8" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                        </Styles>
                                        <!-- Dark mode -->
                                        <Styles>
                                            <WordsStyle name="DEFAULT" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="LINE COMMENTS" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="NUMBERS" fgColor="0080FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="KEYWORDS1" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="KEYWORDS2" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="KEYWORDS3" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS4" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="KEYWORDS5" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="KEYWORDS6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS7" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="KEYWORDS8" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="OPERATORS" fgColor="8080FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
                                            <WordsStyle name="FOLDER IN CODE1" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="FOLDER IN CODE2" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="FOLDER IN COMMENT" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="DELIMITERS1" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
                                            <WordsStyle name="DELIMITERS2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                            <WordsStyle name="DELIMITERS3" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS4" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="65600" />
                                            <WordsStyle name="DELIMITERS5" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="32800" />
                                            <WordsStyle name="DELIMITERS6" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS7" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="3" nesting="0" />
                                            <WordsStyle name="DELIMITERS8" fgColor="333333" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
                                        </Styles>
                                    </UserLang>
                                </NotepadPlus>
                                

                                • Thus, the problem came down to the simple question : how to comment out all the Light Mode section, in one go ? As usual, regular expressions are the solution !

                                • Open or switch to the markdown._new.udl.xml file

                                • Open the Replace dialog ( Ctrl + H )

                                (?xs-i)  ^  [\t\x20]*  <!--[ ]Light[ ]mode[ ]-->  \R  \K  [\t\x20]*  <Styles>  \R  .+?  ^  [\t\x20]*  </Styles>  \R  #  ( Search )
                                
                                (        )<!--\r\n$0(        )-->\r\n
                                
                                • Untick all box options

                                • Tick the Wrap around option

                                • Select the Regular expression search mode

                                • Click once on the Replace All button ( Do not use the Replace button ! )

                                • Close the Replace dialog ( Esc )

                                • Save the new contents, relative to the Dark mode

                                • After stopping and re-starting Notepad++, I did verify that this new UDL was functional and identical to the Mardown (Preinstalled) UDL

                                => From now on, all the light mode section is commented out between two lines <!-- and -->

                                So, you just have to modify the fgcolor and bgcolor attibutes of the Dark mode section, as you like ;-))


                                Notes :

                                • The search regex uses the free-spacing mode (?x) to better identify the main parts of the search regex

                                • When the (?x) modifier is used, the search regex may lie on one or several lines

                                For instance, my previous single-line regex :

                                (?xs-i)  ^  [\t\x20]*  <!--[ ]Light[ ]mode[ ]-->  \R  \K  [\t\x20]*  <Styles>  \R  .+?  ^  [\t\x20]*  </Styles>  \R  #  ( Search )
                                

                                Could also be expressed as :

                                (?xs-i)                        #  FREE-SPACING (x) , SINGLE-LINE (s) , SENSIBLE to CASE (-i)  ( 'in-line' modifiers )
                                ^  [\t\x20]*                   #  ANY range of leading SPACE or TABULATION characters, possibly NULL, at BEGINNING of CURRENT line
                                <!--[ ]Light[ ]mode[ ]-->  \R  #  String '<!-- Light mode -->' with that EXACT case and the LINE-BREAK chars  ( \R )
                                \K                             #  Resets any MATCHED text, so far and resets the REGEX ENGINE position to 0
                                [\t\x20]*                      #  ANY range of leading SPACE or TABULATION characters, possibly NULL, at BEGINNING of CURRENT line
                                <Styles>  \R                   #  String '<Styles>' with that EXACT case and the LINE-BREAK chars ( \R )
                                .+?                            #  The SHORTEST NON-NULL range of ANY char ( standard or EOL ) till...
                                ^  [\t\x20]*                   #  ANY range of leading SPACE or TABULATION characters, possibly NULL, at BEGINNING of CURRENT line
                                </Styles>  \R                  #  String '</Styles>' with that EXACT case and the LINE-BREAK chars ( \R )
                                
                                • In this mode, space and line-break chars are never part of the regex AND anything after a first # character is a comment. Thus :

                                  • Any space character, part of the regex, must be changed as [ ] or \x20 or preceded with an anti-slash \

                                  • Any # character, part of the regex, must be changed as [#] or \x23 or preceded with an anti-slash \

                                • Note that the appropriate replacement regex cannot benefit from the (?x) mode. So all its text is necessarily linked in one (possibly long ) line

                                (        )<!--\r\n$0(        )-->\r\n
                                

                                Best Regards

                                guy038

                                José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 0
                                • José Luis Montero CastellanosJ
                                  José Luis Montero Castellanos @guy038
                                  last edited by José Luis Montero Castellanos

                                  @guy038
                                  Good morning - Thanks for your kind reply:

                                  I forgot to mention that the RegEx that I made, not only deactivates one section while activating the other, and vice versa, that is, it alternates (toggles) between the two modes or serves as a “selector” that is why the ?1 as a conditional selector which means that if capturing group 1 matches the first part of the toggle is replaced, if not then the second.

                                  ?ℕYesPattern:NoPattern (from the user manual).

                                  It all boils down to changing the tags positions (part of them) <Style>, </Style>,<Xtyle>, </Xtyle> (the spaces in the previous tags are effect of the ` character).

                                  Regarding your suggestions, I haven’t tried it yet, but I’m about to do it. The first thing to see in detail each expression and understand its purpose. It seems elegant and obviously more understandable (digestible) especially with the use of (?x). (Don’t forget I’m new to Npp and its RegEX engine.) Although I already knew something about RegEx.

                                  As soon as I have tested the functionality, and deduced that it can be useful to me, I will tell you.

                                  Have a good day :)

                                  1 Reply Last reply Reply Quote 0
                                  • José Luis Montero CastellanosJ
                                    José Luis Montero Castellanos @Lycan Thrope
                                    last edited by José Luis Montero Castellanos

                                    @Lycan-Thrope
                                    Hello:
                                    The idea is that if I’m going to use Npp, it’s natural that I want to take advantage of its resources without resorting to a new learning curve. That’s why the natural option seemed to me to be the Npp macros.

                                    With respect to

                                    So let’s not make it worse by making more assumptions
                                    

                                    I like that smile :), with which the comment ends, And the comment itself, I subscribe.

                                    Have a a Good Day and success.

                                    Lycan ThropeL 1 Reply Last reply Reply Quote 0
                                    • Lycan ThropeL
                                      Lycan Thrope @José Luis Montero Castellanos
                                      last edited by Lycan Thrope

                                      @José-Luis-Montero-Castellanos ,

                                      I suggested the Python option because I’m not quite sure changing the files contents would be able to effectively be changed and reloaded simply by using the regex, because essentially the file has to be saved, I believe, to be implemented, but after thinking about it, I remember that changing the User Defined Language keyword and stylers would interactively change them in real time, so in hindsight, you might be on to something.

                                      The Python option was suggested because even though I’m not good at it, it seems that the stuff that @Alan-Kilborn has posted that I’ve seen goes to the heart of using the Scintilla directly via NPP, so the changes would be able to be changed real time, is what I was figuring…so I may have been wrong to suggest that in light of the possiblity you point out. I’m not that involved in the actual code that runs NPP, so I’m more of a user seeking more advanced abilities of my language without needing to learn to code NPP itself…and Python plugin was the closest thing I cold think of short of actual NPP coding that might be able to accomplish the task you had in mind.

                                      So in closing, good luck with your experimentation. I hope it proves usable as I’d like to not have to do the multiple steps to change from Light mode to Dark Mode as well. I just didn’t want to see the different lanuages we speak, become a problem in our communications. :-)

                                      José Luis Montero CastellanosJ 2 Replies Last reply Reply Quote 0
                                      • José Luis Montero CastellanosJ
                                        José Luis Montero Castellanos @Lycan Thrope
                                        last edited by

                                        This post is deleted!
                                        1 Reply Last reply Reply Quote 1
                                        • José Luis Montero CastellanosJ
                                          José Luis Montero Castellanos @Lycan Thrope
                                          last edited by José Luis Montero Castellanos

                                          @Lycan-Thrope
                                          Greetings:

                                          I edited this post, (deleting the previous one, since the editing time had passed.) highlighting the parts that were changed or added that could be misinterpreted…

                                          just didn’t want to see the different lanuages we speak, become a problem in our communications. :-)

                                          By the way, my Qtranslator works great, I’m a Spanish speaker (greetings from Colombia, remember?). But that if I were to blame the translator it would be dishonest on my side, and of low esteem on my part, because I too have much to complain about and point out, but I reserve that for the efficient running of the forum. Wasn’t what seemed offensive really a mockery of myself? (3 or 4 times in this thread) (a good preventative habit against hubris!).

                                          About python, well I have no choice, and your suggestion is very appropriate, I think @PeterJones also mentioned it. I’ll give it a try. Or I could program it in some language that I know.

                                          Well, opening a file and changing four words is not a “feat” that requires a lot of code. :)

                                          Closing! - Have a good evening…

                                          Lycan ThropeL 1 Reply Last reply Reply Quote 2
                                          • Lycan ThropeL
                                            Lycan Thrope @José Luis Montero Castellanos
                                            last edited by Lycan Thrope

                                            @José-Luis-Montero-Castellanos ,

                                            I understood what you meant, without needing to delete, especially once I realized that you weren’t speaking as if with broken english , but rather because you ARE using a translator, which are not as good at translating your language using the nuances an english speaking person is used to. I realize, with the few languages I have some familiarity with, that most foreign (to English speakers) languages don’t have the same directness or ability for description that English allows speakers, so even though your tranlator seems to be working good from your end…it has a few failings on our end…and at first, I wasn’t sure if it was your personal lack of a wider understanding of English, or if you were using a translator, which can’t compare to the language usage. :)

                                            Now that we know the issue, we at least can understand now, that it wasn’t your statements, but that of a translator’s inability to properly relay your meaning. :)

                                            José Luis Montero CastellanosJ 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors