File tree 3 files changed +39
-2
lines changed
3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -220,18 +220,25 @@ Returns a modified copy of the rule list."
220
220
Returns a modified copy of the rule list."
221
221
(electric-operator--add-rule-list initial new-rules))
222
222
223
+ (defun electric-operator--convert-treesitter-mode (major-mode-symbol )
224
+ " Convert a treesitter mode name to the equivalent regular mode"
225
+ (let ((mode-string (symbol-name major-mode-symbol)))
226
+ (if (string-match-p " -ts-mode" mode-string)
227
+ (intern (replace-regexp-in-string " -ts-mode" " -mode" mode-string))
228
+ major-mode-symbol)))
229
+
223
230
224
231
; ; All rule manipulation should be done through these functions and not by
225
232
; ; using puthash/gethash directly because it's plausible that the
226
233
; ; underlying data structure could be changed (e.g. to an alist).
227
234
228
235
(defun electric-operator-get-rules-for-mode (major-mode-symbol )
229
236
" Get the spacing rules for major mode"
230
- (electric-operator--trie-get-all (electric-operator-get-rules-trie-for-mode major-mode-symbol)))
237
+ (electric-operator--trie-get-all (electric-operator-get-rules-trie-for-mode (electric-operator--convert-treesitter-mode major-mode-symbol) )))
231
238
232
239
(defun electric-operator-get-rules-trie-for-mode (major-mode-symbol )
233
240
" Get the spacing rules for major mode"
234
- (gethash major-mode-symbol electric-operator--mode-rules-table))
241
+ (gethash (electric-operator--convert-treesitter-mode major-mode-symbol) electric-operator--mode-rules-table))
235
242
236
243
(defun electric-operator-add-rules-for-mode (major-mode-symbol &rest new-rules )
237
244
" Replace or add spacing rules for major mode
Original file line number Diff line number Diff line change @@ -261,3 +261,11 @@ Feature: C basic operators
261
261
Scenario : Multiplication with pointer deref
262
262
When I type "result = foo * *bar"
263
263
Then I should see "result = foo * *bar"
264
+
265
+ # We can't test this yet because emacs doesn't ship with treesitter grammars
266
+ # and there's no easy way to install them.
267
+ @known-failure
268
+ Scenario : Treesitter mode just works
269
+ When I turn on c-ts-mode
270
+ When I type "a-b"
271
+ Then I should see "a - b"
Original file line number Diff line number Diff line change @@ -62,6 +62,28 @@ Aenean in sem ac leo mollis blandit. xyz /=" trie) " /= "))
62
62
(should (equal (electric-operator--trie-get-all trie)
63
63
(nreverse '(" * " (" 1" " 2" " 3" ) " 6" " xyz" " bar" ))))))
64
64
65
+ (ert-deftest rules-for-treesitter-modes ()
66
+ (should (equal
67
+ (electric-operator--convert-treesitter-mode 'c-mode )
68
+ 'c-mode ))
69
+
70
+ (should (equal
71
+ (electric-operator--convert-treesitter-mode 'c-ts-mode )
72
+ 'c-mode ))
73
+
74
+ (should (equal
75
+ (electric-operator--convert-treesitter-mode 'ts-mode )
76
+ 'ts-mode ))
77
+
78
+ (should (equal
79
+ (electric-operator--convert-treesitter-mode 'erts-mode )
80
+ 'erts-mode ))
81
+
82
+ (should (equal
83
+ (electric-operator--convert-treesitter-mode 'tsx-ts-mode )
84
+ 'tsx-mode ))
85
+
86
+ )
65
87
66
88
; ; Local Variables:
67
89
; ; nameless-current-name: "electric-operator"
You can’t perform that action at this time.
0 commit comments