Ok, here is an update of the script.
Please keep on posting bugs or improvements. Thanks
Edit: 051114: string indicator set to "
Code:
;##############################################################################
;#
;# Add or update syntaxhiglighting for AutoHotKey scripts in UltraEdit
;#
;# Mod of a script done by Tekl (although not much has survived)
;# Mod done by toralf, 2005-07-18
;#
;# Tested with: AHK 1.0.36.06, Windows XP Pro, UltraEdit 10.10c/10.20/11.10a
;#
;# Requirements
;# - Syntax files for AHK in one directory
;# - UltraEdit uses standard file for highlighting => wordfile.txt
;#
;# Customize:
;# - The default color for strings is gray, change it to any color
;# you want to have "string" to appeer => Extra->Option->syntaxhiglighting
;# - Change the default color for up to 8 keyword groups
;# => Extra->Option->syntaxhiglighting
;# -specify up to 8 syntax files, each containing one keyword per line
;# => you can add your own files, for keywords that you want to highlight
;# Personally I use 3 additional: Operators, Separators and Special, see further below in this topic
;#
; Specify a list of up to 8 syntax files; the order influences the color given to them by UE by default
SyntaxFileNameList = CommandNames|Keywords|Variables|Keys|Operators|Separators|Special
;Default colors in UE: blue |red |orange |green |brown |blue |blue |blue
SyntaxExtention = .txt
PathSyntaxFiles = %ProgramFiles%\AutoHotkey\Extras\Editors\Syntax
FileUEWordFile = %ProgramFiles%\UltraEdit\wordfile.txt
;############# END of Custamization Area ##################################
;############# Ask and Check for valid input ###############################
;Search or ask for Wordfile, when it doesn't exist -> exit
IfNotExist, %FileUEWordFile%
FileSelectFile, FileUEWordFile, 1, %PathProgramFiles%, Select UltraEdit wordfile, *.txt
IfNotExist, %FileUEWordFile%
{
MsgBox, 16,, UltraEdit Wordfile cannot be found.
ExitApp
}
;Search or ask for specified syntax folder and files, when they don't exist -> exit
IfNotExist, %PathSyntaxFiles%
FileSelectFolder, PathSyntaxFiles, ,2, Select Folder of Syntax Files
MissingFile =
FileCount = 0
Loop, Parse, SyntaxFileNameList, |
{
FileCount += 1
IfNotExist, %PathSyntaxFiles%\%A_LoopField%%SyntaxExtention%
MissingFile = %MissingFile%`n%A_LoopField%%SyntaxExtention%
}
If MissingFile is not Space
{
MsgBox, 16,, AHK Syntax file(s)`n%MissingFile%`n`ncannot be found in`n`n%PathSyntaxFiles%\.
ExitApp
}
If FileCount > 8
{
MsgBox, 16,, You have specified %FileCount% Syntax files.`nOnly 8 are supported be UltraEdit.`nPlease shorten the list.
ExitApp
}
;Check the number of languages in the current wordfile, if more than 19 without AHK -> exit
NumberOfLanguages = 0
Loop, Read, %FileUEWordFile%
{
StringLeft, WFdef, A_LoopReadLine, 2
If WFdef = /L
{
StringSplit, WFname, A_LoopReadLine, "
LanguageName = %WFname2%
If LanguageName <> AutoHotkey
NumberOfLanguages +=1
}
}
If NumberOfLanguages > 19
{
MsgBox, 48,, The wordfile has %NumberOfLanguages% syntax-schemes. UltraEdit does only support 20 schemes.`nPlease Delete schemes from the file!
ExitApp
}
;############# Read keywords from syntax files into arrays ################
Loop, Parse, SyntaxFileNameList, | ;Read all syntax files
{
SyntaxFileName = %A_LoopField%
Gosub, ReadSyntaxFromFile ;SyntaxFileName will become string with keywords
}
;############# Build language specific highlight for AHK ##################
StrgAHKwf = "AutoHotkey" Nocase
StrgAHKwf = %StrgAHKwf% Line Comment = `;
StrgAHKwf = %StrgAHKwf% Line Comment Preceding Chars = [~``] ;to Escape Escaped ;
StrgAHKwf = %StrgAHKwf% Escape Char = ``
StrgAHKwf = %StrgAHKwf% String Chars = "
StrgAHKwf = %StrgAHKwf% Block Comment On = /*
StrgAHKwf = %StrgAHKwf% Block Comment Off = */
StrgAHKwf = %StrgAHKwf% File Extensions = ahk`n
StrgAHKwf = %StrgAHKwf%/DeLimiters = *~`%+-!^&(){}=|\/:"'``;<>%A_Tab%,%A_Space%.`n
StrgAHKwf = %StrgAHKwf%/Indent Strings = "{" ":"`n
StrgAHKwf = %StrgAHKwf%/Unindent Strings = "}" "Return"`n
StrgAHKwf = %StrgAHKwf%/Open Fold Strings = "{"`n
StrgAHKwf = %StrgAHKwf%/Close Fold Strings = "}"`n
StrgAHKwf = %StrgAHKwf%/Function String = "`%[^t ]++^(:[^*^?BbCcKkOoPpRrZz0-9- ]++:*`::^)"`n ; Hotstrings
StrgAHKwf = %StrgAHKwf%/Function String 1 = "`%[^t ]++^([a-zA-Z0-9 #!^^&<>^*^~^$]+`::^)"`n ; Hotkeys
StrgAHKwf = %StrgAHKwf%/Function String 2 = "`%[^t ]++^([a-zA-Z0-9äöüß#_@^$^?^[^]]+:^)"`n ; Subroutines
StrgAHKwf = %StrgAHKwf%/Function String 3 = "`%[^t ]++^([a-zA-Z0-9äöüß#_@^$^?^[^]]+(*)^)"`n ; Functions
StrgAHKwf = %StrgAHKwf%/Function String 4 = "`%[^t ]++^(#[a-zA-Z]+ ^)"`n ; Directive
/* Test Area
;HOTSTRINGS
:*:js@::
:b0*?:11::
:c :ceo::
;HOTKEYS
#n::
^Numpad0::
^!s::
RWIN::
Numpad0 & Numpad1::
#!^& <>*~$test::
;FUNCTIONS
function@(ä,ß,*)
ähnlich(zahl,Fuß)
;SUBROUTINES
Subroutine:
Fußbälle:
;DIRECTIVE
#HotkeyModifierTimeout Milliseconds
*/
Loop, Parse, SyntaxFileNameList, | ;Add the keywords from syntax strings into their Sections
{
StrgAHKwf = %StrgAHKwf%/C%A_Index%"%A_LoopField%" ;Section definition
SyntaxString = %A_LoopField% ;which Section/syntax
Gosub, ParseSyntaxString ;Parse through string and add to list
}
;############# Add or Update Wordfile #####################################
;Name of a file for temporary store the word file
TemporaryUEwordFile = TempUEwordFile.txt
FileDelete, %TemporaryUEwordFile%
Loop, Read, %FileUEWordFile%, %TemporaryUEwordFile% ;Read through Wordfile
{
StringLeft, WFdef, A_LoopReadLine, 2
If WFdef = /L
{
StringSplit, WFname, A_LoopReadLine, "
LanguageName = %WFname2%
LanguageNumber = %WFname1%
StringTrimLeft,LanguageNumber,LanguageNumber,2
If LanguageName = AutoHotkey ;when AHK Section found, place new Section at same location
{
FileAppend, /L%LanguageNumber%%StrgAHKwf%
AHKLanguageFound := True
}
}
If LanguageName <> AutoHotkey ;everything that does not belong to AHK, gets unchanged to file
FileAppend, %A_LoopReadLine%`n
}
If not AHKLanguageFound ;when AHK Section not found, append AHK Section
{
LanguageNumber += 1
FileAppend, /L%LanguageNumber%%StrgAHKwf%, %TemporaryUEwordFile%
}
FileCopy, %FileUEWordFile%, %FileUEWordFile%.ahk.bak, 1 ;Create Backup of current wordfile
FileMove, %TemporaryUEwordFile%, %FileUEWordFile%, 1 ;Replace wordfile with temporary file
; Tell user what has been done
If AHKLanguageFound
MsgBox, 64,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%FileUEWordFile%`n`nA backup has been created in the same folder.
Else
MsgBox, 64,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%FileUEWordFile%`n`nA backup has been created in the same folder.
ExitApp ; That's it, exit
;############# SubRoutines ################################################
ReadSyntaxFromFile:
TempString =
Loop, Read , %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention% ;read syntax file
{
StringLeft,Char, A_LoopReadLine ,1
If Char <> `; ;If line is comment, don't bother
;otherwise only add first word in line
Loop Parse, A_LoopReadLine, `,%A_Tab%%A_Space%
{
TempString = %TempString%%A_LoopField%`n
Break
}
}
%SyntaxFileName% = %TempString% ;Assign string to syntax filename
Sort, %SyntaxFileName%, U ;Sort keywords in string
Return
ParseSyntaxString:
Loop, Parse, %SyntaxString%, `n ;Parse through syntax string
{
StringLeft, Char, A_LoopField,1
If (Char = PrevChar) ;add keyword to line when first character is same with previous keyword
StrgAHKwf = %StrgAHKwf% %A_LoopField%
Else ;for every keyword with a new first letter, start a new row
StrgAHKwf = %StrgAHKwf%`n%A_LoopField%
PrevChar = %Char% ;remember first character of keyword
}
Return
;############# END of File ################################################