@@ -67,10 +67,13 @@ If set, enables quick access to NetLinx documentation via \\[netlinx-open-help].
6767(add-to-list 'treesit-language-source-alist
6868 `(netlinx , netlinx-mode-grammar-location , netlinx-mode-grammar-version ))
6969
70- ; ; Auto-install grammar if not present
71- (unless (treesit-language-available-p 'netlinx )
72- (message " Installing NetLinx tree-sitter grammar... " )
73- (treesit-install-language-grammar 'netlinx ))
70+ ; ; Auto-install grammar if not present (runs once when mode file is loaded)
71+ (defun netlinx-mode--ensure-grammar ()
72+ " Ensure NetLinx grammar is installed, installing if necessary."
73+ (unless (treesit-language-available-p 'netlinx )
74+ (message " NetLinx: Installing tree-sitter grammar... " )
75+ (treesit-install-language-grammar 'netlinx )
76+ (message " NetLinx: Grammar installation complete " )))
7477
7578; ;; Commands
7679
@@ -91,11 +94,14 @@ The file path is configured via `netlinx-mode-help-file'."
9194 " Major mode for NetLinx."
9295 :group 'netlinx
9396
97+ ; ; Ensure grammar is installed
98+ (netlinx-mode--ensure-grammar)
99+
94100 ; ; Keybindings
95101 (define-key netlinx-mode-map (kbd " C-c C-h" ) #'netlinx-open-help )
96102
97- ; ; Check if the NetLinx grammar is installed
98- (when (treesit-ready-p 'netlinx )
103+ ; ; Check if the NetLinx grammar is installed (t forces fresh check after installation)
104+ (when (treesit-ready-p 'netlinx t )
99105 ; ; Create parser
100106 (treesit-parser-create 'netlinx )
101107
0 commit comments