Xojo 2016r1 TAB align comments

In the editor I’m using a monospace font (of course), and from other IDEs I’m used to use the Tab key to move the cursor to the “comment column” so all
my comments appear in the same horiz. location.
Is there a way to do this in Xojo ?

There is a way but it’s not built in. Also I don’t think you’ll be able to use Tab. I only know Mac where a shortcut combo can be setup to trigger it, not sure about other platforms.

So ‘the way’ is an IDE Script which measures the current line and adds spaces to put the comment in your target column. A complication is compensating for how much the line is indented (this info isn’t provided). Also how do you want to handle it if there’s a selection or the insertion cursor isn’t at the end of the line or there’s already a comment.

Here’s a very crude example of such an IDE Script. It does a terrible job identifying indentations, the insertion cursor has to be at the end of the line, and other caveats.

[code] Const CommentColumn = 50 //spaces over to align comment

dim sa(), thisLine As String
sa = Text.Left(SelStart).Split(EndOfLine)
if sa.Ubound = -1 then return

dim indent, i As integer //find indentation of code
for i = 0 to sa.Ubound
if i < sa.Ubound then
if sa(i).Left(3) = "if " then
indent = indent + 1
elseif sa(i).Left(4) = "for " then
indent = indent + 1
elseif sa(i).Left(6) = "while " then
indent = indent + 1
elseif sa(i).left(3) = "do " then
indent = indent + 1
end
end
if sa(i).Left(3) = “end” then
indent = indent - 1
elseif sa(i).Left(4) = “next” then
indent = indent - 1
elseif sa(i).Left(4) = “loop” then
indent = indent - 1
end
next

thisLine = sa(sa.Ubound) //build spaces to add
dim toPad As integer = Max(1, CommentColumn-thisLine.Len-indent)
dim pad As String
dim q As integer
for q = 1 to toPad
pad = pad + " "
next
pad = pad + “//”

dim origStart As integer = SelStart //add spaces to line
SelLength = 0
SelText = pad
SelStart = origStart + pad.Len
SelLength = 0[/code]

To add this IDE Script to Xojo choose File > IDE Script > New IDE Script, paste this code, and save as say ColumnComment. Now when you choose File > IDE Script the ColumnComment item is listed and selecting it applies the script.

On Mac, to associate a shortcut with this item go to System Preferences > Keyboard > Shortcuts > App Shortcuts. Click the + button where you set the Application to Xojo, Menu Title to ColumnComment and the ShortCut. I used Command-U since that seems unused and easy to hit. Now when you go to File > IDE Script ColumnComment has a Shortcut. Just press Command-U and the script runs. All that’s left is rewriting the script :slight_smile: and/or finding a trigger mechanism for Windows or Linux.