|
12 | 12 |
|
13 | 13 | ;;; Code: |
14 | 14 |
|
| 15 | +(defgroup netlinx nil |
| 16 | + "Major mode for NetLinx using tree-sitter." |
| 17 | + :group 'languages |
| 18 | + :prefix "netlinx-") |
| 19 | + |
| 20 | +;; Indentation configuration |
| 21 | +(defcustom netlinx-mode-indent-offset 4 |
| 22 | + "Number of spaces for each indentation step in `netlinx-mode'." |
| 23 | + :type 'integer |
| 24 | + :safe 'integerp |
| 25 | + :group 'netlinx) |
| 26 | + |
| 27 | +(defcustom netlinx-mode-align-argument-list-to-first-sibling nil |
| 28 | + "Align argument lists to the first sibling. |
| 29 | +
|
| 30 | +If set to t, the following indentation is used: |
| 31 | +
|
| 32 | + send_command device, \"'PROPERTY-Name,Value1,Value2,', |
| 33 | + 'Value3'\" |
| 34 | +
|
| 35 | +Otherwise, the indentation is: |
| 36 | +
|
| 37 | + send_command device, \"'PROPERTY-Name,Value1,Value2,', |
| 38 | + 'Value3'\"" |
| 39 | + :type 'boolean |
| 40 | + :safe 'booleanp |
| 41 | + :group 'netlinx) |
| 42 | + |
| 43 | +(defcustom netlinx-mode-align-device-array-to-first-sibling nil |
| 44 | + "Align device array elements to the first sibling. |
| 45 | +
|
| 46 | +If set to t, the following indentation is used: |
| 47 | +
|
| 48 | + dvDevices = { dvPanel1, |
| 49 | + dvPanel2, |
| 50 | + dvPanel3 } |
| 51 | +
|
| 52 | +Otherwise, the indentation is: |
| 53 | +
|
| 54 | + dvDevices = { dvPanel1, |
| 55 | + dvPanel2, |
| 56 | + dvPanel3 }" |
| 57 | + :type 'boolean |
| 58 | + :safe 'booleanp |
| 59 | + :group 'netlinx) |
| 60 | + |
| 61 | +;; Helper function for conditional indentation |
| 62 | +(defun netlinx-mode--indent-argument-list (node parent &rest _) |
| 63 | + "Indent argument list NODE relative to PARENT. |
| 64 | +Uses `netlinx-mode-align-argument-list-to-first-sibling' to determine alignment." |
| 65 | + (if netlinx-mode-align-argument-list-to-first-sibling |
| 66 | + (treesit-node-start (treesit-node-child parent 0)) |
| 67 | + `(parent-bol ,netlinx-mode-indent-offset))) |
| 68 | + |
| 69 | +(defun netlinx-mode--indent-initializer-list (node parent &rest _) |
| 70 | + "Indent initializer list NODE relative to PARENT. |
| 71 | +Uses `netlinx-mode-align-device-array-to-first-sibling' to determine alignment." |
| 72 | + (if netlinx-mode-align-device-array-to-first-sibling |
| 73 | + (treesit-node-start (treesit-node-child parent 0)) |
| 74 | + `(parent-bol ,netlinx-mode-indent-offset))) |
| 75 | + |
15 | 76 | ;; Indentation rules for tree-sitter |
16 | 77 | (defvar netlinx-mode--indent-rules |
17 | 78 | `((netlinx |
|
44 | 105 | ((parent-is "compound_statement") parent-bol netlinx-mode-indent-offset) |
45 | 106 |
|
46 | 107 | ;; Array and struct initializers |
47 | | - ((parent-is "initializer_list") parent-bol netlinx-mode-indent-offset) |
| 108 | + ((parent-is "initializer_list") netlinx-mode--indent-initializer-list) |
48 | 109 |
|
49 | 110 | ;; Parameter lists |
50 | 111 | ((parent-is "parameter_list") parent-bol netlinx-mode-indent-offset) |
51 | | - ((parent-is "argument_list") parent-bol netlinx-mode-indent-offset) |
| 112 | + ((parent-is "argument_list") netlinx-mode--indent-argument-list) |
52 | 113 |
|
53 | 114 | ;; Default: maintain current indentation for other nodes |
54 | 115 | (no-node parent-bol 0))) |
|
0 commit comments