home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 October - Disc 3 / PCNET_CD_2006_10_3.iso / apps / AutoHotkey104411_Install.exe / Extras / Run this to install syntax highlighting for ConTEXT.ahk < prev    next >
Encoding:
Text File  |  2006-08-31  |  9.3 KB  |  340 lines

  1. ; Installs AutoHotkey syntax highlighting for the ConTEXT editor.
  2. ;
  3. ; Created by foom
  4. ; Color theme is based on the UnrealScript highlighter found on:
  5. ; http://wiki.beyondunreal.com/wiki/ConTEXT/UnrealScript
  6. ; Which itself resembles the highlighting syntax/theme of the UScript Editor in UnrealEd⌐ by Epic Games Inc.
  7. ;
  8. ; Report Problems at:
  9. ; http://www.autohotkey.com/forum/topic10895.html
  10. ;
  11. ; August 29, 2006
  12. ; - Initial release.
  13.  
  14. SetBatchLines -1
  15. #SingleInstance
  16.  
  17. ; Discover where AutoHotkey and its related files reside:
  18. RegRead, AhkDir, HKLM, SOFTWARE\AutoHotkey, InstallDir
  19. if (ErrorLevel or not FileExist(AhkDir . "\AutoHotkey.exe"))  ; Not found, so try best-guess instead.
  20.     SplitPath, A_AhkPath,, AhkDir
  21.  
  22. ; Get path to ConTEXT:
  23. RegRead, contextDir, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\Applications\ConTEXT.exe\shell\edit\command
  24. if contextDir
  25.     SplitPath, contextDir,, contextDir  ; This removes the following string from the end: \ConTEXT.exe "%1"
  26. else  ; Try a best-guess location.
  27.     contextDir = %A_ProgramFiles%\ConTEXT
  28. IfNotExist, %contextDir%
  29.     Gosub, selectcontextdir
  30.  
  31. ;Do not edit the settings below. You might, but don't! Edit the settings in ConTEXT instead. You've been warned.
  32. highlightsettings=
  33. (
  34. Language:            AutoHotkey
  35. Filter:              AutoHotkey (*.ahk)|*.ahk
  36. HelpFile:            %AhkDir%\AutoHotkey.chm
  37. CaseSensitive:       0
  38. LineComment:         ;
  39.  
  40. //dont use blockcomments, context blockcomments are not ahk conform
  41. BlockCommentBeg:
  42. BlockCommentEnd:
  43.  
  44. IdentifierBegChars:  a..z A..Z _#
  45. IdentifierChars:     a..z A..Z _# 0..9
  46. NumConstBegChars:    0..9
  47. NumConstChars:       0..9 .abcdefhABCDEFH
  48.  
  49. EscapeChar:          `
  50. StringBegChar:       "
  51. StringEndChar:       "
  52. MultilineStrings:    0
  53. UsePreprocessor:     0
  54. CurrLineHighlighted: 1
  55.  
  56. SpaceCol:            clWhite $00400000
  57. Keyword1Col:         clAqua $00400000
  58. Keyword2Col:         clWhite $00320000 B
  59. Keyword3Col:         $00FFBC79 $00400000
  60. Keyword4Col:         clWhite $00620000
  61.  
  62. // clAqua $00400000
  63. Keyword5Col:         $00FFC0C0 $00400000
  64. IdentifierCol:       clWhite $00400000
  65. CommentCol:          $00909090 $00410000
  66. NumberCol:           clWhite $00400000
  67. StringCol:           clLime $00400000
  68. SymbolCol:           clWhite $00400000
  69.  
  70. // clGray $00400000
  71. PreprocessorCol:     $00FFC0C0 $00400000
  72. SelectionCol:        $00400000 $00BFFFFF
  73. CurrentLineCol:      clWhite $00600000
  74. MatchedBracesCol:    clYellow $00400000
  75.  
  76. OverrideTxtFgColor:  0
  77. BlockAutoindent:     1
  78. BlockBegStr:         {
  79. BlockEndStr:         }
  80.  
  81. )
  82.  
  83. commandstxt=%ahkdir%\extras\editors\syntax\commands.txt
  84. commandnamestxt=%ahkdir%\extras\editors\syntax\commandnames.txt
  85. functionstxt=%ahkdir%\extras\editors\syntax\functions.txt
  86. variablestxt=%ahkdir%\extras\editors\syntax\variables.txt
  87. keystxt=%ahkdir%\extras\editors\syntax\keys.txt
  88. keywordstxt=%ahkdir%\extras\editors\syntax\keywords.txt
  89.  
  90. AutoHotkeyctpl=%ahkdir%\extras\editors\syntax\AutoHotkey.ctpl
  91. AutoHotkeychl =%ahkdir%\extras\editors\syntax\AutoHotkey.chl
  92.  
  93.  
  94.  
  95. if (!FileExist(commandstxt) or !FileExist(functionstxt) or !FileExist(variablestxt) or !FileExist(keywordstxt) or !FileExist(keystxt) or !FileExist(commandnamestxt))
  96. {
  97.     MsgBox,16,Error, Couldn't find syntax files. Exiting.
  98.     exitapp
  99. }
  100.  
  101. Gosub, deletefiles
  102.  
  103. Loop, Read, %commandstxt%
  104. {
  105.     Command=
  106.     Desc=
  107.     Out=%A_LoopReadLine%
  108.     parse_template(Command, Desc, Out)
  109.     
  110.     loop
  111.     {
  112.         if command in %commandlist%
  113.             command:=command . "_"
  114.         else
  115.             break
  116.     }
  117.  
  118.     if commandlist
  119.         commandlist:=commandlist . "," . Command
  120.     else
  121.         commandlist:=command
  122.  
  123.     FullOut=[%Command% | %Desc%]`n%Out%`n`r`n
  124.     ahktemplate=%ahktemplate%%FullOut%
  125. }
  126.  
  127. commandlist=
  128.  
  129. Loop, Read, %functionstxt%
  130. {
  131.     Command=
  132.     Desc=
  133.     Out=%A_LoopReadLine%
  134.     parse_template(Command, Desc, Out)
  135.  
  136.     loop
  137.     {
  138.         if command in %commandlist%
  139.             command:=command . "_"
  140.         else
  141.             break
  142.     }
  143.  
  144.     if commandlist
  145.         commandlist:=commandlist . "," . Command
  146.     else
  147.         commandlist:=command
  148.  
  149.     FullOut=[%Command% | %Desc%]`n%Out%`n`r`n
  150.     ahktemplate=%ahktemplate%%FullOut%
  151. }
  152.  
  153. commandlist=
  154.  
  155. Loop, Read, %variablestxt%
  156. {
  157.     Command=
  158.     Desc=
  159.     Out=%A_LoopReadLine%
  160.     parse_template(Command, Desc, Out)
  161.  
  162.     FullOut=[%Command% | A_BuildInVariable]`n%Out%`n`r`n
  163.     ahktemplate=%ahktemplate%%FullOut%
  164. }
  165.  
  166. FileAppend, %ahktemplate%, %AutoHotkeyctpl%
  167.  
  168.  
  169.  
  170. ahkchl=
  171.  
  172. ;functions
  173. FileRead, syntaxfile, %functionstxt%
  174. ahkchl:="KeyWords1:" . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;,`n") . "`n`n"
  175.  
  176. ;commandnames (no preprozessor)
  177. FileRead, syntaxfile, %commandnamestxt%
  178. ahkchl:=ahkchl . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;,`n","#",0) . "`n`n"
  179.  
  180. ;keys
  181. FileRead, syntaxfile, %keystxt%
  182. ahkchl:=ahkchl . "KeyWords2:" . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;,`n") . "`n`n"
  183.  
  184. ;keywords
  185. FileRead, syntaxfile, %keywordstxt%
  186. ahkchl:=ahkchl . "KeyWords3:" . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;,`n") . "`nforce`n`n`n"
  187.  
  188. ;built-in variables
  189. FileRead, syntaxfile, %variablestxt%
  190. ahkchl:=ahkchl . "KeyWords4:" . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;,`n") . "`n`n"
  191.  
  192. ;commandnames (only preprozessor)
  193. FileRead, syntaxfile, %commandnamestxt%
  194. ahkchl:=ahkchl . "KeyWords5:" . parse_hl(syntaxfile,",,,%a_space,%a_tab%,(,[,{,;","#",1) . "`n`n"
  195.  
  196. ahkchl:=highlightsettings . "`n`n" . ahkchl 
  197.  
  198. FileAppend, %ahkchl%, %AutoHotkeychl%
  199.  
  200.  
  201. if FileExist(contextDir . "\Template\AutoHotkey.ctpl")
  202. {
  203.     MsgBox,36,Warning,%contextDir%\Template\AutoHotkey.ctpl already exists. Overwrite that file?
  204.     IfMsgBox, No
  205.         FileCopy, %AutoHotkeyctpl%, %contextDir%\Template\AutoHotkey.ctpl, 0
  206.     IfMsgBox, Yes
  207.         FileCopy, %AutoHotkeyctp%, %contextDir%\Template\AutoHotkey.ctpl, 1
  208. }
  209. else
  210.     FileCopy, %AutoHotkeyctpl%, %contextDir%\Template\AutoHotkey.ctpl, 0
  211.  
  212. if FileExist(contextDir . "\Highlighters\AutoHotkey.chl")
  213. {
  214.     MsgBox,36,Warning,%contextDir%\Highlighters\AutoHotkey.chl already exists. Overwrite that file?
  215.     IfMsgBox, No
  216.         FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 0
  217.     IfMsgBox, Yes
  218.         FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 1
  219. }
  220. else
  221.     FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 0
  222.  
  223. exit:
  224.     gosub, deletefiles
  225.     MsgBox AutoHotkey syntax highlighting for ConTEXT has been successfully installed.
  226.     exitapp
  227. return
  228.  
  229. selectcontextdir:
  230.     FileSelectFolder, contextDir ,,0, Select the folder ConTEXT is installed in.
  231.     if errorlevel
  232.         goto exit
  233.     
  234.     if !FileExist(contextDir . "\conTEXT.exe")
  235.     {
  236.         msgbox,18,Error,This is not the folder context is installed in. Install anyway? ;`n.Abort - Exit.`nRetry - Select again.`nIgnore - Install files anyway.`n
  237.         IfMsgBox, Abort
  238.             goto exit
  239.         IfMsgBox, Retry
  240.             goto selectcontextdir
  241.         IfMsgBox, Ignore
  242.         {
  243.             FileCreateDir, %contextDir%\Template
  244.             FileCreateDir, %contextDir%\Highlighters
  245.         }
  246.     }
  247. return
  248.  
  249. deletefiles:
  250.     if FileExist(autohotkeyctpl)
  251.         FileDelete, %autohotkeyctpl%
  252.     if FileExist(autohotkeychl)
  253.         FileDelete, %autohotkeychl%
  254. return
  255.  
  256. parse_hl(file,lastcharlist,firstcharlist="",bIfFirstChar=0 )
  257. {
  258.     Loop, Parse, file, `n, `n
  259.     {
  260.         firstword=
  261.         Loop, Parse, A_LoopField
  262.         {
  263.             if (firstcharlist and a_index = 1)
  264.             {
  265.                 if bIfFirstChar
  266.                 {
  267.                     if a_loopfield not in %firstcharlist%
  268.                         break
  269.                 }
  270.                 else if !bIfFirstChar
  271.                 {
  272.                     if a_loopfield in %firstcharlist%
  273.                         break
  274.                 }
  275.  
  276.             }
  277.             if A_LoopField not in %lastcharlist%
  278.                 firstword=%firstword%%A_LoopField%
  279.             else
  280.                 break
  281.         }
  282.     if firstword
  283.     out=%out%`n%firstword%
  284.     }
  285.     return out
  286. }
  287.  
  288. parse_template(ByRef Command, ByRef Desc, ByRef Out)
  289. {
  290.     Loop, parse, Out
  291.     {
  292.     
  293.         if bDesc
  294.         {
  295.             if (A_LoopField = "|")
  296.                 Desc:=Desc . " or "
  297.             else if (A_LoopField = "[" or a_loopfield = "]")
  298.                 continue
  299.             else if A_LoopField = {        ;,},`t
  300.                       Desc:=Desc . "("
  301.             else if A_LoopField = }        ;,},`t
  302.                       Desc:=Desc . ")"
  303.             else if A_LoopField = %a_tab%        ;,},`t
  304.                       Desc:=Desc . "  "
  305.             else if A_loopfield = ``
  306.             {
  307.                       prevloopfield:=a_loopfield
  308.                       continue
  309.             }
  310.             else if (A_loopfield = "n" and prevloopfield = "``")
  311.                       continue
  312.             else
  313.                 Desc:=Desc . A_LoopField
  314.             
  315.             prevloopfield:=a_loopfield
  316.  
  317.             continue
  318.         }
  319.         
  320.         if (A_LoopField = "," OR A_LoopField = " " OR A_LoopField = "(")
  321.         {
  322.         bDesc=1
  323.         Desc:=Desc . A_LoopField
  324.         }
  325.         
  326. ;         MsgBox, % Command . a_loop Field
  327.         if !bDesc
  328.             Command=%Command%%A_LoopField%
  329.     ;   MsgBox, 4, , File number %A_Index% is %A_LoopField%.`n`nContinue?
  330.     ;   IfMsgBox, No, break
  331.     }
  332.     StringReplace, Out, Out, | ,%a_space%or%a_space%, All
  333.     StringReplace, Out, Out,[,, All
  334.     StringReplace, Out, Out,],, All
  335.     StringReplace, Out, Out,{,(, All
  336.     StringReplace, Out, Out,},), All
  337.     StringReplace, Out, Out,%a_tab%,%a_space%%a_space%, All
  338.     StringReplace, Out, Out,``n,, All
  339. }
  340.