Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Automatic syntaxhighlightning instalation for UltraEdit


  • Please log in to reply
17 replies to this topic
toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Note from moderator: There is a newer version of the script that supports UE 15 at www.autohotkey.com/forum/viewtopic.php?t=43416 -- but the very latest version as of 10/3/2009 is distributed with AutoHotkey in the Extras folder.

This topic is a continuation of this topic:
http://www.autohotke...opic.php?t=1533

Due to the actual script being on the 4th page I decided to create a new topic, to keep the current version of the script in the first post. Therefor it shoudl be easier now to follow the progress.

This is the code that comes with AHK. Chris has modified a bit to make it more robust and general. I will not post my personal version any more, because it is limited to my needs/PC.

;##############################################################################
;#
;#  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-11-14
;#
;#  Tested with: AHK 1.0.40.06, UltraEdit 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
;#            The content of these files is posted further down
;#

; 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|Functions|Keys|Operators|Separators|Special
;Default colors in UE:  blue     |red     |orange   |green    |brown|blue    |blue      |blue

SyntaxExtention = .txt

;#############   END of Customization Area   ##################################

;#############   Ask and Check for valid input  ###############################

RegRead, UeditPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\UEDIT32.exe,Path
IfNotExist, %UeditPath%\uedit32.exe
  {
    UeditPath = %A_ProgramFiles%\UltraEdit
    IfNotExist, %UeditPath%\uedit32.exe
      {
        FileSelectFolder, UeditPath,*%A_ProgramFiles%, 0, Select UltraEdit program-folder
        IfNotExist, %UeditPath%\uedit32.exe
          {
            MsgBox UltraEdit cannot be found.
            ExitApp
          }
      }
  }

UEini = %APPDATA%\IDMComp\UltraEdit\uedit32.ini
IfNotExist, %UEini%
  {
    UEini = %A_WinDir%\uedit32.ini
    IfNotExist, %UEini%
        FileSelectFile, UEini, 1, %A_ProgramFiles%\UltraEdit, Select UltraEdit INI-File, *.ini
  }
IniRead, UEwordfile, %UEini%, Settings, Language File
If UEwordfile = Error
  {
    MsgBox INI-File "%UEini%" is missing the Key "Language File".
    ExitApp
  }

;Search or ask for Wordfile, when it doesn't exist -> exit
UEwordfile = %UeditPath%\wordfile.txt
IfNotExist, %UEwordfile%
  {
    FileSelectFile, UEwordfile, 1, %A_ProgramFiles%, Select UltraEdit wordfile, *.txt
    IfNotExist, %UEwordfile%
      {
        MsgBox, 16,, UltraEdit Wordfile cannot be found.
        ExitApp
      }
  }

; Search or ask for specified syntax folder and files, when they don't exist -> exit
; Get path of AHK Installation so that syntax files can be found more reliably:
RegRead, ahkpath, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
PathSyntaxFiles = %ahkpath%\AutoHotkey\Extras\Editors\Syntax
IfNotExist, %PathSyntaxFiles%
  {
    PathSyntaxFiles = %A_ProgramFiles%\AutoHotkey\Extras\Editors\Syntax
    IfNotExist, %PathSyntaxFiles%
      {
        FileSelectFolder, PathSyntaxFiles, *%A_ProgramFiles%,0, Select Folder "AutoHotkey\Extras\Editors\Syntax"
        IfNotExist, %PathSyntaxFiles%
          {
            MsgBox, 16,, Folder containing syntax files not found.
            ExitApp
          }
      }
  }

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, %UEwordfile%
  {
    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" "Else" ")"`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                       ; Directives

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, %UEwordfile%, %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, %UEwordfile%, %UEwordfile%.ahk.bak, 1    ;Create Backup of current wordfile
FileMove, %TemporaryUEwordFile%, %UEwordfile%, 1       ;Replace wordfile with temporary file

; Tell user what has been done
Question = `n`nWould you like to make UltraEdit the Default editor for AutoHotkey scripts (.ahk files)?
If AHKLanguageFound
    MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
Else
    MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%

IfMsgBox, Yes
    RegWrite, REG_SZ, HKEY_CLASSES_ROOT, AutoHotkeyScript\Shell\Edit\Command,, %UeditPath%\uedit32.exe "`%1"

ExitApp  ; That's it, exit

;#############   SubRoutines   ################################################

ReadSyntaxFromFile:
  TempString =
  Loop, Read , %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention%   ;read syntax file
    {
      StringLeft,Char, A_LoopReadLine ,1
      ;if line is comment, don't bother, otherwise add keyword to string
      If Char <> `;
        {
          ;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   ################################################


The content of the three extra files I use:

;Operators in AHK
%
=
<
>
*
/
+
-

;Separators in AHK
,
** `n `r
|
(
)
{
}

;Special Keywords for highlight in UE
All
AutoSize
bold
BackgroundTrans
cBlue
cDefault
cGreen
cRed
cWhite
is
norm
not
Off
On


Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
@Chris: could please update this script in AHKs distro, thanks.
- I changed the FileSelectFolder options to allow upward navigation.
- Functions are now read from the syntax files as well.
- ( and ) will now cause indent and unindent

The only problem the code currently has, is that it doesn't put the comma from the separator file into the wordfile. I have no clue why.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Thanks for the update; it will go out with the next release.

I put your three text files in the same folder as the installation script (Extras\Editors\UltraEdit). If they should go somewhere else (perhaps a subfolder), please let me know.

I also changed the top line's "syntaxhiglighting" to be "syntax highlighting" ("highlighting" was missing a letter).

Finally, I'm not sure if the following comment should be altered in the distributed version (perhaps it's fine as is): "The content of these files is posted further down".

Thanks.

Tester
  • Members
  • 48 posts
  • Last active: Feb 07 2011 01:34 PM
  • Joined: 06 Jul 2006
Recently I have installed UE 12 and I add some minor improvements to this script.
RegRead, ahkpath, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
if not ahkpath
	SplitPath, A_AhkPath, , ahkpath
PathSyntaxFiles = %ahkpath%\Extras\Editors\Syntax
IfNotExist, %PathSyntaxFiles%
The above corrects issue if user haven't AHK installed by installer (no reg keys).

I put your three text files in the same folder as the installation script (Extras\Editors\UltraEdit). If they should go somewhere else (perhaps a subfolder), please let me know.

It seems that those file should be in Syntax folder (with other definition files).

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Thank you Tester,

As I wrote in the first post

This is the code that comes with AHK. Chris has modified a bit to make it more robust and general. I will not post my personal version any more, because it is limited to my needs/PC.

I'll do not maintain this script (I moved to PSPad). But I guess Chris will take care of this.

Regrading the three extra files: Since these files are very special to this UltraEdit installer, I wouldn't put them in to the general syntax folder, but keep them with the installer script in its own folder.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
Greetings to AHK Community!
Salute Chris, I wish you all the Best!

I'm very satisfied with Key/Mouse Hooking abilities of AutoHotKey. After reading through many posts, I see that the community is very friendly. So, my greetings go to Rajat, Titan, toralf, MsgBox, Veovis, Micha and all other peoples who support, use, contribute, write in AHK!

I already have acknowledged with the syntax of AHK and actually already wrote few scripts, while watching many of contributed scripts, which is very helpful!

So, after bla-bla-bla, here's my first contribution :)
Because my favorite editor is UltraEdit, I have run into some inconveniences in the Functions List Pane, because it listed apart from function definitions, the Function Calls too.

So, here are goes the changes, the updated Function Definition Strings, the maximum I could do to pick out the Function Definitions according to current AHK Language Syntax state:
/Function String 2 = "%[^t ]++^([a-zA-Z0-9дцьЯ#_@^$^?^[^]]+:[~=]^)"
/Function String 3 = "%[^t ]++^(#[a-zA-Z]+*^);++" ;Directives
/Function String 4 = "%[^t ]++;;^(*^)$"
/Function String 5 = "%^([a-zA-Z0-9дцьЯ#_@^$^?^[^]]+[^t ]++(*)^)^{*^p[^t ]++{^}^{*{*$^}"

I have to admit, that the syntax of AHK is a bit cluttered. If there would be a keyword "Function", any editor could have a simple RegExp to filter out Filter Definitions from other Commands/Functions.

First of all, a question to Tekl and toralf. What for are the characters "дцьЯ"?


Remarks

* There's a Limitation in UltraEdit of up to 5 Function String Syntax Definitions.

/Function String 2
...[~=]
Avoiding var:=value to be treated as Functions

/Function String 3 
...+*^);++
Adding whole Line to Functions List, but avoiding Comments

/Function String 4
;;
;; [ Function List Headers as AHK Comments ]
Useful for Long Scripts to unclutter and structurize Items in the Functions List Pane.
This may be changed to your taste.
Take a look at it
Posted Image

/Function String 5 = "%^([a-zA-Z0-9дцьЯ#_@^$^?^[^]]+[^t ]++(*)^)^
Supporting all valid Function Definition representations.
A Function Definition is always embraced in a {block}
All of following examples will be treated as Functions:
fn (par) { ;comments
fn(par){;comments
fn ( par ) ;comments
	{

The only conflict with the Function Definitions is the If() statement, AFAIK.
Because it also uses embraced {blocks}
Currently it is unknown how to eliminate ultimately 100%-ly the If() from being detected.
Although Function Definitions may have leading blanks, to minimize collision with the If(), the RegEx Function Definition String will skip Function Defitions with leading blanks. Almost in 99 cases from 100 the Function Definition starts from Column 1 (from Line Char 1).
As a workaround, to avoid the Ifs to be listed in Functions List, a space can be added before the " If()".

Deciphering the RegExp:
1. %
match SOL (Start Of Line)
2. ^([a-zA-Z0-9#_@^$^?^[^]]+[^t ]++(*)^)
allowing blanks before the function braces ()
3. ^{*^p[^t ]++{^}^{*{*$^}
This one consist from 2 parts:
^{*^p[^t ]++{^} : allowing Comments and allowing OTB
^{*{*$^} : allowing Comments up to EOL

btw, it would be an honor for me to maintain the auto-installer, which was started by Tekl and Toralf.

All The BEST!

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi stevep,

Welcome to the world of AHK

First of all, a question to Tekl and toralf. What for are the characters "дцьЯ"?
[...]
btw, it would be an honor for me to maintain the auto-installer, which was started by Tekl and Toralf.

The characters are the german "äöüß" (Tekl and me are german). Since you have a different system setting it seems to be "дцьЯ".

You are most welcome to maintain this auto-installer. I switched to PSPad, so my desire to maintain this script is low. Please start to modify the script t hat comes with AHK (Run this to install syntax highlighting for UltraEdit.ahk). This will make it easier for Chris to take over the changes you apply.
I suggest you start a new thread with your version of the installer and leave a post in this thread with a link to the new thread. Thanks.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
I'm glad I can be a part of such a programmers work of art.
I'll do my best and then post a link.
Thank You!

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
stevep, thanks for volunteering your time. I'm sure UltraEdit's users will appreciate the improvements you make.

mrinferno
  • Members
  • 10 posts
  • Last active: Apr 13 2010 02:17 PM
  • Joined: 21 Apr 2006
stevep, just wondering if you got around to making the appropriate updates. i just finally installed UltraEdit-32 v12.00b and was looking for the latest & greatest wordfile script.

if not, no biggy. i'll just make the changes manually.

stevenp
  • Members
  • 197 posts
  • Last active: Sep 23 2014 05:47 PM
  • Joined: 28 Aug 2006
I have to sorry. I'm on the deadline with my videoediting job (weddings, birthdays, corp.parties, etc.) and have little or no time to code. I didn't have time to finish the script (btw, it's not only an installer, but also a wordfile.txt manager).
Here's my latest Function Definition strings from wordfile.txt:
/Function String = "%[^t ]++^(:[^*^?BbCcKkOoPpRrZz0-9- ]++:*::^)"
/Function String 1 = "%[^t ]++^([a-zA-Z0-9 #!^+-=^^&<>^*^~^$]+::^)"
/Function String 2 = "%[^t ]++^([a-zA-Z0-9a-yA-?#_@^$^?^[^]]+:[~=]^)"
/Function String 3 = "%[^t ]++^(#[a-zA-Z]+*^);++"
/Function String 4 = "%[^t ]++^{;;^}^{''^}^(*^)$"
/Function String 5 = "%^([a-zA-Z0-9a-yA-?#_@^$^?^[^]]+(^)*)^{*^p[^t ]++{^}^{*{*$^}"

"Simplifying complexity is not simple"

Tester
  • Members
  • 48 posts
  • Last active: Feb 07 2011 01:34 PM
  • Joined: 06 Jul 2006

All of following examples will be treated as Functions:

fn (par) { ;comments
fn(par){;comments
fn ( par ) ;comments
	{

the first and third definitions are wrong - there shoudn't be a space between funtion name and parenthesis.
I think that removing this variants (with space) would be better to see this syntax error while typing.

Reference:

When a function is defined, its parameters are listed in parentheses next to its name (there must be no spaces between its name and the open-parenthesis). If a function should not accept any parameters, leave the parentheses empty; for example: GetCurrentTimestamp().



Unicorn
  • Guests
  • Last active:
  • Joined: --
Try it !! My Wordfile for UltraEdit.
/L20"AutoHotKey" Line Comment = [ Line Comment Valid Columns = [1] Line Comment Alt = ' File Extensions = ahk
/Function String 1 = "^{%[#:]^}^{[^]^-]$^}"
/Function String 2 = "%[^t ]++^(:[^*^?BbCcKkOoPpRrZz0-9- ]++:*::^)"
/Function String 3 = "%[^t ]++^([a-zA-Z0-9 #!^+-=^^&<>^*^~^$]+::^)"
/Function String 4 = "%[^t ]++^([a-zA-Z0-9a-yA-?#_@^$^?^[^]]+:[~=]^)"
/Function String 5 = "%[^t ]++^(#[a-zA-Z]+*^);++"
/Function String 6 = "%[^t ]++^{;;^}^{''^}^(*^)$"
/Function String 7 = "%^([a-zA-Z0-9a-yA-?#_@^$^?^[^]]+(^)*)^{*^p[^t ]++{^}^{*{*$^}"
/C1"Command"
#AllowSameLineComments #ClipboardTimeout #CommentFlag #ErrorStdOut #EscapeChar #HotkeyInterval #HotkeyModifierTimeout #Hotstring #IfWinActive #IfWinExist #Include #InstallKeybdHook #InstallMouseHook #KeyHistory #MaxHotkeysPerInterval #MaxMem #MaxThreads #MaxThreadsBuffer #MaxThreadsPerHotkey #NoEnv #NoTrayIcon #Persistent #SingleInstance #UseHook #WinActivateForce
Alt AutoTrim
BlockInput Break
Click Clipboard ClipWait Continue Control ControlClick ControlFocus ControlGet ControlGetFocus ControlGetPos ControlGetText ControlMove ControlSend ControlSendRaw ControlSetText CoordMode Critical Ctrl
DetectHiddenText DetectHiddenWindows DllCall Drive DriveGet DriveSpaceFree
Edit Else EndRepeat EnvAdd EnvDiv EnvGet EnvMult EnvSet EnvSub EnvUpdate Esc Exit ExitApp
FileAppend FileCopy FileCopyDir FileCreateDir FileCreateShortcut FileDelete FileGetAttrib FileGetShortcut FileGetSize FileGetTime FileGetVersion FileInstall FileMove FileMoveDir FileRead FileReadLine FileRecycle FileRecycleEmpty FileRemoveDir FileSelectFile FileSelectFolder FileSetAttrib FileSetTime FormatTime
Gui GetKeyState Gosub Goto GroupActivate GroupAdd GroupClose GroupDeactivate GuiControl GuiControlGet
HideAutoItWin Hotkey
If IfEqual IfExist IfGreater IfGreaterOrEqual IfInString IfLess IfLessOrEqual IfMsgBox IfNotEqual IfNotExist IfNotInString IfWinActive IfWinExist IfWinNotActive IfWinNotExist ImageSearch InStr IniDelete IniRead IniWrite Input InputBox
KeyHistory KeyWait
LeftClick LeftClickDrag ListHotkeys ListLines ListVars Loop
MButton Menu MouseClick MouseClickDrag MouseGetPos MouseMove MsgBox
Off On OnExit OnMessage OutputDebug
Pause PixelGetColor PixelSearch PostMessage Process Progress
Random RButton Refresh RegDelete RegExMatch RegExReplace RegRead RegWrite Reload Repeat Return RightClick RightClickDrag Run RunAs RunWait
Send SendInput SendMessage SendMode SendPlay SendRaw SetBatchLines SetCapslockState SetControlDelay SetDefaultMouseSpeed SetFormat SetKeyDelay SetMouseDelay SetNumlockState SetScrollLockState SetStoreCapslockMode SetTimer SetTitleMatchMode SetWinDelay SetWorkingDir Shift Shutdown Sleep Sort SoundBeep SoundGet SoundGetWaveVolume SoundPlay SoundSet SoundSetWaveVolume SplashImage SplashTextOff SplashTextOn SplitPath StatusBarGetText StatusBarWait StrLen StringCaseSense StringGetPos StringLeft StringLen StringLower StringMid StringReplace StringRight StringSplit StringTrimLeft StringTrimRight StringUpper SubStr Suspend SysGet
Thread ToolTip Transform TrayTip
URLDownloadToFile
VarSetCapacity
WinActivate WinActivateBottom WinClose WinGet WinGetActiveStats WinGetActiveTitle WinGetClass WinGetPos WinGetText WinGetTitle WinHide WinKill WinMaximize WinMenuSelectItem WinMinimize WinMinimizeAll WinMinimizeAllUndo WinMove WinRestore WinSet WinSetTitle WinShow WinWait WinWaitActive WinWaitClose WinWaitNotActive 



HerbCSO
  • Members
  • 1 posts
  • Last active: Jul 30 2010 02:14 PM
  • Joined: 03 Oct 2009
Don't know if there is a newer thread for this, please point me to it if there is one. I've adapted the script to work for the new UE 15 scheme of separate wordfiles. Still works for the old ones and even works if you're still running with a single wordfile (as is the case by default if you've upgraded). Edited for small script corrections.

;##############################################################################
;#
;#  Add or update syntax highlighting for AutoHotKey scripts in UltraEdit
;#
;#  Mod of a script done by Tekl (although not much has survived)
;#  Mod done by toralf, 2005-11-14
;#  Further mod for UE 15 by HerbCSO, 2009-10-03
;#
;#  Tested with: AHK 1.0.47.06, UltraEdit 15.10.0.1019
;#
;#  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
;#            The content of these files is posted further down
;#

; 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|Functions|Keys|Operators|Separators|Special
;Default colors in UE:  blue     |red     |orange   |green    |brown|blue    |blue      |blue

SyntaxExtention = .txt

;#############   END of Customization Area   ##################################

;#############   Ask and Check for valid input  ###############################

RegRead, UeditPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\UEDIT32.exe,Path
IfNotExist, %UeditPath%\uedit32.exe
  {
    UeditPath = %A_ProgramFiles%\UltraEdit
    IfNotExist, %UeditPath%\uedit32.exe
      {
        FileSelectFolder, UeditPath,*%A_ProgramFiles%, 0, Select UltraEdit program-folder
        IfNotExist, %UeditPath%\uedit32.exe
          {
            MsgBox UltraEdit cannot be found.
            ExitApp
          }
      }
  }

UEini = %APPDATA%\IDMComp\UltraEdit\uedit32.ini
IfNotExist, %UEini%
  {
    UEini = %A_WinDir%\uedit32.ini
    IfNotExist, %UEini%
        FileSelectFile, UEini, 1, %A_ProgramFiles%\UltraEdit, Select UltraEdit INI-File, *.ini
  }
IniRead, UEwordfile, %UEini%, Settings, Language File
If UEwordfile = Error
  {
    MsgBox INI-File "%UEini%" is missing the Key "Language File".
    ExitApp
  }

;Search or ask for Wordfile, when it doesn't exist -> exit
UESeparateWordfiles = false
IfNotExist, %UEwordfile%
  {
    FileSelectFile, UEwordfile, 1, %A_ProgramFiles%, Select UltraEdit wordfile, *.txt
    IfNotExist, %UEwordfile%
      {
        MsgBox, 16,, UltraEdit Wordfile cannot be found.
        ExitApp
      }
  }
FileGetAttrib, Attributes, %UEwordfile%
IfInString, Attributes, D
    UESeparateWordfiles = true
; Discover where AutoHotkey and its related files reside:
RegRead, ahkpath, HKLM, SOFTWARE\AutoHotkey, InstallDir
if (ErrorLevel or not FileExist(ahkpath . "\AutoHotkey.exe"))  ; Not found, so try best-guess instead.
	SplitPath, A_AhkPath,, ahkpath

PathSyntaxFiles = %ahkpath%\AutoHotkey\Extras\Editors\Syntax
IfNotExist, %PathSyntaxFiles%
  {
    PathSyntaxFiles = %A_ProgramFiles%\AutoHotkey\Extras\Editors\Syntax
    IfNotExist, %PathSyntaxFiles%
      {
        FileSelectFolder, PathSyntaxFiles, *%A_ProgramFiles%,0, Select Folder "AutoHotkey\Extras\Editors\Syntax"
        IfNotExist, %PathSyntaxFiles%
          {
            MsgBox, 16,, Folder containing syntax files not found.
            ExitApp
          }
      }
  }

MissingFile =
FileCount = 0
Loop, Parse, SyntaxFileNameList, |
  {
    FileCount += 1
    IfNotExist, %PathSyntaxFiles%\%A_LoopField%%SyntaxExtention%
      {
        IfNotExist, %PathSyntaxFiles%\..\UltraEdit\%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
  }

MaxLanguageNumber = 0
If Not UESeparateWordfiles
  {
    ;Check the number of languages in the current wordfile, if more than 19 without AHK -> exit
    NumberOfLanguages = 0
    Loop, Read, %UEwordfile%
      {
        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
      }
  }
Else
  {
    ;Get list of wordfiles
    UEwordfileList = 
    Loop, %UEwordfile%/*.uew, 0 ;get only wordfiles
      UEwordfileList = %UEwordfileList%%A_LoopFileName%`n
    Loop, parse, UEwordfileList, `n
      {
        Loop, Read, %UEwordfile%/%A_LoopField%
          {
            StringLeft, WFdef, A_LoopReadLine, 2
            If WFDef = /L
              {
                StringSplit, WFname, A_LoopReadLine, "      ;"
                LanguageName = %WFname2%
                LanguageNumber = %WFname1%
                StringTrimLeft,LanguageNumber,LanguageNumber,2
                LanguageNumber += 0
                If (LanguageNumber > MaxLanguageNumber)
                    MaxLanguageNumber = %LanguageNumber%
                If LanguageName = AutoHotkey
                  {
                    UEAutoHotKeyFile = %UEwordfile%/%A_LoopField%
                    UELanguageNumber = %LanguageNumber%
                    Break
                  }
              }
          }
      }
  }
  
;#############   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" "Else" ")"`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-9a-yA-?#_@^$^?^[^]]+:[~=]^)"`n                ; Subroutines
StrgAHKwf = %StrgAHKwf%/Function String 3 = "`%[^t ]++^(#[a-zA-Z]+*^);++"`n                                    ; Functions
StrgAHKwf = %StrgAHKwf%/Function String 4 = "`%[^t ]++^{;;^}^{''^}^(*^)$"`n                                    ; Directives
StrgAHKwf = %StrgAHKwf%/Function String 5 = "`%^([a-zA-Z0-9a-yA-?#_@^$^?^[^]]+(^)*)^{*^p[^t ]++{^}^{*{*$^}"`n  ; ???

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   #####################################

If Not UESeparateWordfiles
  {
    ;Name of a file for temporary store the word file
    TemporaryUEwordFile = TempUEwordFile.txt
    FileDelete, %TemporaryUEwordFile%
   
    Loop, Read, %UEwordfile%, %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, %UEwordfile%, %UEwordfile%.ahk.bak, 1    ;Create Backup of current wordfile
    FileMove, %TemporaryUEwordFile%, %UEwordfile%, 1       ;Replace wordfile with temporary file
  } 
Else
  {
    If UEAutoHotKeyFile Is Space
        UEAutoHotKeyFile = %UEwordfile%/ahk.uew
    FileMove, %UEAutoHotKeyFile%, %UEAutoHotKeyFile%.bak, 1
    If UELanguageNumber Is Space
        UELanguageNumber := MaxLanguageNumber + 1
    FileAppend, /L%UELanguageNumber%%StrgAHKwf%, %UEAutoHotKeyFile%
  }
FileDelete %TemporaryUEwordFile%
; Tell user what has been done
Question = `n`nWould you like to make UltraEdit the Default editor for AutoHotkey scripts (.ahk files)?
If AHKLanguageFound
    MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%
Else
    MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question%

IfMsgBox, Yes
    RegWrite, REG_SZ, HKEY_CLASSES_ROOT, AutoHotkeyScript\Shell\Edit\Command,, %UeditPath%\uedit32.exe "`%1"

ExitApp  ; That's it, exit

;#############   SubRoutines   ################################################

ReadSyntaxFromFile:
  IfNotExist %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention%
    {
      TempSyntaxFile = %PathSyntaxFiles%\..\UltraEdit\%SyntaxFileName%%SyntaxExtention%
    }
  Else
    {
      TempSyntaxFile = %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention%
    }
  TempString =
  Loop, Read , %TempSyntaxFile%   ;read syntax file
    {
      StringLeft,Char, A_LoopReadLine ,1
      ;if line is comment, don't bother, otherwise add keyword to string
      If Char <> `;
        {
          ;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   ################################################

I am going to patent thought. I have yet to see prior art. ;]

entropic
  • Members
  • 181 posts
  • Last active: Nov 27 2011 03:15 AM
  • Joined: 21 Dec 2008
Very nice HerbCSO, thanks!