AutoHotKey源代码换行符

Geo*_*rge 1 autohotkey

有没有办法在AutoHotKey源代码中进行换行?我的代码长度超过80个字符,我希望将它们整齐地分开。我知道我们可以使用其他语言来完成此操作,例如下面的VBA:

http://www.excelforum.com/excel-programming-vba-macros/564301-how-do-i-break-vba-code-into-two-or-more-lines.html

If Day(Date) > 10 _
And Hour(Time) > 20 Then _
MsgBox "It is after the tenth " & _
"and it is evening"
Run Code Online (Sandbox Code Playgroud)

AutoHotKey中是否有源代码换行符?我使用了较旧版本的AutoHotKey,版本1.0.47.06

fxa*_*xam 6

文档中有将长线分割为一系列的短线部分:

长行可以分为一些较小的行,以提高可读性和可维护性。这不会降低脚本的执行速度,因为脚本启动时,这些行就会合并到内存中。

方法#1:以“ and”,“ or”,||,&&,逗号或句点开头的行会自动与其正上方的行合并(在v1.0.46 +中,所有情况都相同除++和-)以外的其他表达式运算符。在下面的示例中,第二行被追加到第一行,因为它以逗号开头:

FileAppend, This is the text to append.`n   ; A comment is allowed here.
    , %A_ProgramFiles%\SomeApplication\LogFile.txt  ; Comment.
Run Code Online (Sandbox Code Playgroud)

同样,以下几行将合并为一行,因为最后两行以“ and”或“ or”开头:

if (Color = "Red" or Color = "Green"  or Color = "Blue"   ; Comment.
    or Color = "Black" or Color = "Gray" or Color = "White")   ; Comment.
    and ProductIsAvailableInColor(Product, Color)   ; Comment. 
Run Code Online (Sandbox Code Playgroud)

三元运算符也是不错的选择:

ProductIsAvailable := (Color = "Red")
    ? false  ; We don't have any red products, so don't bother calling the function.
    : ProductIsAvailableInColor(Product, Color)
Run Code Online (Sandbox Code Playgroud)

尽管以上示例中使用的缩进是可选的,但它可以通过指示哪些行属于其上方的行来提高清晰度。同样,也不必为以“ AND”和“ OR”开头的行添加多余的空格。程序会自动执行此操作。最后,可以在上述示例中的任何行之间或末尾添加空白行或注释。

方法2:此方法应用于合并大量行,或者当这些行不适合方法1时。尽管此方法对于自动替换热字符串特别有用,但它也可以与任何命令或表达式一起使用。例如:

; EXAMPLE #1:
Var = 
(
Line 1 of the text.
Line 2 of the text. By default, a line feed (`n) is present between lines. 
)

; EXAMPLE #2: 
FileAppend,  ; The comma is required in this case. 
(
A line of text. 
By default, the hard carriage return (Enter) between the previous line and this one will be written to the file as a linefeed (`n).
     By default, the tab to the left of this line will also be written to the file (the same is true for spaces).
By default, variable references such as %Var% are resolved to the variable's contents. 
), C:\My File.txt
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,一系列直线在顶部和底部由一对括号界定。这被称为延续部分。请注意,最下面一行包含右括号后的FileAppend的最后一个参数。这种做法是可选的;这样做是为了使逗号将被视为参数定界符,而不是文字逗号。

请阅读文档链接以获取更多详细信息。

因此,您的示例可以重写为以下内容:

If Day(Date) > 10 
And Hour(Time) > 20 Then
    MsgBox
    (
    It is after the tenth 
    and it is evening
    )
Run Code Online (Sandbox Code Playgroud)