emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 2e6093b425e 3/3: Adjust jsx indentation


From: Theodor Thornhill
Subject: emacs-29 2e6093b425e 3/3: Adjust jsx indentation
Date: Sun, 19 Feb 2023 14:48:23 -0500 (EST)

branch: emacs-29
commit 2e6093b425e21551806abed746765631a00942d6
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Theodor Thornhill <theo@thornhill.no>

    Adjust jsx indentation
    
    We can use the fact that 'treesit-indent-1' uses 'treesit-node-on'
    when on a whitespace to set the actual current node as parent.  Now we
    can correctly indent the 'jsx_text' nodes.  We also add some more
    electric-indent-chars so that auto-indenting of jsx behaves a little
    more fluently.
    
    * lisp/progmodes/js.el (js--treesit-indent-rules): Add new rules.
    (js-ts-mode): Add more indent-chars.
    * lisp/progmodes/typescript-ts-mode.el
    (typescript-ts-mode--indent-rules): Add new rules.
    * lisp/progmodes/typescript-ts-mode.el
    (typescript-ts-base-mode): Add more indent-chars and layout rules.
---
 lisp/progmodes/js.el                 | 6 ++++--
 lisp/progmodes/typescript-ts-mode.el | 9 ++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 1f08f09935b..027d6053f6e 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3458,12 +3458,14 @@ This function is intended for use in 
`after-change-functions'."
        ((match "<" "jsx_fragment") parent 0)
        ((parent-is "jsx_fragment") parent js-indent-level)
        ((node-is "jsx_closing_element") parent 0)
-       ((node-is "jsx_element") parent js-indent-level)
+       ((match "jsx_element" "statement") parent js-indent-level)
        ((parent-is "jsx_element") parent js-indent-level)
+       ((parent-is "jsx_text") parent-bol js-indent-level)
        ((parent-is "jsx_opening_element") parent js-indent-level)
        ((parent-is "jsx_expression") parent-bol js-indent-level)
        ((match "/" "jsx_self_closing_element") parent 0)
        ((parent-is "jsx_self_closing_element") parent js-indent-level)
+       ;; FIXME(Theo): This no-node catch-all should be removed.  When is it 
needed?
        (no-node parent-bol 0)))))
 
 (defvar js--treesit-keywords
@@ -3820,7 +3822,7 @@ Currently there are `js-mode' and `js-ts-mode'."
     (setq-local comment-multi-line t)
     ;; Electric-indent.
     (setq-local electric-indent-chars
-               (append "{}():;," electric-indent-chars)) ;FIXME: js2-mode adds 
"[]*".
+                (append "{}():;,<>/" electric-indent-chars)) ;FIXME: js2-mode 
adds "[]*".
     (setq-local electric-layout-rules
                '((?\; . after) (?\{ . after) (?\} . before)))
 
diff --git a/lisp/progmodes/typescript-ts-mode.el 
b/lisp/progmodes/typescript-ts-mode.el
index 88a1ff3e202..de9b2f6845c 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -101,12 +101,14 @@ Argument LANGUAGE is either `typescript' or `tsx'."
          `(((match "<" "jsx_fragment") parent 0)
            ((parent-is "jsx_fragment") parent typescript-ts-mode-indent-offset)
            ((node-is "jsx_closing_element") parent 0)
-           ((node-is "jsx_element") parent typescript-ts-mode-indent-offset)
+           ((match "jsx_element" "statement") parent 
typescript-ts-mode-indent-offset)
            ((parent-is "jsx_element") parent typescript-ts-mode-indent-offset)
+           ((parent-is "jsx_text") parent-bol typescript-ts-mode-indent-offset)
            ((parent-is "jsx_opening_element") parent 
typescript-ts-mode-indent-offset)
            ((parent-is "jsx_expression") parent-bol 
typescript-ts-mode-indent-offset)
            ((match "/" "jsx_self_closing_element") parent 0)
            ((parent-is "jsx_self_closing_element") parent 
typescript-ts-mode-indent-offset)))
+     ;; FIXME(Theo): This no-node catch-all should be removed.  When is it 
needed?
      (no-node parent-bol 0))))
 
 (defvar typescript-ts-mode--keywords
@@ -326,8 +328,9 @@ Argument LANGUAGE is either `typescript' or `tsx'."
 
   ;; Electric
   (setq-local electric-indent-chars
-              (append "{}():;," electric-indent-chars))
-
+              (append "{}():;,<>/" electric-indent-chars))
+  (setq-local electric-layout-rules
+             '((?\; . after) (?\{ . after) (?\} . before)))
   ;; Navigation.
   (setq-local treesit-defun-type-regexp
               (regexp-opt '("class_declaration"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]