; Generates Syntax file for PSPad
; Last Edited: 14/03/2012
; Tested with: Autohotkey_L v1.1.07.01 (Win 7 x64)
; Author: Kidmar, Scott Greenberg (Gen PSPad)
; ============================================================================
; PLACE THIS SCRIPT IN PSPAD FOLDER
; FILL THE AHK_Folder variable (ex: "C:\Program Files (x86)\AutoHotkey")
; ============================================================================
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1 ; Speeds up file operations.
IniKey := ""
PSPadINI = PSPad.ini
PSPadEXE = PSPad.exe
TargetFile = AutoHotkey.ini
TargetProfileName = AutoHotkey
AHK_Folder := "C:\Program Files (x86)\AutoHotkey" ; Fill me up
CheckAllOk()
GetAHKSyntaxFiles()
GenPSPad()
WriteIniFile()
ClearFiles()
ClearFiles()
{
Global TargetFile
FileMove, %TargetFile%, Syntax\%TargetFile%, 1
FileDelete CommandNames.txt
FileDelete Functions.txt
FileDelete Keywords.txt
FileDelete Variables.txt
FileDelete Keys.txt
}
WriteIniFile()
{
Global PSPadINI
Global IniKey
Global TargetProfileName
Global AHK_Folder
IniDelete, %PSPadINI%, %TargetProfileName%
IniWrite, %TargetProfileName%, %PSPadINI%, Config, %IniKey%
IniWrite, AutoHotkey (*.ahk)|*.ahk, %PSPadINI%, %TargetProfileName%, Filter
IniWrite, 0, %PSPadINI%, %TargetProfileName%, HLTabWidth
IniWrite, % "" , %PSPadINI%, %TargetProfileName%, IndentChar
IniWrite, % "" , %PSPadINI%, %TargetProfileName%, UnIndentChar
IniWrite, 00FF00001FFFFFFF010, %PSPadINI%, %TargetProfileName%, Comment
IniWrite, 1FFFFFFF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Identifier
IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key
IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key words 2
IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key words 3
IniWrite, 000000FF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Label
IniWrite, 008000001FFFFFFF000, %PSPadINI%, %TargetProfileName%, Number
IniWrite, 008080001FFFFFFF010, %PSPadINI%, %TargetProfileName%, Preprocessor
IniWrite, 000000801FFFFFFF100, %PSPadINI%, %TargetProfileName%, Reserved Word
IniWrite, 008080001FFFFFFF000, %PSPadINI%, %TargetProfileName%, Space
IniWrite, 000080001FFFFFFF000, %PSPadINI%, %TargetProfileName%, String
IniWrite, 1FFFFFFF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Symbol
IniWrite, %AHK_Folder%\Compiler\Ahk2Exe.exe, %PSPadINI%, %TargetProfileName%, Compilator File
IniWrite, /in `"`%File`%`", %PSPadINI%, %TargetProfileName%, Compilator Param
IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator LOG
IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator Run
IniWrite, %AHK_Folder%\AutoHotkey.chm, %PSPadINI%, %TargetProfileName%, Compilator Help
IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator SaveAll
IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator ParsLog
IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator Capture
IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator HideOutput
IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator DefaultDir
IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator LogType
IniWrite, % "AutoHotkey,|" AHK_Folder "\AutoHotkey.exe| |%File%|", %PSPadINI%, %TargetProfileName%, Prog0
}
CheckAllOk()
{
Global PSPadINI
Global PSPadEXE
Global IniKey
Global TargetProfileName
Global AHK_Folder
; Check for script in right folder
If NOT (FileExist(PSPadEXE) AND FileExist(PSPadINI))
{
MsgBox, Can't generate Syntax file.`nPlease place this script in PSPad folder!
ExitApp
}
; Search a free UserHighliter's slot
Loop, 5
{
UserKey = UserHighLighterName
If A_INDEX > 1
UserKey := UserKey . (A_INDEX -1)
IniRead, User, %PSPadINI%, Config, %UserKey%,
If (User = "" OR User = TargetProfileName)
{
IniKey := UserKey
Break
}
}
If (IniKey = "")
{
MsgBox, No user slot available in PSPad.ini
ExitApp
}
; Check for AHK Installation Path
If NOT FIleExist(AHK_Folder . "\Autohotkey.exe")
{
msgbox, Wrong AHK folder.Correct the script
Exitapp
}
}
GenPSPad()
;;; ============================================================================
;;; FILENAME: Generate PSPad.ahk
;;; ============================================================================
;;; PSPad Syntax Generator Script
;;; ============================================================================
;;; AUTHOR: Scott Greenberg
;;; COMPANY: SG Technology
;;; VERSION: 1.0.0, 02/08/2005 - 02/08/2005
;;; WEBSITE: http://gogogadgetscott.info/
;;;
;;; ============================================================================
;;; NOTE:
;;; Derived from Rajat's PSPad Syntax Generator Script
;;; ============================================================================
{
Global TargetFile
FileDelete, %TargetFile%
FileAppend, `; PSPad keyword syntax file for AutoHotkey`n, %TargetFile%
FileAppend, `; Auto generated by GoGoGadgetScott's PSPad Syntax Generator Script`n`n, %TargetFile%
FileAppend, [Settings] `n, %TargetFile%
FileAppend, Name=AutoHotkey `n, %TargetFile%
FileAppend, HTMLGroup=0 `n, %TargetFile%
FileAppend, FileType=*.ahk `n, %TargetFile%
FileAppend, CommentString=; `n, %TargetFile%
FileAppend, CComment=1 `n, %TargetFile%
FileAppend, BasComment=1 `n, %TargetFile%
FileAppend, SingleQuote=1 `n, %TargetFile%
FileAppend, DoubleQuote=1 `n, %TargetFile%
FileAppend, Preprocessors=1 `n, %TargetFile%
FileAppend, KeyWordChars=-_# `n, %TargetFile%
FileAppend, [KeyWords]`n, %TargetFile%
;this doesn't require fancy cmd names for human reading,
;it just requires names to be highlighted. so getting first name only
Loop, Read, CommandNames.txt, %TargetFile%
{
CurrCmd =
FullCmd = %a_loopreadline%
;directives don't have first comma but a first space
;so whichever is first, take it as end of cmd name
StringGetPos, cPos, a_loopreadline, `,
StringGetPos, sPos, a_loopreadline, %A_Space%
IfLess, sPos, %cPos%
IfGreater, sPos, 0
StringLeft, CurrCmd, a_loopreadline, %sPos%
IfLess, cPos, %sPos%
IfGreater, cPos, 0
StringLeft, CurrCmd, a_loopreadline, %cPos%
IfLess, cPos, %sPos%
IfLess, cPos, 0
StringLeft, CurrCmd, a_loopreadline, %sPos%
IfLess, sPos, %cPos%
IfLess, sPos, 0
StringLeft, CurrCmd, a_loopreadline, %cPos%
StringReplace, FullCmd, FullCmd, ``n, `n, a
StringReplace, FullCmd, FullCmd, ``t, `t, a
StringReplace, CurrCmd, CurrCmd, [,, a
StringReplace, CurrCmd, CurrCmd, %a_space%,, a
;For a directive that has no parameters
IfEqual, CurrCmd,
CurrCmd = %a_loopreadline%
;this check removes duplicates for loop and if
IfNotEqual, CurrCmd, %LastCmd%
FileAppend, %CurrCmd%=`n
LastCmd = %CurrCmd%
}
FileAppend, `n[ReservedWords]`n, %TargetFile%
;Adding keywords including the blank lines and comments
Loop, Read, Keywords.txt, %TargetFile%
FileAppend, %A_LoopReadLine%=`n
FileAppend, `n`n, %TargetFile%
FileAppend, `n[KeyWords2]`n, %TargetFile%
;same with variables
Loop, Read, Variables.txt, %TargetFile%
FileAppend, %A_LoopReadLine%=`n
FileAppend, `n[KeyWords3]`n, %TargetFile%
;keys are added with and without {}
Loop, Read, Keys.txt, %TargetFile%
{
FileAppend, %A_LoopReadLine%=`n
IfEqual, A_LoopReadLine,, Continue
;comment check
StringReplace, check, A_LoopReadLine, %A_Space%,, A
StringReplace, check, check, %A_Tab%,, A
StringLeft, check, check, 1
IfEqual, check, `;, Continue
FileAppend, {%A_LoopReadLine%}=`n
}
}
; Function
GetAHKSyntaxFiles()
; AutoHotkey Version: 1.x
; Script Function:
; Download a number of pages from the AutoHotkey Wiki to prepare the following files:
;
; - CommandNames.txt
; - Functions.txt
; - Keywords.txt
; - Variables.txt
; - Keys.txt
;
; Which can be used to prepare syntax files for a variety of text editors
; see http://www.autohotkey.com/wiki/index.php?title=Syntax_Highlighting
; for a complete listing, to discuss this visit the AHK Forum thread.
{
FileDelete, tmpfile$$$.htm
FileList=CommandNames,Functions,Keywords,Variables,Keys
Loop, parse, FileList, CSV
{
URLDownloadToFile, http://www.autohotkey.com/wiki/index.php?title=Syntax_%A_LoopField%, tmpfile$$$.htm
FileRead, File, tmpfile$$$.htm
RegExMatch(File,"is)<pre>(.*)</pre>",%A_LoopField%)
File:=%A_LoopField%1
File:=RegExReplace(RegExReplace(File, "`nm)^;.+\R" ), "`nm)^\n" ) ; remove empty lines and comments
FileDelete, %A_LoopField%.txt
FileAppend,%File%,%A_LoopField%.txt
FileDelete, tmpfile$$$.htm
File=
}
}I would like to add it to the wiki page too, if it is confirmed to be working for everyone.Edit 06.04.2012: Added " char in compile options




