From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 58815@debbugs.gnu.org
Cc: Yuan Fu <casouri@gmail.com>
Subject: bug#58815: 29.0.50; Small treesitter fixes for js/ts-mode
Date: Thu, 27 Oct 2022 11:58:06 +0200 [thread overview]
Message-ID: <87edutsi4x.fsf@thornhill.no> (raw)
[-- Attachment #1: Type: text/plain, Size: 156 bytes --]
Hello Yuan!
See the attached patch. There's a small fix to ensure the parser, as
well as adding in two small, but nice indentation fixes.
Thanks,
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Tweak-indentation-and-ensure-parser.patch --]
[-- Type: text/x-diff, Size: 3489 bytes --]
From c45f93e3677b3ef66730afd00024933568058755 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Thu, 27 Oct 2022 11:53:07 +0200
Subject: [PATCH] Tweak indentation and ensure parser
* lisp/progmodes/js.el (js--treesit-indent-rules)
(js--treesit-cc-indent-rules): Don't use '.' as indent anchor and add
in 'program' as root anchor.
* lisp/progmodes/ts-mode.el (ts-mode--indent-rules): Don't use '.' as
indent anchor and add in 'program' as root anchor.
(ts-mode): Create parser so that mode can initialize.
---
lisp/progmodes/js.el | 12 +++++++++++-
lisp/progmodes/ts-mode.el | 9 +++++----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 89bd04b231..b940a3a2a4 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3416,12 +3416,16 @@ js--treesit-backward-up-list
(defvar js--treesit-indent-rules
`((javascript
+ ((parent-is "program") parent-bol 0)
(no-node (js--treesit-backward-up-list) ,js-indent-level)
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
- ((node-is ".") parent-bol ,js-indent-level)
+ ((parent-is "ternary_expression")
+ parent-bol ,js-indent-level)
+ ((parent-is "member_expression")
+ parent-bol ,js-indent-level)
((parent-is "named_imports") parent-bol ,js-indent-level)
((parent-is "statement_block") parent-bol ,js-indent-level)
((parent-is "variable_declarator") parent-bol ,js-indent-level)
@@ -3452,6 +3456,7 @@ js--treesit-cc-indent-rules
"_clause"))
(switch-case-re (rx "switch_" (or "case" "default"))))
`((javascript
+ ((parent-is "program") parent-bol 0)
;; Function declaration.
;; "{"
((match "statement_block" ,function-re) parent defun-open)
@@ -3529,6 +3534,11 @@ js--treesit-cc-indent-rules
((node-is "formal_parameters") parent statement-cont)
;; Misc.
+ ((parent-is "ternary_expression")
+ parent-bol ,js-indent-level)
+ ((parent-is "member_expression")
+ parent-bol ,js-indent-level)
+
((parent-is "function_declaration") parent func-decl-cont)
((parent-is "string-fragment") grand-parent string)
((parent-is "comment") grand-parent c)
diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el
index 28800e378a..88c93a6e93 100644
--- a/lisp/progmodes/ts-mode.el
+++ b/lisp/progmodes/ts-mode.el
@@ -55,14 +55,15 @@ ts-mode--syntax-table
(defvar ts-mode--indent-rules
`((tsx
+ ((parent-is "program") parent-bol 0)
((node-is "}") parent-bol 0)
((node-is ")") parent-bol 0)
((node-is "]") parent-bol 0)
((node-is ">") parent-bol 0)
- ((node-is ".")
- parent-bol ,ts-mode-indent-offset)
((parent-is "ternary_expression")
parent-bol ,ts-mode-indent-offset)
+ ((parent-is "member_expression")
+ parent-bol ,ts-mode-indent-offset)
((parent-is "named_imports")
parent-bol ,ts-mode-indent-offset)
((parent-is "statement_block")
@@ -261,8 +262,8 @@ ts-mode
:syntax-table ts-mode--syntax-table
(cond
- ((treesit-ready-p nil 'tsx)
- ;; Tree-sitter.
+ ((treesit-ready-p 'ts-mode 'tsx)
+ (treesit-parser-create 'tsx)
;; Comments.
(setq-local comment-start "// ")
(setq-local comment-start-skip "\\(?://+\\|/\\*+\\)\\s *")
--
2.34.1
reply other threads:[~2022-10-27 9:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87edutsi4x.fsf@thornhill.no \
--to=bug-gnu-emacs@gnu.org \
--cc=58815@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=theo@thornhill.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.