• Login
Community
  • Login

MacroInspect which comments macros

Scheduled Pinned Locked Moved General Discussion
36 Posts 4 Posters 1.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.
  • M
    mpheath @Alan Kilborn
    last edited by mpheath Jan 5, 2025, 10:17 PM Jan 5, 2025, 9:43 PM

    @Alan-Kilborn

    I have already tested IDC_FRCOMMAND_BOOLEANS and ran into issues. If you look at the json data file, you may see lines like:

            "128": "IDF_IN_SELECTION_CHECK IDF_FINDINFILES_PROJECT1_CHECK",
            "256": "IDF_WRAP IDF_FINDINFILES_PROJECT2_CHECK",
            "512": "IDF_WHICH_DIRECTION IDF_FINDINFILES_PROJECT3_CHECK",
    

    which has space delimited pairs of constant names.

    as I use this code to fill the dictionary with the constant pairs:

                    if k in dic:
                        dic[k] += ' ' + v
                    else:
                        dic[k] = v
    

    which are pairs that share the same boolean value in which only 1 can be correct. Though in testing depending on the FindReplaceDLG tab recorded, sometimes none are correct IMO. I am unsure if I can fix the code I have to make it reliable as some incorrect comments may make the user puzzled. I suspect that perhaps some bit flags should not be in the lParams value and perhaps the playback ignores them, though that does not help with making the xml comments.


    Edit:

    There is also a possibility that Notepad++ is getting the checkbox booleans incorrect. Unchecked/checked is ok until disabling the checkbox, which leads to a 3rd state with a enabled/disabled needing to be validated. IDK yet and so may need investigation. This may explain why I get IDF_FINDINFILES_PROJECT2_CHECK and IDF_FINDINFILES_PROJECT3_CHECK in the comments even though they are unchecked and disabled so cannot be valid in the xml comments.

    A 1 Reply Last reply Jan 5, 2025, 10:41 PM Reply Quote 0
    • A
      Alan Kilborn @mpheath
      last edited by Alan Kilborn Jan 5, 2025, 10:43 PM Jan 5, 2025, 10:41 PM

      @mpheath said in MacroInspect which comments macros:

      I have already tested IDC_FRCOMMAND_BOOLEANS and ran into issues.

      I don’t know…but I’m fairly certain the code I posted works correctly.

      which are pairs that share the same boolean value in which only 1 can be correct.

      Yep, the “genius” that implemented the project options decided repurposing some bit weighting for that was a great idea.

      I suspect that perhaps some bit flags should not be in the lParams value and perhaps the playback ignores them

      Yes, there can be items that are not applicable in there.
      If one knew in advance what the 1701 value was going to be, one could filter out the n/a items, but alas the 1702 message comes before the 1701.

      M 1 Reply Last reply Jan 10, 2025, 12:09 AM Reply Quote 0
      • M
        mpheath @Alan Kilborn
        last edited by Jan 10, 2025, 12:09 AM

        To All, I have updated the gist with revision 4.

        • Added feature for IDC_FRCOMMAND_BOOLEANS comment to display the options as the related boolean constants.
        • Added code to only comment Actions that a not in a multi-line comment block which is quite basic code just intended for the existing comments distributed in shortcuts.xml.

        This script might be complete unless I have missed something.


        @Alan-Kilborn Thanks for sharing the IDC_FRCOMMAND_BOOLEANS code that you use. I went with what I had and decided to keep the code basic and not go deeper into it as the IDC_FRCOMMAND_EXEC actions are many. Two passes of the shortcuts.xml could be done to get the IDC_FRCOMMAND_EXEC actions on the first pass and use a blacklist on the second pass though is it better to try simple IMO before trying complex and probably end up with much uglier code. And as you mention earlier with the idea of a PythonScript example script which IMO should be simple to understand.

        @guy038 I’m not a fan of using attributes as comments though this script may help to get the information quicker which from my point of view was the main goal.

        @PeterJones Thanks for the lesson of why attributes as comments are used. I was not aware of the exact reason before this topic started.

        A 1 Reply Last reply Jan 10, 2025, 11:01 AM Reply Quote 4
        • A
          Alan Kilborn @mpheath
          last edited by Jan 10, 2025, 11:01 AM

          @mpheath

          Getting better all the time…

          One minor thing I noticed that I thought a bit odd was that the output file tab had LF line endings rather than the more traditional CRLF, but this is hardly important.

          A “second pass” might be worth it for the “booleans”, because you could (a) be more specific about them (e.g. is it “in selection” or is it “project 1”?), and (b) you could filter out or flag irrelevant options (e.g. “search direction” is meaningless for a file-level search operation, but it can be encoded in the booleans).

          M 1 Reply Last reply Jan 10, 2025, 11:27 AM Reply Quote 1
          • M
            mpheath @Alan Kilborn
            last edited by Jan 10, 2025, 11:27 AM

            OK, bug squashing time. Just committed revision 5 though let’s works towards revision 6.

            @Alan-Kilborn said in MacroInspect which comments macros:

            One minor thing I noticed that I thought a bit odd was that the output file tab had LF line endings rather than the more traditional CRLF, but this is hardly important.

            Python normalizes \n to the newline sequence though may need to set the new tab to use CRLF.

            A “second pass” might be worth it for the “booleans”, because you could (a) be more specific about them (e.g. is it “in selection” or is it “project 1”?), and (b) you could filter out or flag irrelevant options (e.g. “search direction” is meaningless for a file-level search operation, but it can be encoded in the booleans).

            a) There is no 1or2 AFAIK. This is the purpose of find_in_files_mode which is the boolean flag to select which one of the pairs of constants to display. It determines this based on a previous action containing FINDINFILES. Perhaps you have a macro that shows where this selection fails?

            b) It is a odd constant I agree. IDF_WHICH_DIRECTION is forward direction though not displayed if backwards if I have that correct. Seems poorly named and knowing if backwards seems more important.

            A 1 Reply Last reply Jan 10, 2025, 11:49 AM Reply Quote 0
            • A
              Alan Kilborn @mpheath
              last edited by Alan Kilborn Jan 10, 2025, 11:50 AM Jan 10, 2025, 11:49 AM

              @mpheath said:

              Python normalizes \n to the newline sequence

              Assuming you mean “Python normalizes \n to \r\n on Windows”, yes, this is true but only when writing to a file, which your code is not doing (you are writing to an untitled tab, e.g. new 2).


              Perhaps you have a macro that shows where this selection fails?

              OK.
              I saw this:

                          <!-- IDC_FRCOMMAND_BOOLEANS  [IDF_MATCHCASE, IDF_FINDINFILES_RECURSIVE_CHECK, IDF_FINDINFILES_PROJECT3_CHECK] -->
                          <Action type="3" message="1702" wParam="0" lParam="546" sParam="" />
                          <!-- IDC_FRCOMMAND_EXEC  [IDD_FINDINFILES_FIND_BUTTON] -->
                          <Action type="3" message="1701" wParam="0" lParam="1656" sParam="" />
              

              and I saw PROJECT3 in it, and that is irrelevant to a FINDINFILES. But really, I think it is just a boolean (for “direction”) that doesn’t affect the search but got in there as part of the “loose” N++ code handling the booleans when a macro is recorded. Maybe it is another good reason to filter it out or flag it somehow – so dumb users like me don’t think it is relevant. Again, not sure how much further you want to take your script.

              Maybe helpful as a reference, here’s what I had in my old “disassembler” code as to what options are relevant to what search actions:
              27658e44-9c7f-4dfb-ba0e-d6dac0a9d04a-image.png
              I think you can figure out that “ww” is whole-word and “mc” is match-case. “pp” had me confused for a moment, but I think it is presearch-purge.


              Maybe a N++ issue should be raised that sometimes irrelevant search options are being recorded into the booleans? What do you think?

              M 2 Replies Last reply Jan 10, 2025, 1:18 PM Reply Quote 1
              • M
                mpheath @Alan Kilborn
                last edited by Jan 10, 2025, 1:18 PM

                @Alan-Kilborn said in MacroInspect which comments macros:

                Assuming you mean “Python normalizes \n to \r\n on Windows”, yes, this is true but only when writing to a file, which your code is not doing (you are writing to an untitled tab, e.g. new 2).

                Reading and write to files, Python does normalize though the editor methods do not so may need to harmonize EOLs which I may have solved locally and can post a revised update. shortcuts.xml can be read from editor and read from file so both need to be \r\n literally so editor.addText() adds \r\n literally.

                … and I saw PROJECT3 in it, and that is irrelevant to a FINDINFILES. But really, I think it is just a boolean (for “direction”) that doesn’t affect the search but got in there as part of the “loose” N++ code handling the booleans when a macro is recorded. Maybe it is another good reason to filter it out or flag it somehow – so dumb users like me don’t think it is relevant. Again, not sure how much further you want to take your script.

                Ah, the extra constants that perhaps should not be there in the comments as I mentioned earlier. How far? not more than what is needed is what I hope for.

                Maybe helpful as a reference, here’s what I had in my old “disassembler” code as to what options are relevant to what search actions:

                An interesting table, this might be useful for filtering with a blacklist. Certainly a great effort into making the table. Well done.

                Maybe a N++ issue should be raised that sometimes irrelevant search options are being recorded into the booleans? What do you think?

                I consider good to fix the problem at the source. Ideally, the script should just do as is done already without doing excessive filtering. It tires me just to think of having to do more when it should not be needed if the booleans were concise and correct … or perhaps I am not so young anymore.

                Will see what can be done with the script within reason. I like doing things based on interest though sometimes it can feel like torture and the filtering implementation reminds me of the latter.

                A M 2 Replies Last reply Jan 10, 2025, 1:24 PM Reply Quote 0
                • A
                  Alan Kilborn @mpheath
                  last edited by Jan 10, 2025, 1:24 PM

                  Maybe a N++ issue should be raised that sometimes irrelevant search options are being recorded into the booleans? What do you think?

                  I consider good to fix the problem at the source. Ideally, the script should just do as is done already without doing excessive filtering. It tires me just to think of having to do more when it should not be needed if the booleans were concise and correct … or perhaps I am not so young anymore.

                  I will follow-up and put an issue in on this.

                  A 1 Reply Last reply Jan 10, 2025, 7:06 PM Reply Quote 0
                  • M
                    mpheath @mpheath
                    last edited by Jan 10, 2025, 2:42 PM

                    To All, I have updated the gist with revision 6.

                    Revision 5:

                    • Fixed root path for portable and installed.

                    Revision 6:

                    • Fixed EOL to be CRLF.
                    1 Reply Last reply Reply Quote 1
                    • A
                      Alan Kilborn @Alan Kilborn
                      last edited by Jan 10, 2025, 7:06 PM

                      @Alan-Kilborn said:

                      I will follow-up and put an issue in on this.

                      Issue is CREATED .

                      1 Reply Last reply Reply Quote 1
                      • M
                        mpheath @Alan Kilborn
                        last edited by Jan 10, 2025, 10:41 PM

                        @Alan-Kilborn This table is a whitelist or a blacklist? If a whitelist then perhaps could replace the range() with predefined flags in a list like is in your table. Could you paste the table as text in a codebox so it can be copied as text? Then will try 2 pass reading to get the 16** numbers to know which list of booleans to bitwise and append to the comment. Just need to test this concept and it may work more to users satisfaction.

                        1 Reply Last reply Reply Quote 0
                        • A
                          Alan Kilborn
                          last edited by Alan Kilborn Jan 11, 2025, 1:33 AM Jan 11, 2025, 1:30 AM

                                  'numeric_value_to_relevant_options' : {
                                  #          ww  mc  pp  bm   sub  hid  sel   wrp   bwd   dot
                                      1    : 1 | 2 |                          256 | 512 | 1024,             # find_next
                                      1608 : 1 | 2 |                          256 | 512 | 1024,             # replace
                                      1609 : 1 | 2 |                    128 | 256 | 512 | 1024,             # replace_all
                                      1614 : 1 | 2 |                    128 | 256 | 512 | 1024,             # count
                                      1615 : 1 | 2 | 4 | 16 |           128 | 256 | 512 | 1024,             # mark
                                      1633 :             16 |           128 | 256 | 512       ,             # clear_marking
                                      1635 : 1 | 2 |                                      1024,             # replace_in_open_tabs
                                      1636 : 1 | 2 |                                      1024,             # find_in_open_tabs
                                      1641 : 1 | 2 |                                      1024,             # find_in_active_tab
                                      1656 : 1 | 2 |          32 | 64 |                   1024,             # find_in_files
                                      1660 : 1 | 2 |          32 | 64 |                   1024,             # replace_in_files
                                  #                                     prj1  prj2  prj3
                                      1665 : 1 | 2 |                    128 | 256 | 512 | 1024,             # replace_in_projects
                                      1666 : 1 | 2 |                    128 | 256 | 512 | 1024,             # find_in_projects
                                  },
                          

                          I’d use the 1701 msg’s numeric data as the key to looking into this dict to get a relevant_options_val. Then I’d take the previous 1702 msg’s numeric data and AND it with ~relevant_options_val to calculate unneeded_options.

                          M 1 Reply Last reply Jan 11, 2025, 6:04 AM Reply Quote 2
                          • M
                            mpheath @Alan Kilborn
                            last edited by Jan 11, 2025, 6:04 AM

                            To All, I have updated the gist with revision 7.

                            • Added dictionary provided by @Alan-Kilborn to improve IDC_FRCOMMAND_BOOLEANS processing with valid boolean lists.

                            Let me know of issues.

                            1 Reply Last reply Reply Quote 1
                            • A
                              Alan Kilborn
                              last edited by Alan Kilborn Jan 11, 2025, 11:23 AM Jan 11, 2025, 11:20 AM

                              Such a minor quibble it isn’t worth mentioning, but if you end up doing any more changes maybe throw in a change that would remove all &amp; strings from the comment?, e.g.:

                                          <!-- &amp;Save -->
                                          <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
                              

                              And, I know it messes with the “purity” of the algorithm, but consider changing:

                                          <!-- IDC_FRCOMMAND_BOOLEANS  [IDF_WHICH_DIRECTION] -->
                                          <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
                              

                              to something like:

                                          <!-- IDC_FRCOMMAND_BOOLEANS  [forward_direction] -->
                                          <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
                              
                              M 1 Reply Last reply Jan 12, 2025, 11:18 PM Reply Quote 1
                              • M
                                mpheath @Alan Kilborn
                                last edited by Jan 12, 2025, 11:18 PM

                                To All, I have updated the gist with revision 8.

                                • Replace constant IDF_WHICH_DIRECTION with alternative IDF_FORWARD_DIRECTION to make it more meaningful with the action.
                                • Use html.unescape() on type2 values to resolve entities. Example &amp; will change to &.

                                @Alan-Kilborn OK, XML comments do not require escapes with entities. -- can be a problem with XML comments so will be reduced to single - if exist.

                                Replacing IDF_WHICH_DIRECTION is OK so as to avoid user confusion with which direction. The json will inherit the change so the file needs to be removed to get the alternative value of IDF_FORWARD_DIRECTION. Or, just edit the values in the json file to your liking.

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