- Emacs compiled with treesit support (version 29+)
- Installed powershell treesitter grammar
(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))
For other customizable variables see: powershell-ts-mode customize group
Requires: Emacs 29+, git, C compiler, C++ compiler- M-x treesit-install-language-grammar
- Enter in powershell as your language
- Enter yes to build recipe for powershell interactively
- Enter in the url of the grammar: https://github.com/airbus-cert/tree-sitter-powershell (NOTE: tested with commit: 9d95502e730fb403bdf56279d84630c8178b10be)
- Stick to the defaults for git branch, “src” directory, C compiler, and C++ compilers
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
- Spot missing syntax highlighting/indent rule
- View AST with treesit-explore-mode
- Locate the part that isn’t working
- Add new pattern
- Reload code in powershell-ts-mode.el
M-x revert-buffer
in your file.ps1
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.