summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/c-ts-mode.el18
-rw-r--r--lisp/progmodes/csharp-mode.el10
-rw-r--r--lisp/progmodes/java-ts-mode.el10
-rw-r--r--lisp/progmodes/js.el9
-rw-r--r--lisp/progmodes/typescript-ts-mode.el11
-rw-r--r--lisp/treesit.el18
6 files changed, 45 insertions, 31 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 086257483e8..a79dabcd312 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -29,7 +29,7 @@
;;; Code:
(require 'treesit)
-(require 'rx)
+(eval-when-compile (require 'rx))
(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
@@ -545,10 +545,13 @@ the subtrees."
;; Comments.
(setq-local comment-start "/* ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end " */")
- (setq-local treesit-comment-start (rx "/" (or (+ "/") (+ "*"))))
- (setq-local treesit-comment-end (rx (+ (or "*")) "/"))
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
(setq-local treesit-simple-indent-rules
(c-ts-mode--set-indent-style 'c))
@@ -568,8 +571,13 @@ the subtrees."
;; Comments.
(setq-local comment-start "// ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "")
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
(treesit-parser-create 'cpp)
diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3f691956f8f..6712fcc57e2 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -36,7 +36,8 @@
(require 'treesit)
(eval-when-compile
- (require 'cc-fonts))
+ (require 'cc-fonts)
+ (require 'rx))
(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
@@ -888,8 +889,13 @@ Key bindings:
;; Comments.
(setq-local comment-start "// ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "")
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
;; Indent.
(setq-local treesit-simple-indent-rules csharp-ts-mode--indent-rules)
diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el
index dd3d6d31e02..cf2482bb6ee 100644
--- a/lisp/progmodes/java-ts-mode.el
+++ b/lisp/progmodes/java-ts-mode.el
@@ -29,6 +29,7 @@
;;; Code:
(require 'treesit)
+(eval-when-compile (require 'rx))
(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
@@ -299,10 +300,13 @@ the subtrees."
;; Comments.
(setq-local comment-start "// ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "")
- (setq-local treesit-comment-start (rx "/" (or (+ "/") (+ "*"))))
- (setq-local treesit-comment-end (rx (+ (or "*")) "/"))
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
;; Indent.
(setq-local treesit-simple-indent-rules java-ts-mode--indent-rules)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index f2016deb5d8..ad1fe62d429 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3848,11 +3848,14 @@ Currently there are `js-mode' and `js-ts-mode'."
(setq-local which-func-imenu-joiner-function #'js--which-func-joiner)
;; Comment.
(setq-local comment-start "// ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "")
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
(setq-local comment-multi-line t)
- (setq-local treesit-comment-start (rx "/" (or (+ "/") (+ "*"))))
- (setq-local treesit-comment-end (rx (+ (or "*")) "/"))
;; Electric-indent.
(setq-local electric-indent-chars
(append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds "[]*".
diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 8a9d540bd3c..bf483a31d34 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -25,8 +25,8 @@
;;; Code:
(require 'treesit)
-(require 'rx)
(require 'js)
+(eval-when-compile (require 'rx))
(declare-function treesit-parser-create "treesit.c")
@@ -294,10 +294,13 @@
;; Comments.
(setq-local comment-start "// ")
- (setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
(setq-local comment-end "")
- (setq-local treesit-comment-start (rx "/" (or (+ "/") (+ "*"))))
- (setq-local treesit-comment-end (rx (+ (or "*")) "/"))
+ (setq-local comment-start-skip (rx (group "/" (or (+ "/") (+ "*")))
+ (* (syntax whitespace))))
+ (setq-local comment-end-skip
+ (rx (* (syntax whitespace))
+ (group (or (syntax comment-end)
+ (seq (+ "*") "/")))))
;; Electric
(setq-local electric-indent-chars
diff --git a/lisp/treesit.el b/lisp/treesit.el
index bae44f6b0ab..8f092f475de 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -973,16 +973,6 @@ parser notifying of the change."
;;; Indent
-;; `comment-start' and `comment-end' assume there is only one type of
-;; comment, and that the comment spans only one line. So they are not
-;; sufficient for our purpose.
-
-(defvar-local treesit-comment-start nil
- "Regular expression matching an opening comment token.")
-
-(defvar-local treesit-comment-end nil
- "Regular expression matching a closing comment token.")
-
(define-error 'treesit-indent-error
"Generic tree-sitter indentation error"
'treesit-error)
@@ -1071,7 +1061,7 @@ See `treesit-simple-indent-presets'.")
(cons 'comment-end (lambda (_node _parent bol &rest _)
(save-excursion
(goto-char bol)
- (looking-at-p treesit-comment-end))))
+ (looking-at-p comment-end-skip))))
;; TODO: Document.
(cons 'catch-all (lambda (&rest _) t))
@@ -1097,14 +1087,14 @@ See `treesit-simple-indent-presets'.")
(lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
- (re-search-forward treesit-comment-start)
+ (re-search-forward comment-start-skip)
+ (skip-syntax-backward "-")
(point))))
(cons 'comment-start-skip
(lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
- (re-search-forward treesit-comment-start)
- (skip-syntax-forward "-")
+ (re-search-forward comment-start-skip)
(point))))
;; TODO: Document.
(cons 'grand-parent