Emacs mode for editing powershell files using tree-sitter
APACHE-2.0 License
[[https://github.com/dmille56/powershell-ts-mode/actions/workflows/main.yml/badge.svg]]
[[https://i.imgur.com/LHOyls2.png]]
** Config :PROPERTIES: :CUSTOM_ID: config :END: #+BEGIN_SRC emacs-lisp (use-package powershell-ts-mode :straight (:host github :repo "dmille56/powershell-ts-mode") :config ;; Optional: if you want to disable top-level vars from being shown in imenu (setq powershell-ts-enable-imenu-top-level-vars nil)) #+END_SRC
For other customizable variables see: powershell-ts-mode customize group
** Grammar installation instructions :PROPERTIES: :CUSTOM_ID: grammar-installation-instructions :END: Requires: Emacs 29+, git, C compiler, C++ compiler
NOTE: for Windows I had to install GCC in order to compile the grammar.
The pre-built binaries (including tree-sitter-powershell) can be found here https://github.com/kiennq/treesit-langs/releases
Why :PROPERTIES: :CUSTOM_ID: why :END: Powershell-mode has some bugs when dealing with strings (ex: "\home\user") and multi-line comments (ex: "<#/n###>") that made it unusable for me. By using treesitter we're able to get more accurate parsing and syntax highlighting rather then relying on regular expressions to do this which reduces errors.
Development cycle :PROPERTIES: :CUSTOM_ID: development-cycle :END:
NOTE: there are test PowerShell files under ./test-ps-scripts/*.ps1 that can be used to ensure that the new highlighting and indent rules do not break the current expected format.