aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodor Thornhill2022-11-25 21:04:18 +0100
committerStefan Kangas2022-11-26 01:57:39 +0100
commit7fc0eae28f03601e25e2a60030ae2dc59085c6d2 (patch)
tree9a7974cbb3823ec222b912346fed8cadd23bbc9d
parent0a8e724e37c96f7082fe17d7ab50cd86a073ccd8 (diff)
downloademacs-7fc0eae28f03601e25e2a60030ae2dc59085c6d2.tar.gz
emacs-7fc0eae28f03601e25e2a60030ae2dc59085c6d2.zip
Rename ts-mode to typescript-ts-mode
* lisp/progmodes/typescript-ts-mode.el: Rename from 'ts-mode' to 'typescript-ts-mode'. Rename all symbols to match new prefix. * etc/NEWS: Mention the new mode name. Ref: https://lists.gnu.org/r/emacs-devel/2022-11/msg01587.html
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/progmodes/typescript-ts-mode.el78
2 files changed, 40 insertions, 40 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 0ffc849feca..3c9243784de 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2969,7 +2969,7 @@ This is a lightweight variant of 'js-mode' that is used by default
2969when visiting JSON files. 2969when visiting JSON files.
2970 2970
2971 2971
2972** New mode 'ts-mode'. 2972** New mode 'typescript-ts-mode'.
2973A major mode based on the tree-sitter library for editing programs 2973A major mode based on the tree-sitter library for editing programs
2974in the TypeScript language. It includes support for font-locking, 2974in the TypeScript language. It includes support for font-locking,
2975indentation, and navigation. 2975indentation, and navigation.
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index bdef1c45765..763686bf660 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -1,4 +1,4 @@
1;;; ts-mode.el --- tree sitter support for TypeScript -*- lexical-binding: t; -*- 1;;; typescript-ts-mode.el --- tree sitter support for TypeScript -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2022 Free Software Foundation, Inc. 3;; Copyright (C) 2022 Free Software Foundation, Inc.
4 4
@@ -30,14 +30,14 @@
30 30
31(declare-function treesit-parser-create "treesit.c") 31(declare-function treesit-parser-create "treesit.c")
32 32
33(defcustom ts-mode-indent-offset 2 33(defcustom typescript-ts-mode-indent-offset 2
34 "Number of spaces for each indentation step in `ts-mode'." 34 "Number of spaces for each indentation step in `typescript-ts-mode'."
35 :version "29.1" 35 :version "29.1"
36 :type 'integer 36 :type 'integer
37 :safe 'integerp 37 :safe 'integerp
38 :group 'typescript) 38 :group 'typescript)
39 39
40(defvar ts-mode--syntax-table 40(defvar typescript-ts-mode--syntax-table
41 (let ((table (make-syntax-table))) 41 (let ((table (make-syntax-table)))
42 ;; Taken from the cc-langs version 42 ;; Taken from the cc-langs version
43 (modify-syntax-entry ?_ "_" table) 43 (modify-syntax-entry ?_ "_" table)
@@ -54,9 +54,9 @@
54 (modify-syntax-entry ?` "\"" table) 54 (modify-syntax-entry ?` "\"" table)
55 (modify-syntax-entry ?\240 "." table) 55 (modify-syntax-entry ?\240 "." table)
56 table) 56 table)
57 "Syntax table for `ts-mode'.") 57 "Syntax table for `typescript-ts-mode'.")
58 58
59(defvar ts-mode--indent-rules 59(defvar typescript-ts-mode--indent-rules
60 `((tsx 60 `((tsx
61 ((parent-is "program") parent-bol 0) 61 ((parent-is "program") parent-bol 0)
62 ((node-is "}") parent-bol 0) 62 ((node-is "}") parent-bol 0)
@@ -65,33 +65,33 @@
65 ((node-is ">") parent-bol 0) 65 ((node-is ">") parent-bol 0)
66 ((and (parent-is "comment") comment-end) comment-start -1) 66 ((and (parent-is "comment") comment-end) comment-start -1)
67 ((parent-is "comment") comment-start-skip 0) 67 ((parent-is "comment") comment-start-skip 0)
68 ((parent-is "ternary_expression") parent-bol ts-mode-indent-offset) 68 ((parent-is "ternary_expression") parent-bol typescript-ts-mode-indent-offset)
69 ((parent-is "member_expression") parent-bol ts-mode-indent-offset) 69 ((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset)
70 ((parent-is "named_imports") parent-bol ts-mode-indent-offset) 70 ((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset)
71 ((parent-is "statement_block") parent-bol ts-mode-indent-offset) 71 ((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset)
72 ((parent-is "type_arguments") parent-bol ts-mode-indent-offset) 72 ((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
73 ((parent-is "variable_declarator") parent-bol ts-mode-indent-offset) 73 ((parent-is "variable_declarator") parent-bol typescript-ts-mode-indent-offset)
74 ((parent-is "arguments") parent-bol ts-mode-indent-offset) 74 ((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
75 ((parent-is "array") parent-bol ts-mode-indent-offset) 75 ((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
76 ((parent-is "formal_parameters") parent-bol ts-mode-indent-offset) 76 ((parent-is "formal_parameters") parent-bol typescript-ts-mode-indent-offset)
77 ((parent-is "template_substitution") parent-bol ts-mode-indent-offset) 77 ((parent-is "template_substitution") parent-bol typescript-ts-mode-indent-offset)
78 ((parent-is "object_pattern") parent-bol ts-mode-indent-offset) 78 ((parent-is "object_pattern") parent-bol typescript-ts-mode-indent-offset)
79 ((parent-is "object") parent-bol ts-mode-indent-offset) 79 ((parent-is "object") parent-bol typescript-ts-mode-indent-offset)
80 ((parent-is "object_type") parent-bol ts-mode-indent-offset) 80 ((parent-is "object_type") parent-bol typescript-ts-mode-indent-offset)
81 ((parent-is "enum_body") parent-bol ts-mode-indent-offset) 81 ((parent-is "enum_body") parent-bol typescript-ts-mode-indent-offset)
82 ((parent-is "arrow_function") parent-bol ts-mode-indent-offset) 82 ((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset)
83 ((parent-is "parenthesized_expression") parent-bol ts-mode-indent-offset) 83 ((parent-is "parenthesized_expression") parent-bol typescript-ts-mode-indent-offset)
84 84
85 ;; TSX 85 ;; TSX
86 ((parent-is "jsx_opening_element") parent ts-mode-indent-offset) 86 ((parent-is "jsx_opening_element") parent typescript-ts-mode-indent-offset)
87 ((node-is "jsx_closing_element") parent 0) 87 ((node-is "jsx_closing_element") parent 0)
88 ((parent-is "jsx_element") parent ts-mode-indent-offset) 88 ((parent-is "jsx_element") parent typescript-ts-mode-indent-offset)
89 ((node-is "/") parent 0) 89 ((node-is "/") parent 0)
90 ((parent-is "jsx_self_closing_element") parent ts-mode-indent-offset) 90 ((parent-is "jsx_self_closing_element") parent typescript-ts-mode-indent-offset)
91 (no-node parent-bol 0))) 91 (no-node parent-bol 0)))
92 "Tree-sitter indent rules.") 92 "Tree-sitter indent rules.")
93 93
94(defvar ts-mode--keywords 94(defvar typescript-ts-mode--keywords
95 '("!" "abstract" "as" "async" "await" "break" 95 '("!" "abstract" "as" "async" "await" "break"
96 "case" "catch" "class" "const" "continue" "debugger" 96 "case" "catch" "class" "const" "continue" "debugger"
97 "declare" "default" "delete" "do" "else" "enum" 97 "declare" "default" "delete" "do" "else" "enum"
@@ -103,14 +103,14 @@
103 "while" "with" "yield") 103 "while" "with" "yield")
104 "TypeScript keywords for tree-sitter font-locking.") 104 "TypeScript keywords for tree-sitter font-locking.")
105 105
106(defvar ts-mode--operators 106(defvar typescript-ts-mode--operators
107 '("=" "+=" "-=" "*=" "/=" "%=" "**=" "<<=" ">>=" ">>>=" "&=" "^=" 107 '("=" "+=" "-=" "*=" "/=" "%=" "**=" "<<=" ">>=" ">>>=" "&=" "^="
108 "|=" "&&=" "||=" "??=" "==" "!=" "===" "!==" ">" ">=" "<" "<=" "+" 108 "|=" "&&=" "||=" "??=" "==" "!=" "===" "!==" ">" ">=" "<" "<=" "+"
109 "-" "*" "/" "%" "++" "--" "**" "&" "|" "^" "~" "<<" ">>" ">>>" 109 "-" "*" "/" "%" "++" "--" "**" "&" "|" "^" "~" "<<" ">>" ">>>"
110 "&&" "||" "!" "?.") 110 "&&" "||" "!" "?.")
111 "TypeScript operators for tree-sitter font-locking.") 111 "TypeScript operators for tree-sitter font-locking.")
112 112
113(defvar ts-mode--font-lock-settings 113(defvar typescript-ts-mode--font-lock-settings
114 (treesit-font-lock-rules 114 (treesit-font-lock-rules
115 :language 'tsx 115 :language 'tsx
116 :override t 116 :override t
@@ -128,7 +128,7 @@
128 :language 'tsx 128 :language 'tsx
129 :override t 129 :override t
130 :feature 'keyword 130 :feature 'keyword
131 `([,@ts-mode--keywords] @font-lock-keyword-face 131 `([,@typescript-ts-mode--keywords] @font-lock-keyword-face
132 [(this) (super)] @font-lock-keyword-face) 132 [(this) (super)] @font-lock-keyword-face)
133 133
134 :language 'tsx 134 :language 'tsx
@@ -248,7 +248,7 @@
248 248
249 :language 'tsx 249 :language 'tsx
250 :feature 'operator 250 :feature 'operator
251 `([,@ts-mode--operators] @font-lock-operator-face 251 `([,@typescript-ts-mode--operators] @font-lock-operator-face
252 (ternary_expression ["?" ":"] @font-lock-operator-face)) 252 (ternary_expression ["?" ":"] @font-lock-operator-face))
253 253
254 :language 'tsx 254 :language 'tsx
@@ -278,19 +278,19 @@
278 "Tree-sitter font-lock settings.") 278 "Tree-sitter font-lock settings.")
279 279
280;;;###autoload 280;;;###autoload
281(add-to-list 'auto-mode-alist '("\\.ts\\'" . ts-mode)) 281(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
282 282
283;;;###autoload 283;;;###autoload
284(add-to-list 'auto-mode-alist '("\\.tsx\\'" . ts-mode)) 284(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-ts-mode))
285 285
286;;;###autoload 286;;;###autoload
287(define-derived-mode ts-mode prog-mode "TypeScript" 287(define-derived-mode typescript-ts-mode prog-mode "TypeScript"
288 "Major mode for editing TypeScript." 288 "Major mode for editing TypeScript."
289 :group 'typescript 289 :group 'typescript
290 :syntax-table ts-mode--syntax-table 290 :syntax-table typescript-ts-mode--syntax-table
291 291
292 (cond 292 (cond
293 ;; `ts-mode' requires tree-sitter to work, so we don't check if 293 ;; `typescript-ts-mode' requires tree-sitter to work, so we don't check if
294 ;; user enables tree-sitter for it. 294 ;; user enables tree-sitter for it.
295 ((treesit-ready-p 'tsx) 295 ((treesit-ready-p 'tsx)
296 ;; Tree-sitter. 296 ;; Tree-sitter.
@@ -308,7 +308,7 @@
308 (append "{}():;," electric-indent-chars)) 308 (append "{}():;," electric-indent-chars))
309 309
310 ;; Indent. 310 ;; Indent.
311 (setq-local treesit-simple-indent-rules ts-mode--indent-rules) 311 (setq-local treesit-simple-indent-rules typescript-ts-mode--indent-rules)
312 312
313 ;; Navigation. 313 ;; Navigation.
314 (setq-local treesit-defun-type-regexp 314 (setq-local treesit-defun-type-regexp
@@ -318,7 +318,7 @@
318 "lexical_declaration"))) 318 "lexical_declaration")))
319 319
320 ;; Font-lock. 320 ;; Font-lock.
321 (setq-local treesit-font-lock-settings ts-mode--font-lock-settings) 321 (setq-local treesit-font-lock-settings typescript-ts-mode--font-lock-settings)
322 (setq-local treesit-font-lock-feature-list 322 (setq-local treesit-font-lock-feature-list
323 '((comment declaration) 323 '((comment declaration)
324 (constant expression identifier keyword number string) 324 (constant expression identifier keyword number string)
@@ -336,6 +336,6 @@
336 (js-mode) 336 (js-mode)
337 (message "Tree-sitter for TypeScript isn't available, falling back to `js-mode'")))) 337 (message "Tree-sitter for TypeScript isn't available, falling back to `js-mode'"))))
338 338
339(provide 'ts-mode) 339(provide 'typescript-ts-mode)
340 340
341;;; ts-mode.el ends here 341;;; typescript-ts-mode.el ends here