aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJackson Ray Hamilton2019-02-15 22:15:11 -0800
committerJackson Ray Hamilton2019-04-08 22:48:21 -0700
commit6f535762df1f8f55faa36878d4a2a0a8b112f666 (patch)
treebde0ce457f5bbb8887816b508f98be23d6cbf4a4
parentbe86ece42cbb6204480c794d018b02fbda74689b (diff)
downloademacs-6f535762df1f8f55faa36878d4a2a0a8b112f666.tar.gz
emacs-6f535762df1f8f55faa36878d4a2a0a8b112f666.zip
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.
-rw-r--r--lisp/progmodes/js.el52
1 files changed, 26 insertions, 26 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index d0556f3538e..4404ea04a03 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1743,7 +1743,7 @@ This performs fontification according to `js--class-styles'."
1743 "Check if STRING is a unary operator keyword in JavaScript." 1743 "Check if STRING is a unary operator keyword in JavaScript."
1744 (string-match-p js--unary-keyword-re string)) 1744 (string-match-p js--unary-keyword-re string))
1745 1745
1746(defun js--disambiguate-beginning-of-jsx-tag () 1746(defun js-jsx--disambiguate-beginning-of-tag ()
1747 "Parse enough to determine if a JSX tag starts here. 1747 "Parse enough to determine if a JSX tag starts here.
1748Disambiguate JSX from equality operators by testing for syntax 1748Disambiguate JSX from equality operators by testing for syntax
1749only valid as JSX." 1749only valid as JSX."
@@ -1766,7 +1766,7 @@ only valid as JSX."
1766 ;; Check if a JSXAttribute follows. 1766 ;; Check if a JSXAttribute follows.
1767 (looking-at js--name-start-re))))))) 1767 (looking-at js--name-start-re)))))))
1768 1768
1769(defun js--disambiguate-end-of-jsx-tag () 1769(defun js-jsx--disambiguate-end-of-tag ()
1770 "Parse enough to determine if a JSX tag ends here. 1770 "Parse enough to determine if a JSX tag ends here.
1771Disambiguate JSX from equality operators by testing for syntax 1771Disambiguate JSX from equality operators by testing for syntax
1772only valid as JSX, or extremely unlikely except as JSX." 1772only valid as JSX, or extremely unlikely except as JSX."
@@ -1812,7 +1812,7 @@ only valid as JSX, or extremely unlikely except as JSX."
1812 ;; Nothing else to look for; give up parsing. 1812 ;; Nothing else to look for; give up parsing.
1813 (throw 'match nil))))))))) 1813 (throw 'match nil)))))))))
1814 1814
1815(defun js--disambiguate-js-from-jsx (start end) 1815(defun js-jsx--disambiguate-syntax (start end)
1816 "Figure out which ‘<’ and ‘>’ chars (from START to END) aren’t JSX. 1816 "Figure out which ‘<’ and ‘>’ chars (from START to END) aren’t JSX.
1817 1817
1818Later, this info prevents ‘sgml-’ functions from treating some 1818Later, this info prevents ‘sgml-’ functions from treating some
@@ -1821,8 +1821,8 @@ since they are serving their usual function as some JS equality
1821operator or arrow function, instead." 1821operator or arrow function, instead."
1822 (goto-char start) 1822 (goto-char start)
1823 (while (re-search-forward "[<>]" end t) 1823 (while (re-search-forward "[<>]" end t)
1824 (unless (if (eq (char-before) ?<) (js--disambiguate-beginning-of-jsx-tag) 1824 (unless (if (eq (char-before) ?<) (js-jsx--disambiguate-beginning-of-tag)
1825 (js--disambiguate-end-of-jsx-tag)) 1825 (js-jsx--disambiguate-end-of-tag))
1826 ;; Inform sgml- functions that this >, >=, >>>, <, <=, <<<, or 1826 ;; Inform sgml- functions that this >, >=, >>>, <, <=, <<<, or
1827 ;; => token is punctuation (and not an open or close parenthesis 1827 ;; => token is punctuation (and not an open or close parenthesis
1828 ;; as per usual in sgml-mode). 1828 ;; as per usual in sgml-mode).
@@ -1856,7 +1856,7 @@ operator or arrow function, instead."
1856 (js-syntax-propertize-regexp end))))) 1856 (js-syntax-propertize-regexp end)))))
1857 ("\\`\\(#\\)!" (1 "< b"))) 1857 ("\\`\\(#\\)!" (1 "< b")))
1858 (point) end) 1858 (point) end)
1859 (if js-jsx-syntax (js--disambiguate-js-from-jsx start end))) 1859 (if js-jsx-syntax (js-jsx--disambiguate-syntax start end)))
1860 1860
1861(defconst js--prettify-symbols-alist 1861(defconst js--prettify-symbols-alist
1862 '(("=>" . ?⇒) 1862 '(("=>" . ?⇒)
@@ -1881,13 +1881,13 @@ operator or arrow function, instead."
1881 (js--regexp-opt-symbol '("in" "instanceof"))) 1881 (js--regexp-opt-symbol '("in" "instanceof")))
1882 "Regexp matching operators that affect indentation of continued expressions.") 1882 "Regexp matching operators that affect indentation of continued expressions.")
1883 1883
1884(defconst js--jsx-start-tag-re 1884(defconst js-jsx--start-tag-re
1885 (concat "<" sgml-name-re) 1885 (concat "<" sgml-name-re)
1886 "Regexp matching code that looks like a JSXOpeningElement.") 1886 "Regexp matching code that looks like a JSXOpeningElement.")
1887 1887
1888(defun js--looking-at-jsx-start-tag-p () 1888(defun js-jsx--looking-at-start-tag-p ()
1889 "Non-nil if a JSXOpeningElement immediately follows point." 1889 "Non-nil if a JSXOpeningElement immediately follows point."
1890 (looking-at js--jsx-start-tag-re)) 1890 (looking-at js-jsx--start-tag-re))
1891 1891
1892(defun js--looking-at-operator-p () 1892(defun js--looking-at-operator-p ()
1893 "Return non-nil if point is on a JavaScript operator, other than a comma." 1893 "Return non-nil if point is on a JavaScript operator, other than a comma."
@@ -1913,7 +1913,7 @@ operator or arrow function, instead."
1913 ;; return NaN anyway. Shouldn't be a problem. 1913 ;; return NaN anyway. Shouldn't be a problem.
1914 (memq (char-before) '(?, ?} ?{))))) 1914 (memq (char-before) '(?, ?} ?{)))))
1915 ;; “<” isn’t necessarily an operator in JSX. 1915 ;; “<” isn’t necessarily an operator in JSX.
1916 (not (and js-jsx-syntax (js--looking-at-jsx-start-tag-p)))))) 1916 (not (and js-jsx-syntax (js-jsx--looking-at-start-tag-p))))))
1917 1917
1918(defun js--find-newline-backward () 1918(defun js--find-newline-backward ()
1919 "Move backward to the nearest newline that is not in a block comment." 1919 "Move backward to the nearest newline that is not in a block comment."
@@ -1933,13 +1933,13 @@ operator or arrow function, instead."
1933 (setq result nil))) 1933 (setq result nil)))
1934 result)) 1934 result))
1935 1935
1936(defconst js--jsx-end-tag-re 1936(defconst js-jsx--end-tag-re
1937 (concat "</" sgml-name-re ">\\|/>") 1937 (concat "</" sgml-name-re ">\\|/>")
1938 "Regexp matching a JSXClosingElement.") 1938 "Regexp matching a JSXClosingElement.")
1939 1939
1940(defun js--looking-back-at-jsx-end-tag-p () 1940(defun js-jsx--looking-back-at-end-tag-p ()
1941 "Non-nil if a JSXClosingElement immediately precedes point." 1941 "Non-nil if a JSXClosingElement immediately precedes point."
1942 (looking-back js--jsx-end-tag-re (point-at-bol))) 1942 (looking-back js-jsx--end-tag-re (point-at-bol)))
1943 1943
1944(defun js--continued-expression-p () 1944(defun js--continued-expression-p ()
1945 "Return non-nil if the current line continues an expression." 1945 "Return non-nil if the current line continues an expression."
@@ -1961,7 +1961,7 @@ operator or arrow function, instead."
1961 (and 1961 (and
1962 ;; The “>” at the end of any JSXBoundaryElement isn’t 1962 ;; The “>” at the end of any JSXBoundaryElement isn’t
1963 ;; part of a continued expression. 1963 ;; part of a continued expression.
1964 (not (and js-jsx-syntax (js--looking-back-at-jsx-end-tag-p))) 1964 (not (and js-jsx-syntax (js-jsx--looking-back-at-end-tag-p)))
1965 (progn 1965 (progn
1966 (or (bobp) (backward-char)) 1966 (or (bobp) (backward-char))
1967 (and (> (point) (point-min)) 1967 (and (> (point) (point-min))
@@ -2285,14 +2285,14 @@ current line is the \"=>\" token."
2285 2285
2286;;; JSX Indentation 2286;;; JSX Indentation
2287 2287
2288(defmacro js--as-sgml (&rest body) 2288(defmacro js-jsx--as-sgml (&rest body)
2289 "Execute BODY as if in sgml-mode." 2289 "Execute BODY as if in sgml-mode."
2290 `(with-syntax-table sgml-mode-syntax-table 2290 `(with-syntax-table sgml-mode-syntax-table
2291 ,@body)) 2291 ,@body))
2292 2292
2293(defun js--outermost-enclosing-jsx-tag-pos () 2293(defun js-jsx--outermost-enclosing-tag-pos ()
2294 (let (context tag-pos last-tag-pos parse-status parens paren-pos curly-pos) 2294 (let (context tag-pos last-tag-pos parse-status parens paren-pos curly-pos)
2295 (js--as-sgml 2295 (js-jsx--as-sgml
2296 ;; Search until we reach the top or encounter the start of a 2296 ;; Search until we reach the top or encounter the start of a
2297 ;; JSXExpressionContainer (implying nested JSX). 2297 ;; JSXExpressionContainer (implying nested JSX).
2298 (while (and (setq context (sgml-get-context)) 2298 (while (and (setq context (sgml-get-context))
@@ -2322,7 +2322,7 @@ current line is the \"=>\" token."
2322 (goto-char tag-pos)))) 2322 (goto-char tag-pos))))
2323 last-tag-pos)) 2323 last-tag-pos))
2324 2324
2325(defun js--jsx-indentation () 2325(defun js-jsx--indentation-type ()
2326 "Determine if/how the current line should be indented as JSX. 2326 "Determine if/how the current line should be indented as JSX.
2327 2327
2328Return nil for first JSXElement line (indent like JS). 2328Return nil for first JSXElement line (indent like JS).
@@ -2336,7 +2336,7 @@ Return nil for non-JSX lines."
2336 (save-excursion 2336 (save-excursion
2337 ;; Determine if inside a JSXElement. 2337 ;; Determine if inside a JSXElement.
2338 (beginning-of-line) ; For exclusivity 2338 (beginning-of-line) ; For exclusivity
2339 (when (setq tag-start-pos (js--outermost-enclosing-jsx-tag-pos)) 2339 (when (setq tag-start-pos (js-jsx--outermost-enclosing-tag-pos))
2340 ;; Check if inside an embedded multi-line JS expression. 2340 ;; Check if inside an embedded multi-line JS expression.
2341 (goto-char current-pos) 2341 (goto-char current-pos)
2342 (end-of-line) ; For exclusivity 2342 (end-of-line) ; For exclusivity
@@ -2369,14 +2369,14 @@ Return nil for non-JSX lines."
2369 (setq parens (cdr parens))))) 2369 (setq parens (cdr parens)))))
2370 (or type 'n+1th))))) 2370 (or type 'n+1th)))))
2371 2371
2372(defun js--indent-line-in-jsx-expression () 2372(defun js-jsx--indent-line-in-expression ()
2373 "Indent the current line as JavaScript within JSX." 2373 "Indent the current line as JavaScript within JSX."
2374 (let ((parse-status (save-excursion (syntax-ppss (point-at-bol)))) 2374 (let ((parse-status (save-excursion (syntax-ppss (point-at-bol))))
2375 offset indent-col) 2375 offset indent-col)
2376 (unless (nth 3 parse-status) 2376 (unless (nth 3 parse-status)
2377 (save-excursion 2377 (save-excursion
2378 (setq offset (- (point) (progn (back-to-indentation) (point))) 2378 (setq offset (- (point) (progn (back-to-indentation) (point)))
2379 indent-col (js--as-sgml (sgml-calculate-indent)))) 2379 indent-col (js-jsx--as-sgml (sgml-calculate-indent))))
2380 (if (null indent-col) 'noindent ; Like in sgml-mode 2380 (if (null indent-col) 'noindent ; Like in sgml-mode
2381 ;; Use whichever indentation column is greater, such that the 2381 ;; Use whichever indentation column is greater, such that the
2382 ;; SGML column is effectively a minimum. 2382 ;; SGML column is effectively a minimum.
@@ -2384,9 +2384,9 @@ Return nil for non-JSX lines."
2384 (+ indent-col js-indent-level))) 2384 (+ indent-col js-indent-level)))
2385 (when (> offset 0) (forward-char offset)))))) 2385 (when (> offset 0) (forward-char offset))))))
2386 2386
2387(defun js--indent-n+1th-jsx-line () 2387(defun js-jsx--indent-n+1th-line ()
2388 "Indent the current line as JSX within JavaScript." 2388 "Indent the current line as JSX within JavaScript."
2389 (js--as-sgml (sgml-indent-line))) 2389 (js-jsx--as-sgml (sgml-indent-line)))
2390 2390
2391(defun js-indent-line () 2391(defun js-indent-line ()
2392 "Indent the current line as JavaScript." 2392 "Indent the current line as JavaScript."
@@ -2403,10 +2403,10 @@ Return nil for non-JSX lines."
2403i.e., customize JSX element indentation with `sgml-basic-offset', 2403i.e., customize JSX element indentation with `sgml-basic-offset',
2404`sgml-attribute-offset' et al." 2404`sgml-attribute-offset' et al."
2405 (interactive) 2405 (interactive)
2406 (let ((type (js--jsx-indentation))) 2406 (let ((type (js-jsx--indentation-type)))
2407 (if type 2407 (if type
2408 (if (eq type 'n+1th) (js--indent-n+1th-jsx-line) 2408 (if (eq type 'n+1th) (js-jsx--indent-n+1th-line)
2409 (js--indent-line-in-jsx-expression)) 2409 (js-jsx--indent-line-in-expression))
2410 (js-indent-line)))) 2410 (js-indent-line))))
2411 2411
2412;;; Filling 2412;;; Filling