Use js-jsx- prefix for functions and variables

* lisp/progmodes/js.el (js--disambiguate-beginning-of-jsx-tag): Rename
to js-jsx--disambiguate-beginning-of-tag.
(js--disambiguate-end-of-jsx-tag): Rename to
js-jsx--disambiguate-end-of-tag.
(js--disambiguate-js-from-jsx): Rename to js-jsx--disambiguate-syntax.
(js--jsx-start-tag-re): Rename to js-jsx--start-tag-re.
(js--looking-at-jsx-start-tag-p): Rename to
js-jsx--looking-at-start-tag-p.
(js--jsx-end-tag-re): Rename to js-jsx--end-tag-re.
(js--looking-back-at-jsx-end-tag-p): Rename to
js-jsx--looking-back-at-end-tag-p.
(js--as-sgml): Rename to js-jsx--as-sgml.
(js--outermost-enclosing-jsx-tag-pos): Rename to
js-jsx--outermost-enclosing-tag-pos.
(js--jsx-indentation): Rename to js-jsx--indentation-type.
(js--indent-line-in-jsx-expression): Rename to
js-jsx--indent-line-in-expression.
(js--indent-n+1th-jsx-line): Rename to js-jsx--indent-n+1th-line.
parent be86ece4
...@@ -1743,7 +1743,7 @@ This performs fontification according to `js--class-styles'." ...@@ -1743,7 +1743,7 @@ This performs fontification according to `js--class-styles'."
"Check if STRING is a unary operator keyword in JavaScript." "Check if STRING is a unary operator keyword in JavaScript."
(string-match-p js--unary-keyword-re string)) (string-match-p js--unary-keyword-re string))
(defun js--disambiguate-beginning-of-jsx-tag () (defun js-jsx--disambiguate-beginning-of-tag ()
"Parse enough to determine if a JSX tag starts here. "Parse enough to determine if a JSX tag starts here.
Disambiguate JSX from equality operators by testing for syntax Disambiguate JSX from equality operators by testing for syntax
only valid as JSX." only valid as JSX."
...@@ -1766,7 +1766,7 @@ only valid as JSX." ...@@ -1766,7 +1766,7 @@ only valid as JSX."
;; Check if a JSXAttribute follows. ;; Check if a JSXAttribute follows.
(looking-at js--name-start-re))))))) (looking-at js--name-start-re)))))))
(defun js--disambiguate-end-of-jsx-tag () (defun js-jsx--disambiguate-end-of-tag ()
"Parse enough to determine if a JSX tag ends here. "Parse enough to determine if a JSX tag ends here.
Disambiguate JSX from equality operators by testing for syntax Disambiguate JSX from equality operators by testing for syntax
only valid as JSX, or extremely unlikely except as JSX." only valid as JSX, or extremely unlikely except as JSX."
...@@ -1812,7 +1812,7 @@ only valid as JSX, or extremely unlikely except as JSX." ...@@ -1812,7 +1812,7 @@ only valid as JSX, or extremely unlikely except as JSX."
;; Nothing else to look for; give up parsing. ;; Nothing else to look for; give up parsing.
(throw 'match nil))))))))) (throw 'match nil)))))))))
(defun js--disambiguate-js-from-jsx (start end) (defun js-jsx--disambiguate-syntax (start end)
"Figure out which ‘<’ and ‘>’ chars (from START to END) aren’t JSX. "Figure out which ‘<’ and ‘>’ chars (from START to END) aren’t JSX.
Later, this info prevents ‘sgml-’ functions from treating some Later, this info prevents ‘sgml-’ functions from treating some
...@@ -1821,8 +1821,8 @@ since they are serving their usual function as some JS equality ...@@ -1821,8 +1821,8 @@ since they are serving their usual function as some JS equality
operator or arrow function, instead." operator or arrow function, instead."
(goto-char start) (goto-char start)
(while (re-search-forward "[<>]" end t) (while (re-search-forward "[<>]" end t)
(unless (if (eq (char-before) ?<) (js--disambiguate-beginning-of-jsx-tag) (unless (if (eq (char-before) ?<) (js-jsx--disambiguate-beginning-of-tag)
(js--disambiguate-end-of-jsx-tag)) (js-jsx--disambiguate-end-of-tag))
;; Inform sgml- functions that this >, >=, >>>, <, <=, <<<, or ;; Inform sgml- functions that this >, >=, >>>, <, <=, <<<, or
;; => token is punctuation (and not an open or close parenthesis ;; => token is punctuation (and not an open or close parenthesis
;; as per usual in sgml-mode). ;; as per usual in sgml-mode).
...@@ -1856,7 +1856,7 @@ operator or arrow function, instead." ...@@ -1856,7 +1856,7 @@ operator or arrow function, instead."
(js-syntax-propertize-regexp end))))) (js-syntax-propertize-regexp end)))))
("\\`\\(#\\)!" (1 "< b"))) ("\\`\\(#\\)!" (1 "< b")))
(point) end) (point) end)
(if js-jsx-syntax (js--disambiguate-js-from-jsx start end))) (if js-jsx-syntax (js-jsx--disambiguate-syntax start end)))
(defconst js--prettify-symbols-alist (defconst js--prettify-symbols-alist
'(("=>" . ?) '(("=>" . ?)
...@@ -1881,13 +1881,13 @@ operator or arrow function, instead." ...@@ -1881,13 +1881,13 @@ operator or arrow function, instead."
(js--regexp-opt-symbol '("in" "instanceof"))) (js--regexp-opt-symbol '("in" "instanceof")))
"Regexp matching operators that affect indentation of continued expressions.") "Regexp matching operators that affect indentation of continued expressions.")
(defconst js--jsx-start-tag-re (defconst js-jsx--start-tag-re
(concat "<" sgml-name-re) (concat "<" sgml-name-re)
"Regexp matching code that looks like a JSXOpeningElement.") "Regexp matching code that looks like a JSXOpeningElement.")
(defun js--looking-at-jsx-start-tag-p () (defun js-jsx--looking-at-start-tag-p ()
"Non-nil if a JSXOpeningElement immediately follows point." "Non-nil if a JSXOpeningElement immediately follows point."
(looking-at js--jsx-start-tag-re)) (looking-at js-jsx--start-tag-re))
(defun js--looking-at-operator-p () (defun js--looking-at-operator-p ()
"Return non-nil if point is on a JavaScript operator, other than a comma." "Return non-nil if point is on a JavaScript operator, other than a comma."
...@@ -1913,7 +1913,7 @@ operator or arrow function, instead." ...@@ -1913,7 +1913,7 @@ operator or arrow function, instead."
;; return NaN anyway. Shouldn't be a problem. ;; return NaN anyway. Shouldn't be a problem.
(memq (char-before) '(?, ?} ?{))))) (memq (char-before) '(?, ?} ?{)))))
;; “<” isn’t necessarily an operator in JSX. ;; “<” isn’t necessarily an operator in JSX.
(not (and js-jsx-syntax (js--looking-at-jsx-start-tag-p)))))) (not (and js-jsx-syntax (js-jsx--looking-at-start-tag-p))))))
(defun js--find-newline-backward () (defun js--find-newline-backward ()
"Move backward to the nearest newline that is not in a block comment." "Move backward to the nearest newline that is not in a block comment."
...@@ -1933,13 +1933,13 @@ operator or arrow function, instead." ...@@ -1933,13 +1933,13 @@ operator or arrow function, instead."
(setq result nil))) (setq result nil)))
result)) result))
(defconst js--jsx-end-tag-re (defconst js-jsx--end-tag-re
(concat "</" sgml-name-re ">\\|/>") (concat "</" sgml-name-re ">\\|/>")
"Regexp matching a JSXClosingElement.") "Regexp matching a JSXClosingElement.")
(defun js--looking-back-at-jsx-end-tag-p () (defun js-jsx--looking-back-at-end-tag-p ()
"Non-nil if a JSXClosingElement immediately precedes point." "Non-nil if a JSXClosingElement immediately precedes point."
(looking-back js--jsx-end-tag-re (point-at-bol))) (looking-back js-jsx--end-tag-re (point-at-bol)))
(defun js--continued-expression-p () (defun js--continued-expression-p ()
"Return non-nil if the current line continues an expression." "Return non-nil if the current line continues an expression."
...@@ -1961,7 +1961,7 @@ operator or arrow function, instead." ...@@ -1961,7 +1961,7 @@ operator or arrow function, instead."
(and (and
;; The “>” at the end of any JSXBoundaryElement isn’t ;; The “>” at the end of any JSXBoundaryElement isn’t
;; part of a continued expression. ;; part of a continued expression.
(not (and js-jsx-syntax (js--looking-back-at-jsx-end-tag-p))) (not (and js-jsx-syntax (js-jsx--looking-back-at-end-tag-p)))
(progn (progn
(or (bobp) (backward-char)) (or (bobp) (backward-char))
(and (> (point) (point-min)) (and (> (point) (point-min))
...@@ -2285,14 +2285,14 @@ current line is the \"=>\" token." ...@@ -2285,14 +2285,14 @@ current line is the \"=>\" token."
;;; JSX Indentation ;;; JSX Indentation
(defmacro js--as-sgml (&rest body) (defmacro js-jsx--as-sgml (&rest body)
"Execute BODY as if in sgml-mode." "Execute BODY as if in sgml-mode."
`(with-syntax-table sgml-mode-syntax-table `(with-syntax-table sgml-mode-syntax-table
,@body)) ,@body))
(defun js--outermost-enclosing-jsx-tag-pos () (defun js-jsx--outermost-enclosing-tag-pos ()
(let (context tag-pos last-tag-pos parse-status parens paren-pos curly-pos) (let (context tag-pos last-tag-pos parse-status parens paren-pos curly-pos)
(js--as-sgml (js-jsx--as-sgml
;; Search until we reach the top or encounter the start of a ;; Search until we reach the top or encounter the start of a
;; JSXExpressionContainer (implying nested JSX). ;; JSXExpressionContainer (implying nested JSX).
(while (and (setq context (sgml-get-context)) (while (and (setq context (sgml-get-context))
...@@ -2322,7 +2322,7 @@ current line is the \"=>\" token." ...@@ -2322,7 +2322,7 @@ current line is the \"=>\" token."
(goto-char tag-pos)))) (goto-char tag-pos))))
last-tag-pos)) last-tag-pos))
(defun js--jsx-indentation () (defun js-jsx--indentation-type ()
"Determine if/how the current line should be indented as JSX. "Determine if/how the current line should be indented as JSX.
Return nil for first JSXElement line (indent like JS). Return nil for first JSXElement line (indent like JS).
...@@ -2336,7 +2336,7 @@ Return nil for non-JSX lines." ...@@ -2336,7 +2336,7 @@ Return nil for non-JSX lines."
(save-excursion (save-excursion
;; Determine if inside a JSXElement. ;; Determine if inside a JSXElement.
(beginning-of-line) ; For exclusivity (beginning-of-line) ; For exclusivity
(when (setq tag-start-pos (js--outermost-enclosing-jsx-tag-pos)) (when (setq tag-start-pos (js-jsx--outermost-enclosing-tag-pos))
;; Check if inside an embedded multi-line JS expression. ;; Check if inside an embedded multi-line JS expression.
(goto-char current-pos) (goto-char current-pos)
(end-of-line) ; For exclusivity (end-of-line) ; For exclusivity
...@@ -2369,14 +2369,14 @@ Return nil for non-JSX lines." ...@@ -2369,14 +2369,14 @@ Return nil for non-JSX lines."
(setq parens (cdr parens))))) (setq parens (cdr parens)))))
(or type 'n+1th))))) (or type 'n+1th)))))
(defun js--indent-line-in-jsx-expression () (defun js-jsx--indent-line-in-expression ()
"Indent the current line as JavaScript within JSX." "Indent the current line as JavaScript within JSX."
(let ((parse-status (save-excursion (syntax-ppss (point-at-bol)))) (let ((parse-status (save-excursion (syntax-ppss (point-at-bol))))
offset indent-col) offset indent-col)
(unless (nth 3 parse-status) (unless (nth 3 parse-status)
(save-excursion (save-excursion
(setq offset (- (point) (progn (back-to-indentation) (point))) (setq offset (- (point) (progn (back-to-indentation) (point)))
indent-col (js--as-sgml (sgml-calculate-indent)))) indent-col (js-jsx--as-sgml (sgml-calculate-indent))))
(if (null indent-col) 'noindent ; Like in sgml-mode (if (null indent-col) 'noindent ; Like in sgml-mode
;; Use whichever indentation column is greater, such that the ;; Use whichever indentation column is greater, such that the
;; SGML column is effectively a minimum. ;; SGML column is effectively a minimum.
...@@ -2384,9 +2384,9 @@ Return nil for non-JSX lines." ...@@ -2384,9 +2384,9 @@ Return nil for non-JSX lines."
(+ indent-col js-indent-level))) (+ indent-col js-indent-level)))
(when (> offset 0) (forward-char offset)))))) (when (> offset 0) (forward-char offset))))))
(defun js--indent-n+1th-jsx-line () (defun js-jsx--indent-n+1th-line ()
"Indent the current line as JSX within JavaScript." "Indent the current line as JSX within JavaScript."
(js--as-sgml (sgml-indent-line))) (js-jsx--as-sgml (sgml-indent-line)))
(defun js-indent-line () (defun js-indent-line ()
"Indent the current line as JavaScript." "Indent the current line as JavaScript."
...@@ -2403,10 +2403,10 @@ Return nil for non-JSX lines." ...@@ -2403,10 +2403,10 @@ Return nil for non-JSX lines."
i.e., customize JSX element indentation with `sgml-basic-offset', i.e., customize JSX element indentation with `sgml-basic-offset',
`sgml-attribute-offset' et al." `sgml-attribute-offset' et al."
(interactive) (interactive)
(let ((type (js--jsx-indentation))) (let ((type (js-jsx--indentation-type)))
(if type (if type
(if (eq type 'n+1th) (js--indent-n+1th-jsx-line) (if (eq type 'n+1th) (js-jsx--indent-n+1th-line)
(js--indent-line-in-jsx-expression)) (js-jsx--indent-line-in-expression))
(js-indent-line)))) (js-indent-line))))
;;; Filling ;;; Filling
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment