Jump to content

SciTE4AutoIt - Highlighting expandable variables and macros inside strings


Recommended Posts

This question is to those familiar with the SciTE4AutoIt lexer and highlighting functionality. Currently, when there is a string with a sendkey keyword, highlighting works perfectly well for the keyword. It shows up as a different color inside the string.
 

$string = "send this {ENTER} key"

What I would like is for variables and macros inside strings to be highlighted as well, since often use Opt("ExpandVarStrings", 1). Here is what I would like it to look like (or similar):

$string = "expand this $variable$ or @macro@"

I have already tried adding all the macros (with the extra @ on the end) to Embedded.properties under keywords4.$(file.patterns.au3) and au3.keywords.properties under au3.keywords.sendkeys. However, neither addition changed the fact that something like @DesktopDir@ was not highlighted inside a string.

Who else would I be?
Link to comment
Share on other sites

You could just use the variables in the usual way without bothering with the ExpandVarStrings option at all, then it would be colored the way you want without having to change anything other than adding a couple of & and quotes around your strings and variables.

; this
$string = "expand this $variable$ or @macro@"
; becomes this
$string = "expand this " & $variable  or @macro

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I imagine the lexer looks for { and } inside of a string and then looks for one of those keywords.  The lexer would have to be extended to look for $ and @.

Or what BrewManNH said ^^^^^^^^^^^^^^^^^^^^

Edited by jaberwacky
Link to comment
Share on other sites

Come on, BrewManNH, that's no help. Just because you might not use ExpandVarStrings, please don't tell me to abandon a feature that is useful for me. That's just ridiculous. That's like telling you not to use the forum if questions come up that you don't want to answer.

@jaberwacky, I thought the same way in the beginning, but it's not like that. If you type "hello {world}" into SciTE, {world} is not highlighted. Also, I used Agent Ransack to look through all the files in the SciTE directory and see if a curly brace { was being used as some kind of identifier. I came up with nothing.

Who else would I be?
Link to comment
Share on other sites

  • Developers

Come on, BrewManNH, that's no help. Just because you might not use ExpandVarStrings, please don't tell me to abandon a feature that is useful for me. That's just ridiculous. That's like telling you not to use the forum if questions come up that you don't want to answer.

@jaberwacky, I thought the same way in the beginning, but it's not like that. If you type "hello {world}" into SciTE, {world} is not highlighted. Also, I used Agent Ransack to look through all the files in the SciTE directory and see if a curly brace { was being used as some kind of identifier. I came up with nothing.

The lexer checks for keywords defined for au3.keywords.sendkeys in the au3.keywords.properties, and it uses the logic as jaberwacky described.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos, then is there something internally that causes it not to look at @---@, where it will look at {---}? I ask because I added all the macros as would be seen inside expandable strings to that list in au3.keywords.sendkeys, and they were not changed.

EDIT: When you say lexer, do you mean something as a part of SciTE -the program- that might not be changeable?

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

  • Developers

@Jos, then is there something internally that causes it not to look at @---@, where it will look at {---}?

Yes, It isn't implemented. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok, got it. Now that I know, I am assuming that by changing just some files in the SciTE folder, I cannot affect this change. If I understand correctly, I would need to know the source code for SCLEX_AU3 and rebuild SciTE with the functionality I want, right?

Who else would I be?
Link to comment
Share on other sites

  • Developers

Ok, got it. Now that I know, I am assuming that by changing just some files in the SciTE folder, I cannot affect this change. If I understand correctly, I would need to know the source code for SCLEX_AU3 and rebuild SciTE with the functionality I want, right?

correct, but your only issue will be that I haven't submitted the LexAU3.cxx updates to Neil for about 7 years and have made a bunch of modifications in the SciTE version we publish which aren't publicly available.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

In that case, I believe a request is in order. Would you be so kind (as the maintainer of such functionality), to add this feature in an upcoming version of SciTE4AutoIt3? I don't really care about the coloring of the macros and variables, but I do want them to stand out inside the strings.

Who else would I be?
Link to comment
Share on other sites

Maybe allow Jos to reply on whether it's a worthy feature, because he's the one who will be implementing since he has access to the lexer.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_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()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_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()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Developers

In that case, I believe a request is in order. Would you be so kind (as the maintainer of such functionality), to add this feature in an upcoming version of SciTE4AutoIt3? I don't really care about the coloring of the macros and variables, but I do want them to stand out inside the strings.

The macro recognition could be possible, but the variable not really as there is no table of known variablenames to check against.

I am also not much of a fan of this ExpandVarStrings option either and am also not so sure this is a benefit for the larger scripting community.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Come on, BrewManNH, that's no help. Just because you might not use ExpandVarStrings, please don't tell me to abandon a feature that is useful for me. That's just ridiculous. That's like telling you not to use the forum if questions come up that you don't want to answer.

What does that option give to you that not having it would impact you? How is it more useful to you than using an ampersand and quotes? Is it worth not having syntax highlighting just to keep using it? Just some questions you need to ask yourself rather than lashing out at a valid suggestion.

As to your analogy, you need to work on it, because it's a silly comparison.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH, Yes, keeping the feature is worth not having syntax highlighting for me. Highlighting would be icing on the cake in this circumstance.

As for the analogy, it was intended to show how I felt about your suggestion instead of how valid your suggestion is. If you want an analogy that shows how valid your suggestion is, then a person should not use StringAddCR("string"), because it's also just as valid to do a StringReplace("string", @LF, @CRLF). Also, we should not use StringIsAlNum or StringIsAlpha or StringIsASCII or StringIsDigit or StringIsFloat or StringIsInt or any other StringIs---- because we have StringRegExp that can perform all of those functions (as long as someone is familiar with regular expressions). However, for a person unfamiliar with regular expressions, they would be lost.

The reason for having string manipulation functions and Opts is for ease of coding and ease of reading code, or to prevent errors. Personally, I find it difficult to code with concatenation ampersands, quotes, line continuation underscores, etc. They increase the likelihood for coding errors in my circumstances. However, I am able to code faster and with less errors when using ExpandVarStrings. It is much less time consumed in creating long strings with many variables and macros to add an @ sign or $ at the end instead of " &  & ". That's 8 characters typed with concatenation versus 1 character added for ExpandVarStrings. In the course of multi-day coding sessions, that can add up to (perhaps) hours of extra typing.

Who else would I be?
Link to comment
Share on other sites

  • Developers

The reason for having string manipulation functions and Opts is for ease of coding and ease of reading code, or to prevent errors. Personally, I find it difficult to code with concatenation ampersands, quotes, line continuation underscores, etc. They increase the likelihood for coding errors in my circumstances. However, I am able to code faster and with less errors when using ExpandVarStrings. It is much less time consumed in creating long strings with many variables and macros to add an @ sign or $ at the end instead of " &  & ". That's 8 characters typed with concatenation versus 1 character added for ExpandVarStrings. In the course of multi-day coding sessions, that can add up to (perhaps) hours of extra typing.

Have to disagree as au3check will not do any checking when using ExpandVarStrings, were using concatenation it will report any typo.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Personally, I find that code is more readable when I can see that $variable is supposed to be a variable called $variable, rather than as part of a string. But, that's just my personal preference, I wasn't telling you to not use it, I was making a suggestion as to what you should do to get those variables to stand out in your text editor. 

Also, I SERIOUSLY doubt that 4 extra characters per variable name  is going to save hours of typing unless you type really really slowly. BTW, I say 4 rather than 8, because you don't need the space before or after the ampersand.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 3 weeks later...

"I wasn't telling you to not use it"

@BrewManNH, In order to be perfectly clear, your suggestion was exactly that. It was to suggest coding without using the ExpandVarStrings feature, so that my variables would stand out.

Who else would I be?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...