Author Topic: NOTES: VS Code, AutoLisp Ext, and Git  (Read 1699 times)

0 Members and 1 Guest are viewing this topic.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9719
NOTES: VS Code, AutoLisp Ext, and Git
« on: January 29, 2020, 05:00:15 PM »
EDIT/UPDATES:
  • Added workspace to batch script
  • Added launch.json to batch script

Today I got some time to play around with the AutoLisp extension to VS Code so I thought I'd share some of my notes. I only had enough time to read some documentation, look around a little bit, and do initial setup type stuff (I didn't test any of the "debugging/send to AutoCAD" stuff yet). ..these are also my notes for my future Tutorial(s).

***
Below is my folder structure.
Code: [Select]
projects
    |
    +---doc
    |
    +---lib
    |   |
    |   +---[PROJECT NAME]
    |       |
    |       +---src
    |
    o---tools
        |
        +---[PROJECT NAME]
            |
            +---src


To get started I made a batch script for generating a new project by adding in some basic files and some git initialization. Save the following script code as "new-autolisp-project.bat" in the TOOLS directory. 

When you double click the batch script it will:
1. Ask for a project name.
2. Create files and folders:

Code: [Select]
    |   +---[PROJECT NAME]
    |       |
    |       +---readme.md
    |       |
    |       +---.gitignore
    |       |
    |       +---.git
    |       |
    |       +---[PROJECT NAME].code-workspace
    |       |
    |       +---.vscode
    |       |     |
    |       |     +---tasks.json
    |       |     |
    |       |     +---launch.json
    |       |
    |       +---src
    |       |     |
    |       |     +---[PROJECT NAME].lsp
    |       |

Code - Bash: [Select]
  1. @echo off
  2.  
  3. set /P prjName="What is the name of the project (No spaces)?: "
  4.  
  5. :mkdir
  6. if exist %prjName%\nul goto FolderExists
  7. md %prjName%
  8. md %prjName%\\.vscode
  9. :: md %prjName%\\doc
  10. md %prjName%\\src
  11. ::
  12. :: Lisp File
  13. echo ;; File Last Updated: >> %prjName%\\src\\%prjName%.lsp
  14. echo.>> %prjName%\\src\\%prjName%.lsp
  15. echo.>> %prjName%\\src\\%prjName%.lsp
  16. echo.^(defun %prjName% ^( / *error* ERROR-LST- ^)>> %prjName%\\src\\%prjName%.lsp
  17. echo.   ^(setq>> %prjName%\\src\\%prjName%.lsp
  18. echo.     ERROR-LST->> %prjName%\\src\\%prjName%.lsp
  19. echo.     ^'^("AUTOSNAP" "OSMODE" "APERTURE" "HPSPACE" "HPASSOC">> %prjName%\\src\\%prjName%.lsp
  20. echo.       "MIRRTEXT" "AUPREC" "LUPREC" "DIMZIN" "CECOLOR" "CLAYER">> %prjName%\\src\\%prjName%.lsp
  21. echo.       "CMDECHO" "FILEDIA" "OSMODE"^)>> %prjName%\\src\\%prjName%.lsp
  22. echo.     ERROR-LST- ^(mapcar ^(function ^(lambda ^(a^) ^(list ^'setvar a ^(getvar a^)^)^)^) ERROR-LST-^)>> %prjName%\\src\\%prjName%.lsp
  23. echo.     ^)>> %prjName%\\src\\%prjName%.lsp
  24. echo.   ^(defun *error* ^(msg^)>> %prjName%\\src\\%prjName%.lsp
  25. echo.     ^(command^) ^(command^)>> %prjName%\\src\\%prjName%.lsp
  26. echo.     ^(mapcar ^'eval ERROR-LST-^)^)>> %prjName%\\src\\%prjName%.lsp
  27. echo.    ;;>> %prjName%\\src\\%prjName%.lsp
  28. echo.    ;; Begin Project Code>> %prjName%\\src\\%prjName%.lsp
  29. echo.>> %prjName%\\src\\%prjName%.lsp
  30. echo.    ;;>> %prjName%\\src\\%prjName%.lsp
  31. echo.    ;; End Project Code>> %prjName%\\src\\%prjName%.lsp
  32. echo.  ^(princ^)>> %prjName%\\src\\%prjName%.lsp
  33. echo.^)>> %prjName%\\src\\%prjName%.lsp
  34. ::
  35. :: readme.md
  36. echo.# %prjName%>> %prjName%\\readme.md
  37. echo.>> %prjName%\\readme.md
  38. echo.## BRIEF>> %prjName%\\readme.md
  39. echo.>> %prjName%\\readme.md
  40. echo.One Paragraph of project description goes here.>> %prjName%\\readme.md
  41. echo.>> %prjName%\\readme.md
  42. echo.## DESCRIPTION>> %prjName%\\readme.md
  43. echo.>> %prjName%\\readme.md
  44. echo.A detailed decription of the project goes here.>> %prjName%\\readme.md
  45. echo.>> %prjName%\\readme.md
  46. echo.### GOALS>> %prjName%\\readme.md
  47. echo.>> %prjName%\\readme.md
  48. echo.Describe any goals you tried to achieve by writing this project.>> %prjName%\\readme.md
  49. echo.>> %prjName%\\readme.md
  50. echo.## PREREQUISITES>> %prjName%\\readme.md
  51. echo.>> %prjName%\\readme.md
  52. echo.Describe any other tools/code/projects this project requires.>> %prjName%\\readme.md
  53. echo.>> %prjName%\\readme.md
  54. echo.## RUNNING>> %prjName%\\readme.md
  55. echo.>> %prjName%\\readme.md
  56. echo.Describe how to call/run this code.>> %prjName%\\readme.md
  57. echo.>> %prjName%\\readme.md
  58. echo.```>> %prjName%\\readme.md
  59. echo.example call>> %prjName%\\readme.md
  60. echo.```>> %prjName%\\readme.md
  61. echo.>> %prjName%\\readme.md
  62. echo.## AUTHOR>> %prjName%\\readme.md
  63. echo.>> %prjName%\\readme.md
  64. echo.Your name [your.name@.email.com]>> %prjName%\\readme.md
  65. echo.>> %prjName%\\readme.md
  66. echo.## ACKNOWLEDGMENTS>> %prjName%\\readme.md
  67. echo.>> %prjName%\\readme.md
  68. echo.* Hat tip to anyone whose code was used>> %prjName%\\readme.md
  69. echo.* Inspiration>> %prjName%\\readme.md
  70. echo.* etc>> %prjName%\\readme.md
  71. ::
  72. :: tasks.json
  73. echo.{>> %prjName%\\.vscode\\tasks.json
  74. echo.    "version": "2.0.0",>> %prjName%\\.vscode\\tasks.json
  75. echo.    "tasks": [>> %prjName%\\.vscode\\tasks.json
  76. echo.        {>> %prjName%\\.vscode\\tasks.json
  77. echo.            "label": "package",>> %prjName%\\.vscode\\tasks.json
  78. echo.            "type": "shell",>> %prjName%\\.vscode\\tasks.json
  79. echo.            "command": "git archive -o ..\\%prjName%_archive.zip HEAD",>> %prjName%\\.vscode\\tasks.json
  80. echo.            "group": {>> %prjName%\\.vscode\\tasks.json
  81. echo.                "kind": "build",>> %prjName%\\.vscode\\tasks.json
  82. echo.                "isDefault": true>> %prjName%\\.vscode\\tasks.json
  83. echo.            }>> %prjName%\\.vscode\\tasks.json
  84. echo.        }>> %prjName%\\.vscode\\tasks.json
  85. echo.    ]>> %prjName%\\.vscode\\tasks.json
  86. echo.}>> %prjName%\\.vscode\\tasks.json
  87. ::
  88. :: launch.json
  89. echo.{>> %prjName%\\.vscode\\launch.json
  90. echo.    "version": "0.2.0",>> %prjName%\\.vscode\\launch.json
  91. echo.    "configurations": [>> %prjName%\\.vscode\\launch.json
  92. echo.        {>> %prjName%\\.vscode\\launch.json
  93. echo.            "type": "attachlisp",>> %prjName%\\.vscode\\launch.json
  94. echo.            "request": "attach",>> %prjName%\\.vscode\\launch.json
  95. echo.            "name": "AutoLISP Debug: Attach",>> %prjName%\\.vscode\\launch.json
  96. echo.            "attributes": {>> %prjName%\\.vscode\\launch.json
  97. echo.                "//": "This configuration will load a lisp into a running instance of AutoCAD which is identified before VS Code enters Debug mode",>> %prjName%\\.vscode\\launch.json
  98. echo.                "process": "acad">> %prjName%\\.vscode\\launch.json
  99. echo.            }>> %prjName%\\.vscode\\launch.json
  100. echo.        },>> %prjName%\\.vscode\\launch.json
  101. echo.        {>> %prjName%\\.vscode\\launch.json
  102. echo.            "type": "launchlisp",>> %prjName%\\.vscode\\launch.json
  103. echo.            "request": "launch",>> %prjName%\\.vscode\\launch.json
  104. echo.            "name": "AutoLISP Debug: Launch",>> %prjName%\\.vscode\\launch.json
  105. echo.            "attributes": {>> %prjName%\\.vscode\\launch.json
  106. echo                 "path": "C://Program Files//Autodesk//AutoCAD 2021//acad.exe">> %prjName%\\.vscode\\launch.json
  107. echo.            }>> %prjName%\\.vscode\\launch.json
  108. echo.        }>> %prjName%\\.vscode\\launch.json
  109. echo.    ]>> %prjName%\\.vscode\\launch.json
  110. echo.}>> %prjName%\\.vscode\\launch.json
  111. ::
  112. :: code-workspace
  113. echo.{>> %prjName%\\%prjName%.code-workspace
  114. echo.        "folders": [>> %prjName%\\%prjName%.code-workspace
  115. echo.                {>> %prjName%\\%prjName%.code-workspace
  116. echo.                        "path": ".">> %prjName%\\%prjName%.code-workspace
  117. echo.                }>> %prjName%\\%prjName%.code-workspace
  118. echo.        ],>> %prjName%\\%prjName%.code-workspace
  119. echo.        "settings": {}>> %prjName%\\%prjName%.code-workspace
  120. echo.}>> %prjName%\\%prjName%.code-workspace
  121. echo.;;; VLisp project file [V2.0]>> %prjName%\\%prjName%.prj
  122. echo.(VLISP-PROJECT-LIST >> %prjName%\\%prjName%.prj
  123. echo.  :NAME>> %prjName%\\%prjName%.prj
  124. echo.  %prjName%>> %prjName%\\%prjName%.prj
  125. echo.  :OWN-LIST>> %prjName%\\%prjName%.prj
  126. echo.  (".//src//%prjName%")>> %prjName%\\%prjName%.prj
  127. echo.  :FAS-DIRECTORY>> %prjName%\\%prjName%.prj
  128. echo.  nil>> %prjName%\\%prjName%.prj
  129. echo.  :TMP-DIRECTORY>> %prjName%\\%prjName%.prj
  130. echo.  nil>> %prjName%\\%prjName%.prj
  131. echo.  :PROJECT-KEYS>> %prjName%\\%prjName%.prj
  132. echo.  (:BUILD (:standard))>> %prjName%\\%prjName%.prj
  133. echo.  :CONTEXT-ID>> %prjName%\\%prjName%.prj
  134. echo.  :AUTOLISP>> %prjName%\\%prjName%.prj
  135. echo.)>> %prjName%\\%prjName%.prj
  136. echo.;;; EOF>> %prjName%\\%prjName%.prj
  137. ::
  138. :: .gitignore
  139. echo.# Object files >> %prjName%\\.gitignore
  140. echo.############################## >> %prjName%\\.gitignore
  141. echo.*.o >> %prjName%\\.gitignore
  142. echo.*.ko >> %prjName%\\.gitignore
  143. echo. >> %prjName%\\.gitignore
  144. echo.# Libraries >> %prjName%\\.gitignore
  145. echo.############################## >> %prjName%\\.gitignore
  146. echo.*.com >> %prjName%\\.gitignore
  147. echo.*.lib >> %prjName%\\.gitignore
  148. echo.*.a >> %prjName%\\.gitignore
  149. echo. >> %prjName%\\.gitignore
  150. echo.# Shared objects >> %prjName%\\.gitignore
  151. echo.############################## >> %prjName%\\.gitignore
  152. echo.*.dll >> %prjName%\\.gitignore
  153. echo.*.so >> %prjName%\\.gitignore
  154. echo.*.so.* >> %prjName%\\.gitignore
  155. echo.*.dylib >> %prjName%\\.gitignore
  156. echo. >> %prjName%\\.gitignore
  157. echo.# Executables >> %prjName%\\.gitignore
  158. echo.############################## >> %prjName%\\.gitignore
  159. echo.*.exe >> %prjName%\\.gitignore
  160. echo.*.out >> %prjName%\\.gitignore
  161. echo.*.app >> %prjName%\\.gitignore
  162. echo. >> %prjName%\\.gitignore
  163. echo.# Packages >> %prjName%\\.gitignore
  164. echo.############################## >> %prjName%\\.gitignore
  165. echo.# it's better to unpack these files and commit the raw source >> %prjName%\\.gitignore
  166. echo.# git has its own built in compression methods >> %prjName%\\.gitignore
  167. echo.*.7z >> %prjName%\\.gitignore
  168. echo.*.dmg >> %prjName%\\.gitignore
  169. echo.*.gz >> %prjName%\\.gitignore
  170. echo.*.iso >> %prjName%\\.gitignore
  171. echo.*.jar >> %prjName%\\.gitignore
  172. echo.*.rar >> %prjName%\\.gitignore
  173. echo.*.tar >> %prjName%\\.gitignore
  174. echo.*.zip >> %prjName%\\.gitignore
  175. echo. >> %prjName%\\.gitignore
  176. echo.# Packing-only formats >> %prjName%\\.gitignore
  177. echo.############################## >> %prjName%\\.gitignore
  178. echo.*.iso >> %prjName%\\.gitignore
  179. echo.*.tar >> %prjName%\\.gitignore
  180. echo. >> %prjName%\\.gitignore
  181. echo.# Package management formats >> %prjName%\\.gitignore
  182. echo.############################## >> %prjName%\\.gitignore
  183. echo.*.dmg >> %prjName%\\.gitignore
  184. echo.*.xpi >> %prjName%\\.gitignore
  185. echo.*.gem >> %prjName%\\.gitignore
  186. echo.*.egg >> %prjName%\\.gitignore
  187. echo.*.deb >> %prjName%\\.gitignore
  188. echo.*.rpm >> %prjName%\\.gitignore
  189. echo. >> %prjName%\\.gitignore
  190. echo.# Logs and databases >> %prjName%\\.gitignore
  191. echo.############################## >> %prjName%\\.gitignore
  192. echo.*.log >> %prjName%\\.gitignore
  193. echo.*.sql >> %prjName%\\.gitignore
  194. echo.*.sqlite >> %prjName%\\.gitignore
  195. echo. >> %prjName%\\.gitignore
  196. echo.# OS generated files >> %prjName%\\.gitignore
  197. echo.############################## >> %prjName%\\.gitignore
  198. echo..DS_Store >> %prjName%\\.gitignore
  199. echo..DS_Store? >> %prjName%\\.gitignore
  200. echo.._* >> %prjName%\\.gitignore
  201. echo..Spotlight-V100 >> %prjName%\\.gitignore
  202. echo..Trashes >> %prjName%\\.gitignore
  203. echo.ehthumbs.db >> %prjName%\\.gitignore
  204. echo.Thumbs.db >> %prjName%\\.gitignore
  205. echo. >> %prjName%\\.gitignore
  206. echo.# Local stuff >> %prjName%\\.gitignore
  207. echo.# This section is devoted to this project >> %prjName%\\.gitignore
  208. echo.############################## >> %prjName%\\.gitignore
  209. echo..vscode/*>> %prjName%\\.gitignore
  210. echo..vscode/tasks.json>> %prjName%\\.gitignore
  211. echo..vscode/launch.json>> %prjName%\\.gitignore
  212. echo.*.json>> %prjName%\\.gitignore
  213. echo.*code-workspace>> %prjName%\\.gitignore
  214. echo.*%prjName%.prj>> %prjName%\\.gitignore
  215. call git init %prjName%
  216. cd %prjName%
  217. call git add .gitignore
  218. call git commit -m ".gitignore: Initial commit."
  219. call git add src\\%prjName%.lsp
  220. call git commit -m "%prjName%.lsp: Initial commit."
  221. cd ..
  222. if not exist %prjName%\nul goto FolderNotMade
  223. echo Made folder %prjName%
  224. goto end
  225.  
  226. :FolderExists
  227. echo %prjName% already exists
  228. goto end
  229.  
  230. :FolderNotMade
  231. echo %prjName% could not be made
  232.  
  233. :end
  234. pause

After you run the batch script your folder structure should look like this.

Code: [Select]
projects
    |
    ...
    |
    o---tools
    |   |
    |   +---[PROJECT NAME]
    |       |
    |       +---readme.md
    |       |
    |       +---.gitignore
    |       |
    |       +---.git
    |       |
    |       +---[PROJECT NAME].code-workspace
    |       |
    |       +---.vscode
    |       |     |
    |       |     +---tasks.json
    |       |     |
    |       |     +---launch.json
    |       |
    |       +---src
    |       |     |
    |       |     +---[PROJECT NAME].lsp
    |       |


Now open VS Code and "Open Folder"
Now open VS Code and "Open Workspace"

Navigate to the [PROJECT NAME] folder.

In VS Code, press Ctrl+Shift+B to create an archive of your project.
« Last Edit: July 16, 2021, 12:08:58 PM by John Kaul (Se7en) »
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

togores

  • Mosquito
  • Posts: 10
Re: NOTES: VS Code, AutoLisp Ext, and Git
« Reply #1 on: August 02, 2020, 05:47:15 PM »
I would suggest also defining a Workspace for your project. Then you could use Open Workspace... instead of Open Folder...
It would be better as you could use a multi-root Workspace if code is stored in different folders.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9719
Re: NOTES: VS Code, AutoLisp Ext, and Git
« Reply #2 on: July 16, 2021, 12:12:54 PM »
Updated the batch script in the first post to add/create a workspace and a launch.json.

This project-setup-script is very nice now and VS Code works great with lisp. So far I can see VS code replacing the VLIDE.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9719
Re: NOTES: VS Code, AutoLisp Ext, and Git
« Reply #3 on: July 20, 2021, 12:15:31 PM »
Here is a link to the VS Code editors keyboard shortcuts.

[ https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf ]
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

MickD

  • Gator
  • Posts: 3498
  • (x-in)->[process]->(y-out)
Re: NOTES: VS Code, AutoLisp Ext, and Git
« Reply #4 on: July 20, 2021, 05:42:09 PM »
Here is a link to the VS Code editors keyboard shortcuts.

[ https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf ]

What...no Vim bindings plugin John?? :)

I use it in VS Code and it works fine for the most part.
For git and command line I use the built in terminal and standard git commands, Ctrl+` on my box toggles the terminal window in the project folder, very handy :)
Forth is like the Tao: it is a Way, and is realized when followed.
Its fragility is its strength; its simplicity is its direction - Michael Ham

"First, solve the problem. Then, write the code." John Johnson

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9719
Re: NOTES: VS Code, AutoLisp Ext, and Git
« Reply #5 on: July 20, 2021, 11:16:04 PM »
haha. No but I've thought about your REPL slime thing several times the last few months (and wondered if I could even fathom or begin to understand enough to work on that). I have always thought most lispers would be far better off with Emacs (Vim yes of course, but Emacs I thought would be the easier sell because of it's lisp backend).

I prefer git on the command line as well (I really hate using a mouse when I'm coding).

This effort was to get the AutoLisp developers up to speed for the switch from the VLIDE to VS Code. Hopefully VS Code gets them a better environment to develop in (the VLIDE is horrible!). I've really tried to make it as easy as I could; setting up the project files, directory structure, and json files with that batch script saves tons of time!
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org