MacroInspect which comments macros
-
@Alan-Kilborn Glad it worked well for you.
I rushed this release as I had not done a gist before so thought I’d give it a try and so here it is as an early release. So good to hear no hiccups yet from the script as 1/1 is perfect score so far. :)
The json files should be good for several Notepad++ versions until a header file gets updated. Downloading them each use will slow down the run of the script. The header files are temporary to create the json files so the header files can be deleted and if an update to the script is done, I may add the code in to delete the header files asap. I just want to know it works for everyone before getting rid of the evidence that might help to solve any bugs.
The
IDC_FRCOMMAND_BOOLEANSlParam value could be bit down into it’s settings which is the checkbox states … I never got that far yet and may consider it.I had not seen or heard of your macro disassembler before now. Quite similar approach with commenting the file. I have considered a Gui as a alternative recorder though I consider it would be a very involving task to do so doubt I will do that. So, commenting the file is probably the best option IMO.
I notice mention of
SCI_PASTEwith\rvalue in your link. I’m not sure if running the macro would know how to handle that as paste where at which point. Doesn’t matter to me at the moment as may figure it out later.If you may notice in the code, I do not handle
sParamso the code happily ignores it.sParamcan be multi-line so off-limits sounds good to me. -
@mpheath said in MacroInspect which comments macros:
The json files should be good for several Notepad++ versions until a header file gets updated. Downloading them each use will slow down the run of the script.
I’d have been more apt to leave them if the code had created a subdir and put them in that.
As is, I don’t like misc files sitting in the root of my config dir. -
Hello, @mpheath, @alan-kilborn and All,
I do not wish to minimize your approaches and works, on this matter, but I’m wondering :
Wouldn’t it be better to simply add a
commentattribute to any section of theshortcuts.xmlfile ?Perhaps, I’m not seeing all the implications or drawbacks of this possible improvement !
BR
guy038
-
@guy038 said in MacroInspect which comments macros:
drawbacks of this possible improvement
The next time that N++ itself needs to update
shortcuts.xml, say goodbye to the comments. -
Hi, @mpheath, @alan-kilborn and All,
Well, I meant something like this :
<Action type="0" message 2170" wParam="0" lParam="0", sParam="" comments="Scintilla Message SCI_COPY" /> <Action type="2" message="0" wParam="41001" lParam="0" sParam="" comments="Menu command FILE_NEW" />Best Regards,
guy038
-
@guy038 said in MacroInspect which comments macros:
Well, I meant something like this :
Unfortunately, that still won’t work: Manually create that macro with the
commentsattributes, then restart: thecommentsattributes are still there, because Notepad++ hasn’t tried to write that file yet; then use Macro > Modify Shortcut/Delete Macro to change the shortcut for any macro (even a different macro), exit Notepad++, and restart: thecommentsattributes are gone, because Notepad++ re-wrote the file during the exit.When Notepad++ needs to write out
shortcuts.xml– which it needs to do if you use the GUI to change something in Shortcut Mapper, or record or delete a Macro, or add a new Run menu command – then it will only include the attributes that Notepad++ tracks, so thecommentsattribute will go away; since Notepad++ doesn’t track<!-- ... -->comments either, those will also go away.This is why, if I want a permanent comment, I either use the
sParamattribute to hold a command that doesn’t use thesParamvalue, or I add dummy commands using the SCI_NULL command usingtype="0"message="2172"`, as in:<Action type="0" message="2172" wParam="0" lParam="0" sParam="This Comment Will Be Kept" /> -
Hello, @mpheath, @alan-kilborn, @peterjones and All,
Peter, I still don’t understand ! Of course, without some modifications in N++ code, this method would obviously not work !
But, if the structure of the
Shortcuts.xmlfile is globally modified in order to include an emptycommentsattribute, by default, I do not see why this new behavior wouldn’t work !I also understand that, if a macro would be deleted, from the
Shortcut Mapper, every part of this specific macro would be deleted, including the comments !BR
guy038
-
@guy038 ,
Sorry, I did not realize you were suggesting modifying Notepad++ to be able to allow a
comment="..."attribute. That’s something completely different.My comments about Shortcut Mapper were not trying to say that you should delete the macro under investigation for the experiment; my comments were that, for all existing versions of Notepad++, if you change the keyboard shortcut for any macro (or if you record a new macro, or add a new Run menu command, or change the keyboard shortcut for any menu entry), then when the current version of Notepad++ writes the file, it will write it without
<!-- comments -->and withoutcomments="pseudocomment"attributes included, thus erasing it. I was talking about existing behavior.For a feature request: I doubt Don would be interested in allowing the new attribute, because it’s not something that the Macro Recorder will use, and probably not something that even most people manually editing macros would use; he doesn’t often add (or allow others to add) features that would just help the select few power-users.
And without a feature request, my workaround examples of using
sParam– either on actions that just leave itsParam="", or on the SCI_NULL action – seems a good workaround for power users who want to document their macros under existing conditions. -
This post is deleted! -
Hello, @mpheath, @alan-kilborn, @peterjones and All,
Note that, if this new attribute would exist, then, using the @mpheath’s solution or any other one, it could be possible to fill in all the
commentszones automatically, when N++ exits and theshortcuts.xmlfile is saved !On restarting N++, the display of the
shortcuts.xmlfile would produce good pieces of information, in the user language !However, this would probably need a lot of coding for, I must admit, a little benefice !
Best Regards,
guy038
-
To All, I have updated the gist with revision 2.
Minor changes. The header files will be removed if json files are created or already exist.
@Alan-Kilborn said in MacroInspect which comments macros:
I’d have been more apt to leave them if the code had created a subdir and put them in that.
As is, I don’t like misc files sitting in the root of my config dir.Agree. It could get very messy if scripts follow the trend including this script.
The name of this subdir could be
Config\MacroInspectthough I consider that as starting an ugly trend. Perhaps within theConfig\PythonScript\scripts\MacroInspectthough still the files are not scripts as they are data files.Perhaps a central subdir like
Config\Tempand temporary data files go there. So a user can clean that directory periodically and the scripts can remake the data files from latest version content as needed. To save name collisions could possibly prefix the files with script name likeMacroInspect-Type0.jsonfor example. If a script does not remake the data files then this temp directory would not be good to use and so may need a subdir likeConfig\Staticfor example.The concept may need some confirmation before I modify the script to alter where the data files go else the script may make a mess with obsolete data files in the
Configdirectory. -
When I write a script that needs a permanent data file, I put the data file in the same folder as the script with a common prefix on the name. An example probably helps:
Script:
...\plugins\Config\PythonScript\scripts\fubar.py
Data:...\plugins\Config\PythonScript\scripts\fubar_data.jsonIt’s not too messy; locate the script (e.g. Windows Explorer) and the data file is visually adjacent to it.
If I need more than one data file (i.e., your situation), I give everything its own folder:
Folder:
...\plugins\Config\PythonScript\scripts\foo\
Script:...\plugins\Config\PythonScript\scripts\foo\foo.py
Data1:...\plugins\Config\PythonScript\scripts\foo\foo_data1.json
Data2:...\plugins\Config\PythonScript\scripts\foo\foo_data2.txtIn this case it isn’t terribly important to name the data files with the common prefix…
YMMV. I’m sure you’ll decide on a workable solution.
-
To All, I have updated the gist with revision 3.
Implemented the @Alan-Kilborn idea of single json file saved next to the script.
Please manually remove existing data files from the Config directory:
FindReplaceDlg_rc.h FindReplaceDlg_rc.h.json Scintilla.h Scintilla.h.jsonUpdate
MacroInspect.pyin theConfig\PythonScript\scriptsdirectory. On first run should download the header data and save toConfig\PythonScript\scripts\MacroInspect_data.json. No temporary header files as the data will all be processed in memory.Improved message
1701comment which isIDC_FRCOMMAND_EXECwill now show it’slParamrelated constant.
Some examples:<!-- IDC_FRCOMMAND_EXEC [IDCMARKALL] --> <!-- IDC_FRCOMMAND_EXEC [IDD_FINDINFILES_FIND_BUTTON] --> <!-- IDC_FRCOMMAND_EXEC [IDD_FINDINFILES_FINDINPROJECTS] --> -
I ran revision 3 and it seemed to go as desired.
Afterward I looked for the
MacroInspect_data.jsonfile and curiously I did not find it anywhere on my system.After changing the code to add
print('json_file:', json_file)I then saw the problem.
I use a script to “run the script in the active tab” so that I can tie it to a keycombo for quickly executing a script under development, over and over again as development proceeds. I think I would go mad if I had to navigate the menus to repeatedly run a script I’m actively working on. (Yes, there are other alternatives…)Anyway, I found that the data file for your script was being created for me as
RunCurrentPyFileAsPythonscript_data.jsonbecause my “script runner” script is namedRunCurrentPyFileAsPythonscript.py. This results (apparently) from the use of__file__in your code.No big deal, I can compensate for this… :-)
Again, great job on a great script.
-
Sorry to hear. It’s still a bug even if it is a script running a script. I just tested
sys.argvand thought argument 0 might be OK though it returns['C:\\Programs\\Notepad++\\notepad++.exe']. If you can test something that works for you and everyone else then please share. I may test some alternatives though I am not sure if I can reproduce your environment to be sure of a fix. -
In general, a way I’ve found to do it is:
inspect.getframeinfo(inspect.currentframe()).filenameafter importing
inspect, and then getting the directory part of the path from that.This worked great in PythonScript2, as the path to the file was returned from the inspect call. In PythonScript3, however, all that call obtains is a filename without the complete path.
You can experiment with that if you like, or I’ll post some more complete code later.
-
Just tested in a Python interpreter.
__file__can be set to a value. So perhaps yourRunCurrentPyFileAsPythonscript.pycan set__file__to the absolute path of the child script before it runs the subprocess, so then the child process use of__file__is inherited like as if it is the main process. -
@mpheath said:
perhaps your RunCurrentPyFileAsPythonscript.py can set file to the absolute path of the child script before it runs …
A good idea, however it doesn’t work (I still get the calling script’s name/path), at least the way I’m having a script run a script; there are many ways to do it. It’s actually surprisingly difficult to have a script run a script (and have things all turn out like you’d like).
LATER EDIT:
Actually, it did work; what caused it to not work the first time I tried it was programmer error, i.e., me!
I may have to look further into using the__file__variable technique instead of myinspect-based technique, as it seems like it could simplify things under Python3. -
I see you didn’t break down the search “boolean” values in your latest script, so, I took the liberty of pulling that code from my now defunct macro disassembler and inserting it into your script:
elif message == 'IDC_FRCOMMAND_BOOLEANS': numeric_data = int(v) bit_weights_numeric_value_to_str_dict = { 1 : 'MATCH_WHOLE_WORD_ONLY', 2 : 'MATCH_CASE', 4 : 'PURGE_MARKS_BEFORE_NEW_SEARCH', 16 : 'BOOKMARK_LINE', 32 : 'IN_SUBFOLDERS', 64 : 'IN_HIDDEN_FOLDERS', 128 : 'IN_SELECTION__OR__PROJECT1', 256 : 'WRAP_AROUND__OR__PROJECT2', 512 : 'FORWARD_DIRECTION__OR__PROJECT3', 1024 : 'DOT_MATCHES_NEWLINE_FOR_REGEX', } running_single_bitweight = 1 search_options_str_list = [] while numeric_data != 0: if running_single_bitweight in bit_weights_numeric_value_to_str_dict: if (numeric_data & running_single_bitweight) != 0: search_options_str_list.append(bit_weights_numeric_value_to_str_dict[running_single_bitweight]) numeric_data &= ~running_single_bitweight running_single_bitweight <<= 1 value_str = 'NONE' if len(search_options_str_list) == 0 else ' / '.join(search_options_str_list) comment += ' [ ' + value_str + ' ]' -
I have already tested
IDC_FRCOMMAND_BOOLEANSand 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] = vwhich 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
lParamsvalue 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_CHECKandIDF_FINDINFILES_PROJECT3_CHECKin the comments even though they are unchecked and disabled so cannot be valid in the xml comments.