Goodies 21: Comment Links

At the dotfmp conference 2022 we got a nice idea for a feature: MBS FileMaker Plugin already scans script lines to find missing variables and show a little warning for undeclared variables. We added the feature to scan for comments containing URLs. If we find an URL, we add a little button to the end of the line, which currently shows an arrow and a globe:

You may click on the line to select it and then click on the control we add. Maybe double click works directly. But only if the list of script steps doesn't consume the click, it will come to our control.

You can configure this feature using our preferences dialog or the SyntaxColoring.CommentLinks.SetEnabled function, so you can turn it on and off via script if needed.

Available since version 12.3 for FileMaker Pro on macOS.

As a little detail, the globe checks which time zone you are and shows either 🌍 for Europe and Africa, 🌎 for the Americas and 🌏 for Asian.

Goto and Script scheme

This may change how you write scripts: Your longer scripts may now have an index on top with goto: URLs jumping to specific lines. The goto:start and goto:end links may help to jump to start or end of the script. And script: links may jump to a different script.

 

Let's start with script links. You put in the script name after the script: prefix. The plugin will read the name, decode percent escaped sequences and looks for a script in same file with the given name to show it. If you have special characters in the script name, please use GetAsURLEncoded() function in FileMaker to get the URL encoded properly, e.g. with %20 for spaces. This may look like this in the script:

 

# We open the database connection in the Connect to database script 

# See also script:Close%20database ➜🌍  

#

Perform Script [ Specified: From list ; “Connect to database” ; Parameter:    ]

#

Set Variable [ $result; Value: Get(ScriptResult) ]

 

 

And you may include goto: URLs in the comments. For example you can just put in a number to jump to a line. This allows you to jump from the top of the script right into the action below without scrolling yourself. Just like you would do an index page in a big PDF to jump to the right page. You can also use goto:end to jump to the end of the script. For performance reasons you may want to collect comments on the bottom of the script. Jumping from top to the bottom would scroll all the way down to show these comments. You can do a goto:start to jump back to the first line.

 

# Description Test Script

# Author Christian

# History on the bottom goto:end ➜🌍 

Allow User Abort [ Off ]

Set Error Capture [ On ]

Set Variable [ $param ; Value: Get(ScriptParameter) ] 

# do something useful

# loop counting up from 1 to $count

Set Variable [ $count ; Value: 100 ] 

Set Variable [ $index ; Value: 1 ] 

If [ $index ≤ $count ] 

Loop [ Flush: Always ]

# your script steps here

# next

Set Variable [ $index ; Value: $index + 1 ] 

Exit Loop If [ $index > $count ] 

End Loop

End If

Set Variable [ $result ; Value: "" ] 

Exit Script [ Text Result: $result ] 

# back to top: goto:start ➜🌍 

#  Version History

# Modified 30th October 2023 by Christian

# * added more comments

# * added loop in line 15   goto:15 ➜🌍 

# Created 30th October 2023 by Christian

# * first version

 

If you start using these links in your scripts, you may enjoy easier navigation on macOS in the Script Workspace. Available for macOS since MBS Plugin version 13.5.

You can enable comment links via preferences dialog or with the SyntaxColoring.CommentLinks.SetEnabled function.


Code Folding 21 Links for MBS