Skip to content

Instantly share code, notes, and snippets.

@brigand
Created April 17, 2012 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brigand/2408612 to your computer and use it in GitHub Desktop.
Save brigand/2408612 to your computer and use it in GitHub Desktop.
a script that allows allows you to write AutoHotkey code quicker
; AutoExpander.ahk
/*
Copyright (c) 2012, Frankie Bagnardi
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*/
::ahk::
Data := GetData()
Code := TempToCode(Data)
CB := Clipboard
Clipboard := Code
Send ^v
Clipboard := CB
return
TempToCode(Data) {
return ReplaceCall("([^,]+)(?:,?)", Data, "HandleItem")
}
HandleItem(M, Item) {
If (Item ~= "::")
;~ MsgBox % M . "`n `nreturn`n`n"
return Item . "`n `nreturn`n`n"
else
return ReplaceCall("(\w+)[ ]((?:\w+[ ]*)*)(?:->[ ]*(.*))?", Item, "HandleFunction")
}
HandleFunction(M, Name, Params, Lambda) {
Params := Trim(Params)
StringReplace, Params, Params, %A_Space%, % ", ", All
outs =
(
%Name%(%Params%) {
return %Lambda%
}
)
return outs
}
::eos::
ExitApp
GetData() {
Input, Data, v, {Enter}
return Data
}
ReplaceCall(N, H, F, Start=1) {
If !IsFunc(F)
return
If !IsObject(F)
F := Func(F) ; Make it an object
G := this.GetGroups(N)
Pos := 1, P_ := "", Result := ""
While ( Pos := RegExMatch(H, N, P_, Pos + StrLen(P_)) ) {
R := F.(P_, P_1, P_2, P_3, P_4, P_5, P_6, P_7, P_8
, P_9, P_10, P_11, P_12, P_13, P_14, P_15)
; Credit to majkinetor for the next two lines
Result .= SubStr(H, Start, Pos-Start) . R ; R is the return value
Start := Pos + StrLen(P_)
}
return Result . SubStr(H, Start)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment