|
17 | 17 |
|
18 | 18 | ;;; Code: |
19 | 19 |
|
20 | | -(require 'treesit) |
21 | | - |
22 | | -;; Ensure font-lock file can be loaded |
23 | | -(eval-and-compile |
24 | | - (let ((dir (file-name-directory (or load-file-name buffer-file-name)))) |
25 | | - (add-to-list 'load-path dir))) |
26 | | - |
27 | | -(require 'netlinx-mode-font-lock) |
28 | | - |
29 | | -(declare-function treesit-parser-create "treesit.c") |
30 | | -(declare-function treesit-node-type "treesit.c") |
31 | | - |
32 | | -(defgroup netlinx nil |
33 | | - "Major mode for NetLinx using tree-sitter." |
34 | | - :group 'languages |
35 | | - :prefix "netlinx-") |
36 | | - |
37 | | -(defcustom netlinx-mode-grammar-location |
38 | | - "https://github.com/Norgate-AV/tree-sitter-netlinx" |
39 | | - "Repository URL for the tree-sitter NetLinx grammar." |
40 | | - :type 'string |
41 | | - :group 'netlinx) |
42 | | - |
43 | | -;; Add grammar source on load |
44 | | -(add-to-list 'treesit-language-source-alist |
45 | | - '(netlinx "https://github.com/Norgate-AV/tree-sitter-netlinx")) |
46 | | - |
47 | | -(defun netlinx-mode--ensure-grammar () |
48 | | - "Ensure NetLinx grammar is installed, installing if necessary." |
49 | | - (unless (treesit-language-available-p 'netlinx) |
50 | | - (message "NetLinx: Installing tree-sitter grammar (this may take a minute)...") |
51 | | - (treesit-install-language-grammar 'netlinx) |
52 | | - (message "NetLinx: Grammar installation complete"))) |
53 | | - |
54 | 20 | ;;;###autoload |
55 | 21 | (define-derived-mode netlinx-mode prog-mode "NetLinx" |
56 | 22 | "Major mode for editing NetLinx files with tree-sitter support." |
57 | 23 | :group 'netlinx |
58 | 24 |
|
59 | | - ;; Install grammar if needed |
60 | | - (netlinx-mode--ensure-grammar) |
61 | | - |
62 | 25 | (if (treesit-ready-p 'netlinx t) |
63 | 26 | (progn |
64 | 27 | ;; Create parser |
|
76 | 39 | (treesit-major-mode-setup)) |
77 | 40 | (message "NetLinx: tree-sitter grammar not available. Check *Messages* for errors."))) |
78 | 41 |
|
79 | | -;;;###autoload |
80 | | -(add-to-list 'auto-mode-alist '("\\.axs\\'" . netlinx-mode)) |
81 | | - |
82 | | -;;;###autoload |
83 | | -(add-to-list 'auto-mode-alist '("\\.axi\\'" . netlinx-mode)) |
84 | | - |
85 | | -(provide 'netlinx-mode) |
86 | | - |
87 | 42 | ;;; netlinx-mode.el ends here |
0 commit comments