Jump to content



Photo

AU3 Syntax Highlight for RichEdit - Updated 3/18/12

syntax highlight

  • Please log in to reply
38 replies to this topic

#1 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 23 May 2011 - 07:50 PM

Last Update - 3/18/2012

Here are a few functions that will take any Autoit code and convert it to RTF format with AutoIt syntax highlighted.
The code can be saved or applied right to the RichEdit control you are working with.

Special thanks go to MrCreator. A good amount of ideas for different parts of the code and regular expressions came from studying his Autoit Syntax Highlight for HTML\BBCode. Viewing how he handled certain situations was very helpful. Thanks to Robjong also for feedback on some of the SRE expressions.

This latest updated was all about speed. With the previous version, it was very slow when dealing with large udfs like Winapi.au3 for example. This new version gets it done in around 13 seconds which I was very happy with. I also broke out all the colors in the RTF color table making them easy to modify if you want. Same with font and font size. One other addition is the update function which can be used to show progress as the conversion is happening.

Please let me know if you have any problems. Thanks


Update: 3/18/12
  • Got more help from Robjong with some of the regular expressions. Thanks again!
  • Fixed crash when loading large file.

Posted Image


Change Log:

Spoiler

Attached File  RESH.zip   17.51KB   245 downloads

Attached File  RESHv2.zip   21.1KB   120 downloads

Attached File  RESHv2.1.zip   22.39KB   155 downloads

Attached File  RESHv2.2.zip   24.44KB   392 downloads


Edited by Beege, 18 March 2012 - 06:13 AM.








#2 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 February 2012 - 10:50 AM

Updated this... because its so popular. :)

#3 guinness

guinness

    guinness

  • MVPs
  • 11,062 posts

Posted 18 February 2012 - 12:14 PM

Very nice indeed. Have you thought about adopting the latest style? (If you don't ask you don't get!)

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#4 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 February 2012 - 12:34 PM

Thanks Guinness.:) Yes I have thought about it. I've been wonder weather I should have preset styles that the user could switch, or create a function that allows them to set the colors to whatever they want. I think just passing an array of hex color values would be easy enough but wasnt sure which route I should go. What do you think?

#5 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,217 posts

Posted 18 February 2012 - 12:42 PM

The regular expression use in this is nutz, awesome work!
Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#6 guinness

guinness

    guinness

  • MVPs
  • 11,062 posts

Posted 18 February 2012 - 12:57 PM

What do you think?

An array should be fine. You've also got me hooked on using associative arrays.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#7 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 18 February 2012 - 01:00 PM

The regular expression use in this is nutz, awesome work!

Thanks

An array should be fine.

Array it is then.

You've also got me hooked on using associative arrays.

Their addicting! It seemed the more I started using them the more situations started poping up that fit them perfectly! Plus their pretty fast! :)

Edited by Beege, 18 February 2012 - 01:07 PM.


#8 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 05:37 PM

Updated with new function to change color table to whatever you want.

#9 guinness

guinness

    guinness

  • MVPs
  • 11,062 posts

Posted 19 February 2012 - 05:52 PM

Updated with new function to change color table to whatever you want.

Sweet! :)

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#10 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 06:41 PM

Thanks!

Before I start writing something, do you have or know of any snippet that will extract the color values from the Scite User Options file?

#11 AZJIO

AZJIO

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,081 posts

Posted 19 February 2012 - 07:09 PM

Beege

Before I start writing something, do you have or know of any snippet that will extract the color values from the Scite User Options file?

"Case $Import" in CreationTheme

([()[]<>.*+-=&^,/]) = ([][()<>.*+=&^,/-])

#12 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 07:59 PM

Thanks AZJIO, I came up with the following:

#include <array.au3> Global $aCurrentColors = _GetCurrentSciteColors() _ArrayDisplay($aCurrentColors) Func _GetCurrentSciteColors($sSciteUserPropPath = '')      If Not $sSciteUserPropPath Then $sSciteUserPropPath = @UserProfileDir & 'SciteUser.properties'      If Not FileExists($sSciteUserPropPath) Then Return SetError(1, 0, 0)      Local $sSciteUserProps = FileRead($sSciteUserPropPath)      If @error Then Return SetError(2,0,0)      Local $aUserColors = StringRegExp($sSciteUserProps, '(?mi)^style.au3.(?:d|10|11|12|13|14|15)=fore:(#[0-9a-f]{6}).*$', 3)      If @error Then Return SetError(3, @error, 0)      Return $aUserColors EndFunc   ;==>_GetCurrentSciteColors


([()[]<>.*+-=&^,/]) = ([][()<>.*+=&^,/-])

Thats partly true but I think some of those characters would need need to be escaped. I would surely think '^' would because thats an operorator for sets.

Edit: Changed expression to more secure version. Thanks AZJIO

Edited by Beege, 19 February 2012 - 08:48 PM.


#13 AZJIO

AZJIO

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,081 posts

Posted 19 February 2012 - 08:16 PM

screenshot

(?mi)^style.au3.(?:)|10|11|12|13|14|15)=fore:#([0-9a-f]{6}).*$

# au3 style.au3.0=fore:#72ADC0   # White space style.au3.1=fore:#71AE71,italics   # Comment line style.au3.2=fore:#71AE71,italics   # Comment block style.au3.3=fore:#C738B9   # Number style.au3.4=fore:#AAA6DB   # Function style.au3.5=fore:#0080FF   # Keyword style.au3.6=fore:#FF46FF   # Macro style.au3.7=fore:#999999   # String style.au3.8=fore:#FF8080   # Operator style.au3.9=fore:#D29A6C   # Variable style.au3.10=fore:#EA9515,bold   # Sent keys style.au3.11=fore:#F000FF   # Pre-Processor style.au3.12=fore:#0080C0   # Special style.au3.13=fore:#7D8AE6,bold   # Abbrev-Expand style.au3.14=fore:#0080FF,bold   # Com Objects style.au3.15=fore:#72ADC0   # Standard UDF's

Edited by AZJIO, 19 February 2012 - 08:25 PM.


#14 guinness

guinness

    guinness

  • MVPs
  • 11,062 posts

Posted 19 February 2012 - 08:21 PM

Beege,

I tried your version of _GetCurrentSciteColors which returned only 2 results. Then I substituted your SRE for AZJIO's and it returned 15, which looking at au3.properties is correct. Nice function by the way, I'll be saving that to my functions folder.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#15 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 08:35 PM

Yup that works too. Only I would need the # included for the new function.

(?mi)^style.au3.(?:)|10|11|12|13|14|15)=fore:(#[0-9a-f]{6}).*$

#16 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 08:39 PM

Beege,

I tried your version of _GetCurrentSciteColors which returned only 2 results. Then I substituted your SRE for AZJIO's and it returned 15, which looking at au3.properties is correct. Nice function by the way, I'll be saving that to my functions folder.

Ya my version is a little two specific. AZJIO's version will be more secure for property files that might have been modified or slightly different in some way. Ill update my previous post.

#17 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 08:56 PM

screenshot

Is that PCRE engine? I'm confused why the doc states:

 Note that special characters do not retain their special meanings inside a set, with the exception of , ^, -,[ and ] match the escaped character inside a set.


#18 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,217 posts

Posted 19 February 2012 - 09:54 PM

I was using the new version and suddenly BAM, right when it was about to load the large UDF into the edit control it gave me this.

Spoiler


I'm on a x86 acer aspire one d250 with win xp if its of any importance.

Edited by THAT1ANONYMOUSEDUDE, 19 February 2012 - 09:56 PM.

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.

#19 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 10:06 PM

The pic you posted is not visible. The code you were trying to highlight is the only thing that might help me figure out what happened..

#20 CaptainClucks

CaptainClucks

    Unum Cavillator Spuria

  • Active Members
  • PipPipPipPipPipPip
  • 1,217 posts

Posted 19 February 2012 - 10:12 PM

Hmm, really? the image isn't visible? damn, I need to find a better site then.

Anyway, the image doesn't matter, what matters is that AutoIt is crashing on my PC when loading anything above about 2k or 3k lines of script, and aside from that, on your 3rd version, It would be nice if we could just copy and past the result as in your second version.

Also, AutoIt is crashing no matter what version I use, but I haven't tried the first file you posted, just v2 and v2.1.

Must be something that has to do with running on a crappy laptop.

Edited by THAT1ANONYMOUSEDUDE, 19 February 2012 - 10:13 PM.

Spoiler
Warning: Posts by this user are subject to change or may disappear without notice.





Also tagged with one or more of these keywords: syntax, highlight

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users