Function: js-jsx--indentation

js-jsx--indentation is a byte-compiled function defined in js.el.gz.

Signature

(js-jsx--indentation PARSE-STATUS)

Documentation

Helper function for js--proper-indentation.

Return the proper indentation of the current line if it is part of a JSXElement expression spanning multiple lines; otherwise, return nil.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/js.el.gz
(defun js-jsx--indentation (parse-status)
  "Helper function for `js--proper-indentation'.
Return the proper indentation of the current line if it is part
of a JSXElement expression spanning multiple lines; otherwise,
return nil."
  (let ((current-line (line-number-at-pos))
        (curly-pos (js-jsx--enclosing-curly-pos))
        nth-context context expr-p beg-line col
        forward-sexp-function) ; Use the Lisp version.
    ;; Find the immediate context for indentation information, but
    ;; keep going to determine that point is at the N+1th line of
    ;; multiline JSX.
    (save-excursion
      (while
          (and
           (setq nth-context (js-jsx--context))
           (progn
             (unless context
               (setq context nth-context)
               (setq expr-p (and curly-pos (< (point) curly-pos))))
             (setq beg-line (line-number-at-pos))
             (and
              (= beg-line current-line)
              (or (not curly-pos) (> (point) curly-pos)))))))
    ;; When on the second or later line of JSX, indent as JSX,
    ;; possibly switching back to JS indentation within
    ;; JSXExpressionContainers, possibly using the JSX as a base
    ;; column while switching back to JS indentation.
    (when (and context (> current-line beg-line))
      (save-excursion
        (setq col (js-jsx--contextual-indentation current-line context)))
      (if expr-p
          (js-jsx--expr-indentation
           parse-status (js-jsx--expr-attribute-pos curly-pos (nth 1 context)) col)
        col))))