aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJackson Ray Hamilton2019-04-09 19:42:49 -0700
committerJackson Ray Hamilton2019-04-09 19:42:49 -0700
commitf29010729f85434ee24efd0d7ed29b7e24cf8be6 (patch)
tree8ae675f30a8bcd55f4771802a47975abc18ed1b8
parentc0b09f42f5107dc009629ee73a790ca1d62d290a (diff)
downloademacs-f29010729f85434ee24efd0d7ed29b7e24cf8be6.tar.gz
emacs-f29010729f85434ee24efd0d7ed29b7e24cf8be6.zip
Add new defcustom js-jsx-align->-with-<
* lisp/progmodes/js.el (js-jsx-align->-with-<): New variable for users to control one opinionated aspect of JSX indentation. It defaults to the style seen in the React docs, which many users expected as the “correct” indentation. Still, the old SGML-style of indentation could be desirable too, especially since it was the old default. This ensures users have a way of getting back the old behavior. (js-jsx--contextual-indentation): Respect js-jsx-align->-with-<. * test/manual/indent/jsx-align-gt-with-lt.jsx: New test for js-jsx-align->-with-<.
-rw-r--r--lisp/progmodes/js.el35
-rw-r--r--test/manual/indent/jsx-align-gt-with-lt.jsx12
2 files changed, 43 insertions, 4 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 90f857c96fa..afdc28e53b9 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -600,6 +600,31 @@ It is set to be buffer-local (and t) when in `js-jsx-mode'."
600 :safe 'booleanp 600 :safe 'booleanp
601 :group 'js) 601 :group 'js)
602 602
603(defcustom js-jsx-align->-with-< t
604 "When non-nil, “>” will be indented to the opening “<” in JSX.
605
606When this is enabled, JSX indentation looks like this:
607
608 <element
609 attr=\"\"
610 >
611 </element>
612 <input
613 />
614
615When this is disabled, JSX indentation looks like this:
616
617 <element
618 attr=\"\"
619 >
620 </element>
621 <input
622 />"
623 :version "27.1"
624 :type 'boolean
625 :safe 'booleanp
626 :group 'js)
627
603(defcustom js-jsx-indent-level nil 628(defcustom js-jsx-indent-level nil
604 "When non-nil, indent JSX by this value, instead of like JS. 629 "When non-nil, indent JSX by this value, instead of like JS.
605 630
@@ -2725,10 +2750,12 @@ The column calculation is based off of `sgml-calculate-indent'."
2725 ;; bracket on its own line is indented at the same level as the 2750 ;; bracket on its own line is indented at the same level as the
2726 ;; opening angle bracket of the JSXElement. Otherwise, indent 2751 ;; opening angle bracket of the JSXElement. Otherwise, indent
2727 ;; JSXAttribute space like SGML. 2752 ;; JSXAttribute space like SGML.
2728 (if (progn 2753 (if (and
2729 (goto-char (nth 2 context)) 2754 js-jsx-align->-with-<
2730 (and (= line (line-number-at-pos)) 2755 (progn
2731 (looking-back "^\\s-*/?>" (line-beginning-position)))) 2756 (goto-char (nth 2 context))
2757 (and (= line (line-number-at-pos))
2758 (looking-back "^\\s-*/?>" (line-beginning-position)))))
2732 (progn 2759 (progn
2733 (goto-char (nth 1 context)) 2760 (goto-char (nth 1 context))
2734 (current-column)) 2761 (current-column))
diff --git a/test/manual/indent/jsx-align-gt-with-lt.jsx b/test/manual/indent/jsx-align-gt-with-lt.jsx
new file mode 100644
index 00000000000..8eb1d6d718c
--- /dev/null
+++ b/test/manual/indent/jsx-align-gt-with-lt.jsx
@@ -0,0 +1,12 @@
1<element
2 attr=""
3 >
4</element>
5<input
6 />
7
8// Local Variables:
9// indent-tabs-mode: nil
10// js-indent-level: 2
11// js-jsx-align->-with-<: nil
12// End: