20200308 1604
자료 = “https://www.autohotkey.com/docs/Scripts.htm#continuation”
Splitting a Long Line into a Series of Shorter Ones Long lines can be divided up into a collection of smaller ones to improve readability and maintainability. This does not reduce the script's execution speed because such lines are merged in memory the moment the script launches. Method #1: A line that starts with "and", "or", ||, &&, a comma, or a period is automatically merged with the line directly above it (in v1.0.46+, the same is true for all other expression operators except ++ and --). In the following example, the second line is appended to the first because it begins with a comma: FileAppend, This is the text to append.`n ; A comment is allowed here. , %A_ProgramFiles%\SomeApplication\LogFile.txt ; Comment. S↓ Similarly, the following lines would get merged into a single line because the last two start with "and" or "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. S↓ The ternary operator is also a good candidate: ProductIsAvailable := (Color = "Red") ? false ; We don't have any red products, so don't bother calling the function. : ProductIsAvailableInColor(Product, Color) S↓ Although the indentation used in the examples above is optional, it might improve clarity by indicating which lines belong to ones above them. Also, it is not necessary to include extra spaces for lines starting with the words "AND" and "OR"; the program does this automatically. Finally, blank lines or comments may be added between or at the end of any of the lines in the above examples. Method #2: This method should be used to merge a large number of lines or when the lines are not suitable for Method #1. Although this method is especially useful for auto-replace hotstrings, it can also be used with any command or expression. For example: ; EXAMPLE #1: Var = ( Line 1 of the text. Line 2 of the text. By default, a linefeed (`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 S↓ In the examples above, a series of lines is bounded at the top and bottom by a pair of parentheses. This is known as a continuation section. Notice that the bottom line contains FileAppend's last parameter after the closing parenthesis. This practice is optional; it is done in cases like this so that the comma will be seen as a parameter-delimiter rather than a literal comma. The default behavior of a continuation section can be overridden by including one or more of the following options to the right of the section's opening parenthesis. If more than one option is present, separate each one from the previous with a space. For example: ( LTrim Join| %. Join: Specifies how lines should be connected together. If this option is omitted, each line except the last will be followed by a linefeed character (`n). If the word Join is specified by itself, lines are connected directly to each other without any characters in between. Otherwise, the word Join should be followed immediately by as many as 15 characters. For example, Join`s would insert a space after each line except the last ("`s" indicates a literal space -- it is a special escape sequence recognized only by Join). Another example is Join`r`n, which inserts CR+LF between lines. Similarly, Join| inserts a pipe between lines. To have the final line in the section also ended by a join-string, include a blank line immediately above the section's closing parenthesis. Known limitation: If the Join string ends with a colon, it must not be the last option on the line. For example, (Join: is treated as the label "(Join" and (LTrim Join: is unsupported, but (Join: C is okay. LTrim: Omits spaces and tabs at the beginning of each line. This is primarily used to allow the continuation section to be indented. Also, this option may be turned on for multiple continuation sections by specifying #LTrim on a line by itself. #LTrim is positional: it affects all continuation sections physically beneath it. The setting may be turned off via #LTrim Off. RTrim0 (RTrim followed by a zero): Turns off the omission of spaces and tabs from the end of each line. Comments (or Comment or Com or C) [v1.0.45.03+]: Allows semicolon comments inside the continuation section (but not /*..*/). Such comments (along with any spaces and tabs to their left) are entirely omitted from the joined result rather than being treated as literal text. Each comment can appear to the right of a line or on a new line by itself. % (percent sign): Treats percent signs as literal rather than as variable references. This avoids the need to escape each percent sign to make it literal. This option is not needed in places where percent signs are already literal, such as auto-replace hotstrings. , (comma): Treats commas as delimiters rather than as literal commas. This rarely-used option is necessary only for the commas between command parameters because in function calls, the type of comma does not matter. Also, this option transforms only those commas that actually delimit parameters. In other words, once the command's final parameter is reached (or there are no parameters), subsequent commas are treated as literal commas regardless of this option. ` (accent): Treats each backtick character literally rather than as an escape character. This also prevents commas and percent signs from being explicitly and individually escaped. In addition, it prevents the translation of any explicitly specified escape sequences such as `r and `t. ) [v1.1.01+]: If a closing parenthesis appears in the continuation section's options (except as a parameter of the Join option), the line is reinterpreted as an expression instead of the beginning of a continuation section. This allows expressions like (x.y)[z]() to work without the need to escape the opening parenthesis. Remarks Escape sequences such as `n (linefeed) and `t (tab) are supported inside the continuation section except when the accent (`) option has been specified. When the comment option is absent, semicolon and /*..*/ comments are not supported within the interior of a continuation section because they are seen as literal text. However, comments can be included on the bottom and top lines of the section. For example: FileAppend, ; Comment. ; Comment. ( LTrim Join ; Comment. ; This is not a comment; it is literal. Include the word Comments in the line above to make it a comment. ), C:\File.txt ; Comment. As a consequence of the above, semicolons never need to be escaped within a continuation section. A continuation section cannot produce a line whose total length is greater than 16,383 characters (if it tries, the program will alert you the moment the script is launched). One way to work around this is to do a series of concatenations into a variable. For example: Var = ( ... ) Var = %Var%`n ; Add more text to the variable via another continuation section. ( ... ) FileAppend, %Var%, C:\My File.txt S↓ Since a closing parenthesis indicates the end of a continuation section, to have a line start with literal closing parenthesis, precede it with an accent/backtick: `). A continuation section can be immediately followed by a line containing the open-parenthesis of another continuation section. This allows the options mentioned above to be varied during the course of building a single line. The piecemeal construction of a continuation section by means of #Include is not supported.
|
'[PA] 업무자동화 > [AH]Autohotkey' 카테고리의 다른 글
AH 엑셀열기 without Excel (0) | 2020.04.07 |
---|---|
AH 정리하세요 (0) | 2020.03.29 |
AH Persistent의 이해 (0) | 2020.03.29 |
AH 화면설정 정보 얻기 (0) | 2020.03.29 |
AH SciTE4 사용법 (0) | 2020.03.29 |