This version makes use of "Pre_Edit_Script()" v1.3 Function, in which supports "%%#Include_Another.ahkpe_File%%" (useful to keep "%%++UniqueId%%" or "%%++Any_Var%%" correct counting that can be used, for example, to create "Anonymous Functions"!)
Code: Select all
Cmd_Total_Parameters = %0%
Cmd_Parameter := []
loop, % Cmd_Total_Parameters
Cmd_Parameter[a_index] := %a_index%
if (Cmd_Parameter[1] != "")
{
;msgbox, % Cmd_Parameter[1]
FileRead, File_Content, % Cmd_Parameter[1] ;"Cmd_Parameter[1]" contains the file path
File_Extension := ".ahk"
FileDelete, % Cmd_Parameter[1] File_Extension
Pre_Edited_Script := "FileDelete, " Cmd_Parameter[1] File_Extension "`r`n`r`n"
Pre_Edited_Script .= Pre_Edit_Script(File_Content)
FileAppend, % Pre_Edited_Script, % Cmd_Parameter[1] File_Extension, UTF-8 ;"UTF-8" same Encoding used by ".ahk" files
run, % Cmd_Parameter[1] File_Extension
exitapp
}
;______________________________
App_Title := "Pre-Editor"
App_Version := "1.1"
;______________________________
Script =
(join`r`n
xxx := "111"
yyy := "222"
zzz := "333"
;ttt := "44444"
gui, add, text, , `%`%xxx`%`% `%`%yyy`%`% `%`%zzz`%`% `%`%;ttt`%`%
gui, add, text, , `%`%++Count`%`% `%`%++Count`%`% `%`%++Count`%`% - `%`%Count`%`% `%`%Count`%`% `%`%Count`%`%
gui, add, text, , `%`%++UniqueId`%`% `%`%++UniqueId`%`% - `%`%UniqueId`%`% `%`%UniqueId`%`%
;_________
gui, add, text, w300 h200, Left click anywhere in this window
gui, add, button, gRunAnonymousFunctions, Run Anonymous Functions
gui, show
return
RunAnonymousFunctions: ;__
`%`%#Include_Another.ahkpe`%`%
Anonymous_Function`%`%++UniqueId`%`%()
Anonymous_Function`%`%UniqueId`%`%()
{
msgbox, `% A_ThisFunc
}
Anonymous_Function`%`%++UniqueId`%`%()
Anonymous_Function`%`%UniqueId`%`%()
{
msgbox, `% A_ThisFunc
}
Anonymous_Function`%`%++UniqueId`%`%()
Anonymous_Function`%`%UniqueId`%`%()
{
msgbox, `% A_ThisFunc
}
`%`%#Include_Another.ahkpe`%`%
return
guiclose: ;__
exitapp
;___________
;Function_Name := "Test"
`%`%;Function_Name`%`%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("`%`%;Function_Name`%`%")) ;"0x201" left mouse down
Static count := 0
tooltip, `% A_ThisFunc "() - " count++, 0, 200, 1
}
;Function_Name := "First"
`%`%;Function_Name`%`%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("`%`%;Function_Name`%`%")) ;"0x201" left mouse down
Static count := 1
tooltip, `% A_ThisFunc "() - " count++, 0, 225, 2
}
;Function_Name := "Last"
`%`%;Function_Name`%`%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("`%`%;Function_Name`%`%")) ;"0x201" left mouse down
Static count := 2
tooltip, `% A_ThisFunc "() - " count++, 0, 250, 3
}
)
Temp_Script_File_Name := "#_AHK_Temp_Pre_Edited_Script.ahk"
gui,add, button, gPreRunScript, Pré-Edit and Run Script
gui, add, button, x+5 gShowPreEdScript, show Pre-Edited code
gui, add, edit, xm w800 h600 +HScroll WantTab +HwndUserInputControlId,
ControlSetText , , % Script, % "ahk_id" UserInputControlId
gui, show, , % App_Title " (v" App_Version ")"
return
ShowPreEdScript: ;___________________________________
ControlGetText, UserScript, , % "ahk_id" UserInputControlId
gui ShowPreEdScript:default
gui, destroy
gui, add, edit, w700 h500 +HScroll +HwndPreEdScriptOut,
ControlSetText , , % Pre_Edit_Script(UserScript), % "ahk_id" PreEdScriptOut
gui, show
return
PreRunScript: ;_________________________________________
ControlGetText, UserScript, , % "ahk_id" UserInputControlId
FileDelete, % Temp_Script_File_Name
FileAppend , % Pre_Edit_Script(UserScript), % Temp_Script_File_Name
run, % Temp_Script_File_Name
return
guiclose: ;_________________________________________
exitapp
RegExEsc(String, Options := "") ;_________ RegExEsc(Function) - v1.0 __________
{
if (Options == "$")
return, RegExReplace(String, "\$", "$$$$") ;to be used with "RegExReplace" third parameter! ("$$" represents one literal "$")
return, "\E\Q" RegExReplace(String, "\\E", "\E\\E\Q") "\E" ;to be used with "RegExMatch" and "RegExReplace" second parameters! ("\\" represents one literal "\")
}
Pre_Edit_Script(Script) ;_______________ v1.3 _________________
{
Pre_Vars := []
MatchLength := 0
FoundPos := 1
loop
{
FoundPos := RegExMatch(Script, "(?P<Set>(\n| |\t)(?P<Key>\S+?)( |\t)*?:=( |\t)*?""(?P<Value>.*?)"")|(?P<Rep>%%(?P<Var>\S+?)%%)", Match_, FoundPos + MatchLength)
;\s, Matches any single whitespace character, mainly space, tab, and newline (`r and `n)
;"(\n| |\t)" in use because "\s" does not work correctly!
;\S, means "any non-whitespace character".
if (FoundPos == "" or FoundPos = 0)
break
else
{
if (Match_ = Match_Set)
{
Pre_Vars[Match_Key] := Match_Value
MatchLength := StrLen(Match_)
;msgbox, % Match_Set " - " Match_Key " / " Match_Value
}
else if (Match_ = Match_Rep)
{
if RegExMatch(Match_Var, "i)^#Include_(.+)", Found_Include)
{
;msgbox, % Found_Include " / " Found_Include1
FileRead, Include_Content, % Found_Include1
Script := RegExReplace(Script, RegExEsc(Match_Rep), RegExEsc(Include_Content, "$"), , 1, FoundPos)
Include_Content := "" ;free memory
MatchLength := 0
continue ;Skips the rest of the current loop iteration and begins a new one. (Valid inside any kind of loop.)
}
if RegExMatch(Match_Var, "^\+\+(.+)", Found_Var)
{
;msgbox, % Match_Var " / " Found_Var1
Match_Var := Found_Var1
Match_Var_Value := Pre_Vars[Match_Var]
if Match_Var_Value is number
Pre_Vars[Match_Var]++
else
Pre_Vars[Match_Var] := 0
}
Script := RegExReplace(Script, RegExEsc(Match_Rep), RegExEsc(Pre_Vars[Match_Var], "$"), , 1, FoundPos)
MatchLength := StrLen(Pre_Vars[Match_Var])
;msgbox, % Match_Rep " - " Match_Var
}
}
}
return, Script
}
Code: Select all
xxx := "111"
yyy := "222"
zzz := "333"
;ttt := "44444"
gui, add, text, , %%xxx%% %%yyy%% %%zzz%% %%;ttt%%
gui, add, text, , %%++Count%% %%++Count%% %%++Count%% - %%Count%% %%Count%% %%Count%%
gui, add, text, , %%++UniqueId%% %%++UniqueId%% - %%UniqueId%% %%UniqueId%%
;_________
gui, add, text, w300 h200, Left click anywhere in this window
gui, add, button, gRunAnonymousFunctions, Run Anonymous Functions
gui, show
return
RunAnonymousFunctions: ;__
%%#Include_Another.ahkpe%%
Anonymous_Function%%++UniqueId%%()
Anonymous_Function%%UniqueId%%()
{
msgbox, % A_ThisFunc
}
Anonymous_Function%%++UniqueId%%()
Anonymous_Function%%UniqueId%%()
{
msgbox, % A_ThisFunc
}
Anonymous_Function%%++UniqueId%%()
Anonymous_Function%%UniqueId%%()
{
msgbox, % A_ThisFunc
}
%%#Include_Another.ahkpe%%
return
guiclose: ;__
exitapp
;___________
;Function_Name := "Test"
%%;Function_Name%%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("%%;Function_Name%%")) ;"0x201" left mouse down
Static count := 0
tooltip, % A_ThisFunc "() - " count++, 0, 200, 1
}
;Function_Name := "First"
%%;Function_Name%%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("%%;Function_Name%%")) ;"0x201" left mouse down
Static count := 1
tooltip, % A_ThisFunc "() - " count++, 0, 225, 2
}
;Function_Name := "Last"
%%;Function_Name%%() ;__________________________________________________
{
Static RunAtScriptExecution := OnMessage(0x201, Func("%%;Function_Name%%")) ;"0x201" left mouse down
Static count := 2
tooltip, % A_ThisFunc "() - " count++, 0, 250, 3
}