AutoLISP expressions can be formatted to make them easier to read.
You can automatically format select or all AutoLISP expressions in the active editor window. When using the Format Selection and Format Document tools of VS Code, comments are aligned with the statement that follows and open/close parenthesis pairs on different lines are aligned in the same column to help identify balancing parenthesis.
The following shows an example of a custom function before and after being formatted:
(defun CDate ( / ms) ; Check to see which AutoCAD release is being used (if (<= (atof (getvar "ACADVER")) 22.0) (rtos (getvar "CDATE") 2 8) (progn ; Get the current milliseconds and append it to the CDATE value (setq ms (itoa (getvar "MILLISECS"))) (strcat (rtos (getvar "CDATE") 2 6)(substr ms (- (strlen ms) 2))) ) ) )
(defun CDate ( / ms) ; Check to see which AutoCAD release is being used (if (<= (atof (getvar "ACADVER")) 22.0) (rtos (getvar "CDATE") 2 8) (progn ; Get the current milliseconds and append it to the CDATE value (setq ms (itoa (getvar "MILLISECS"))) (strcat (rtos (getvar "CDATE") 2 6)(substr ms (- (strlen ms) 2))) ) ) )
The AutoCAD AutoLISP Extension defines how VS Code should format AutoLISP code statements in an open LSP file. Many of the formatting rules can't be changed, but there are several rules that can be changed based on your preference. The following formatting settings can be changed as part of the extension:
Controls the style of closing parenthesis. A closing parenthesis is placed on the same line as the function or aligned with the function's opening parenthesis.
Controls the format style of long lists. Each or multiple parameters of a function are placed on separate lines.
Suggested maximum number of characters to display on each line. Value must be 60 or greater.
Indentation value used in the Narrow Formatting Style of function arguments. Value must be in the range of 1 and 6.
For information on how to access the format settings of the AutoCAD AutoLISP Extension, see To Format AutoLISP Expressions in the Current Editor Window.