Code snippets are stored in the snippets.json file that is part of the AutoCAD AutoLISP Extension; you can add new or edit existing code snippets to improve your efficiency when writing AutoLISP programs. The snippets.json file is written in JSON and supports C-style comments. Each code snippet should contain the following attributes:
- name – A unique name for the code snippet; used if no description is provided
- prefix – Defines the name to be typed and displayed in the IntelliSense list to insert the code snippet
- body – Expressions that define the code snippet, can contain new lines, tabs, and placeholders
- description – Defines the text that should be displayed in the IntelliSense tooltip for the code snippet
The following shows the basic definition of a code snippet:
"ifprogn": { "prefix": "ifp", "body": [ "(if (${1:testexpr})", "\t(progn", "\t\t(${2:thenexpr})", "\t)", ")" ], "description": "if progn expression" }
- In Visual Studio Code or another text editor, open the
snippets.json file.
Based on your OS, the snippets.json file can be found in one of these locations:
- Windows – %USERPROFILE%\.vscode\extensions\autodesk.autolispext-n.n.n\snippets
- Mac OS – ~/.vscode/extensions/autodesk.autolispext-n.n.n/snippets
Note: n.n.n in the previous paths is a placeholder, the actual version of the AutoCAD AutoLISP Extension will vary over time as the extension is updated. - In the
snippets.json file, add your new code snippet or change an existing one.
Note: Be careful about where you insert new text or which text you change, the formatting of the file is critical to it being properly parsed.
- Save the snippets.json file and test the code snippet changes.