From 891f2ed682f0a8886f776c184409d754c8d5868a Mon Sep 17 00:00:00 2001 From: dinkumoil Date: Mon, 14 Nov 2022 18:30:36 +0100 Subject: [PATCH] Add function list parser for NppExec plugin's scripting language Fix #12517, close #12519 --- .../Test/FunctionList/udl-NppExec/unitTest | 194 ++++++++++++++++++ .../udl-NppExec/unitTest.expected.result | 1 + .../installer/filesForTesting/overrideMap.xml | 1 + .../installer/functionList/nppexec.xml | 61 ++++++ .../installer/functionList/overrideMap.xml | 1 + 5 files changed, 258 insertions(+) create mode 100644 PowerEditor/Test/FunctionList/udl-NppExec/unitTest create mode 100644 PowerEditor/Test/FunctionList/udl-NppExec/unitTest.expected.result create mode 100644 PowerEditor/installer/functionList/nppexec.xml diff --git a/PowerEditor/Test/FunctionList/udl-NppExec/unitTest b/PowerEditor/Test/FunctionList/udl-NppExec/unitTest new file mode 100644 index 000000000..15b1862aa --- /dev/null +++ b/PowerEditor/Test/FunctionList/udl-NppExec/unitTest @@ -0,0 +1,194 @@ +::StartupScript +npp_console keep + +npp_exec "SetSingleEdgeLine" + + + +::MultipleSelectAddNext +npp_console keep + +sci_sendmsg SCI_SETSEARCHFLAGS SCFIND_WHOLEWORD +sci_sendmsg SCI_TARGETWHOLEDOCUMENT +sci_sendmsg SCI_MULTIPLESELECTADDNEXT + + + +::MultipleSelectAddEach +npp_console keep + +sci_sendmsg SCI_SETSEARCHFLAGS SCFIND_WHOLEWORD +sci_sendmsg SCI_TARGETWHOLEDOCUMENT + +sci_sendmsg SCI_GETSELECTIONEMPTY + +if $(MSG_RESULT) == 1 then + sci_sendmsg SCI_MULTIPLESELECTADDNEXT +endif + +sci_sendmsg SCI_MULTIPLESELECTADDEACH + + + +::SetSingleEdgeLine +npp_console keep +sci_sendmsg SCI_SETEDGECOLUMN 80 +sci_sendmsg SCI_SETEDGEMODE EDGE_LINE + + + +::ConfigSingleEdgeLine +npp_console keep +sci_sendmsg SCI_GETEDGECOLUMN +inputbox "Input edge column" : "Edge column" : $(MSG_RESULT) +sci_sendmsg SCI_SETEDGECOLUMN $(INPUT) +sci_sendmsg SCI_SETEDGEMODE EDGE_LINE + + + +::SingleEdgeLineOn +npp_console keep +sci_sendmsg SCI_SETEDGEMODE EDGE_LINE + + + +::MultipleEdgeLinesOn +npp_console keep +sci_sendmsg SCI_SETEDGEMODE EDGE_MULTILINE + + + +::BackgroundEdgeOn +npp_console keep +sci_sendmsg SCI_SETEDGEMODE EDGE_BACKGROUND + + + +::EdgesOff +npp_console keep +sci_sendmsg SCI_SETEDGEMODE EDGE_NONE + + + +::WrapSelectedLinesAtEdge +npp_console keep + +sci_sendmsg SCI_GETEDGEMODE + +if~ $(MSG_RESULT) != EDGE_LINE then + set local $(LinePixelWidth) = 0 + goto :DoWrap +endif + +sci_sendmsg SCI_GETEDGECOLUMN +set local $(LineCharWidth) ~ $(MSG_RESULT) + 1 + +set local $(TemplateStr) = W +set local $(Cnt) = 2 + +:ForLoopStart + if $(Cnt) > $(LineCharWidth) goto :ForLoopEnd + set local $(TemplateStr) = $(TemplateStr)W + set local $(Cnt) ~ $(Cnt) + 1 +goto :ForLoopStart + +:ForLoopEnd +sci_sendmsg SCI_TEXTWIDTH STYLE_DEFAULT "$(TemplateStr)" +set local $(LinePixelWidth) = $(MSG_RESULT) + +:DoWrap +sci_sendmsg SCI_TARGETFROMSELECTION +sci_sendmsg SCI_LINESSPLIT $(LinePixelWidth) + + + +::DeleteLinesFrom2ndView +npp_console keep +npp_console disable +npe_console -- m- + +sci_sendmsg SCI_DOCUMENTSTART +npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW +sci_sendmsg SCI_DOCUMENTSTART + +npp_sendmsg NPPM_GETCURRENTVIEW + +if $(MSG_RESULT) == 0 then + npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW +endif + +sci_sendmsg SCI_GETLINECOUNT +set local $(LineCount) = $(MSG_RESULT) +set local $(LineIdx) = 0 + +:ProcessSearchTerms +if $(LineIdx) >= $(LineCount) goto :End + sci_sendmsg SCI_GETLINE $(LineIdx) @"" + set local $(CurLine) = $(MSG_LPARAM) + + if "$(CurLine)" == "" goto :AdvanceToNextLine + + npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW + + sci_sendmsg SCI_GETCURRENTPOS + sci_sendmsg SCI_LINEFROMPOSITION $(MSG_RESULT) + set local $(StartLineIdx) = $(MSG_RESULT) + + set local $(Flags) ~ NPE_SF_SETPOS + + :ReplaceLoop + sci_find $(Flags) "$(CurLine)" + if $(MSG_RESULT) == -1 goto :ReplaceLoopEnd + + sci_sendmsg SCI_LINEFROMPOSITION $(MSG_RESULT) + set local $(FoundLineIdx) = $(MSG_RESULT) + + sci_sendmsg SCI_GETLINE $(FoundLineIdx) @"" + set local $(FoundLine) = $(MSG_LPARAM) + + set local $(FoundLineLC) ~ strlower "$(FoundLine)" + set local $(CurLineLC) ~ strlower "$(CurLine)" + + if "$(FoundLineLC)" == "$(CurLineLC)" then + sci_sendmsg SCI_GOTOLINE $(FoundLineIdx) + sci_sendmsg SCI_LINEDELETE + endif + + set local $(Flags) ~ $(Flags) | NPE_SF_NEXT + goto :ReplaceLoop + + :ReplaceLoopEnd + sci_sendmsg SCI_GOTOLINE $(StartLineIdx) + npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW + + :AdvanceToNextLine + set local $(LineIdx) ~ $(LineIdx) + 1 +goto :ProcessSearchTerms + +:End +sci_sendmsg SCI_DOCUMENTSTART +npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW +sci_sendmsg SCI_DOCUMENTSTART + +npp_sendmsg NPPM_GETCURRENTVIEW + +if $(MSG_RESULT) == 1 then + npp_sendmsg NPPM_MENUCOMMAND 0 IDM_VIEW_SWITCHTO_OTHER_VIEW +endif + +npp_console enable + + + +::ReadLongText +npp_console keep + +npp_sendmsg WM_COMMAND IDM_VIEW_CLONE_TO_ANOTHER_VIEW +sci_sendmsg SCI_PAGEDOWN +npp_sendmsg WM_COMMAND IDM_VIEW_SYNSCROLLV + + + +::TrimTrailingSpace +npp_console keep +npp_sendmsg WM_COMMAND IDM_EDIT_TRIMTRAILING diff --git a/PowerEditor/Test/FunctionList/udl-NppExec/unitTest.expected.result b/PowerEditor/Test/FunctionList/udl-NppExec/unitTest.expected.result new file mode 100644 index 000000000..2c2eb07c5 --- /dev/null +++ b/PowerEditor/Test/FunctionList/udl-NppExec/unitTest.expected.result @@ -0,0 +1 @@ +{"nodes":[{"leaves":["::StartupScript"],"name":"StartupScript"},{"leaves":["::MultipleSelectAddNext"],"name":"MultipleSelectAddNext"},{"leaves":["::MultipleSelectAddEach"],"name":"MultipleSelectAddEach"},{"leaves":["::SetSingleEdgeLine"],"name":"SetSingleEdgeLine"},{"leaves":["::ConfigSingleEdgeLine"],"name":"ConfigSingleEdgeLine"},{"leaves":["::SingleEdgeLineOn"],"name":"SingleEdgeLineOn"},{"leaves":["::MultipleEdgeLinesOn"],"name":"MultipleEdgeLinesOn"},{"leaves":["::BackgroundEdgeOn"],"name":"BackgroundEdgeOn"},{"leaves":["::EdgesOff"],"name":"EdgesOff"},{"leaves":["::WrapSelectedLinesAtEdge","ForLoopStart","ForLoopEnd","DoWrap"],"name":"WrapSelectedLinesAtEdge"},{"leaves":["::DeleteLinesFrom2ndView","ProcessSearchTerms","ReplaceLoop","ReplaceLoopEnd","AdvanceToNextLine","End"],"name":"DeleteLinesFrom2ndView"},{"leaves":["::ReadLongText"],"name":"ReadLongText"},{"leaves":["::TrimTrailingSpace"],"name":"TrimTrailingSpace"}],"root":"unitTest"} \ No newline at end of file diff --git a/PowerEditor/installer/filesForTesting/overrideMap.xml b/PowerEditor/installer/filesForTesting/overrideMap.xml index 2f701219f..f00c96439 100644 --- a/PowerEditor/installer/filesForTesting/overrideMap.xml +++ b/PowerEditor/installer/filesForTesting/overrideMap.xml @@ -125,6 +125,7 @@ --> + diff --git a/PowerEditor/installer/functionList/nppexec.xml b/PowerEditor/installer/functionList/nppexec.xml new file mode 100644 index 000000000..1678d12b3 --- /dev/null +++ b/PowerEditor/installer/functionList/nppexec.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/installer/functionList/overrideMap.xml b/PowerEditor/installer/functionList/overrideMap.xml index 2dbefbf9e..8c6a997e3 100644 --- a/PowerEditor/installer/functionList/overrideMap.xml +++ b/PowerEditor/installer/functionList/overrideMap.xml @@ -125,6 +125,7 @@ --> +