Thanks for the feedback & testing.
SpeedMaster wrote: ↑10 Nov 2019, 08:28
Suggestion:
Adding a toggle icon to also remove AHK comments and bloc comments (; /* */) would be a good addition.
(Sometimes it is useful to paste a snippet with it's AHK comments and sometimes not)
Perhaps this is too specific to add to lintalist, also because of various commenting styles in other languages. If you MUST have it I would probably do the following.
In lintalist
https://github.com/lintalist/lintalist/blob/master/lintalist.ahk#L1009, or 1025 in the beta, change the FileAppend line so it insert a "LintaListGlobalScript" variable into each script
Code: Select all
FileAppend, % "LintaListGlobalScript=" LintaListGlobalScript "`n`n" Script, %TmpDir%\tmpScript.ahk, UTF-8 ; %
Then I would add the following to
include\MyPlugins.ahk or
include\MyFunctions.ahk
Code: Select all
#IfWinActive, ahk_group AppTitle ; Hotkeys only work in the just created GUI
F12::
LintaListGlobalScript:="StripComments"
Gosub, Paste
LintaListGlobalScript:=""
Return
#IfWinActive
And then use the following script code for those snippets - remember you can use a local variable as script as well so that way it will work across bundles and you would only have to update one script to change it
script code:
Code: Select all
#NoEnv
#SingleInstance, force
SetBatchLines, -1
ListLines, off
LLInit() ; fake call to load global variables from Lintalist main script - see Docs
ClipSet("s",1,SendMethod,Clipboard) ; store current clipboard contents
ClearClipboard() ; clear it
MsgBox % LintaListGlobalScript
[[llpart1]]
If (LintaListGlobalScript = "StripComments")
{
llpart1:=regexreplace(llpart1,"mU) `;.*(\r?\n)","$1")
llpart1:=regexreplace(llpart1,"msU)/\*.*\*\/")
}
Clipboard:=llpart1
Sleep 200
SendKey(SendMethod, "^v") ; paste changed clipboard using SendMethod defined by Lintalist settings
Clipboard:=ClipSet("g",1) ; restore original clipboard contents
ExitApp
Now when you press ENTER or Alt-0..9 in the search gui it will paste with Comments, if you press F12 it will try to strip the comments before pasting the snippet
This does mean I need to add "LintaListGlobalScript" to the standard Lintalist but that might be a useful addition as other users may find it useful to pass on some info to script based on similar use cases.
Edit Much easier would be to copy the clip to the clipboard directly using the "alt-enter" shortcut/label like so, now you have the clipboard so you can use the regex codes from above to strip comments, example with F11
Code: Select all
#IfWinActive, ahk_group AppTitle ; Hotkeys only work in the just created GUI
F11::
Gosub, !Enter
Sleep 500
MsgBox % clipboard ; just to illustrate
Return
#IfWinActive