position of the first non-whitespace character after the beginning of
the line. The argument @var{node} is the largest (highest-in-tree)
node that starts at that position; and @var{parent} is the parent of
-@var{node}. Emacs finds @var{bol}, @var{node} and @var{parent} and
+@var{node}. However, when that position is on a whitespace or inside
+a multi-line string, no node that starts at that position, so
+@var{node} is @code{nil}. In that case, @var{parent} would be the
+smallest node that spans that position.
+
+Emacs finds @var{bol}, @var{node} and @var{parent} and
passes them to each @var{matcher} and @var{anchor}. @var{matcher}
should return non-@code{nil} if the rule is applicable, and
@var{anchor} should return a buffer position.
(lambda (_n parent &rest _)
(save-excursion
(goto-char (treesit-node-start parent))
- (back-to-indentation)
- (point)))))
+ (current-indentation)))))
(prev-sibling . ,(byte-compile
(lambda (node &rest _)
(treesit-node-start
(smallest-node
(cond ((null (treesit-parser-list)) nil)
((eq 1 (length (treesit-parser-list)))
- (treesit-node-at bol))
+ (treesit-node-at bol nil nil t))
((treesit-language-at (point))
(treesit-node-at bol (treesit-language-at (point))))
(t (treesit-node-at bol))))
;; encompass the whitespace.
(parent (cond ((and node parser)
(treesit-node-parent node))
- (parser
- (treesit-node-at bol parser))
- (t nil))))
+ (t (treesit-node-on bol bol)))))
(funcall treesit-indent-function node parent bol))))
(defun treesit-indent ()
"Indent according to the result of `treesit-indent-function'."
(treesit-update-ranges)
- (pcase-let* ((orig-pos (point))
- (bol (current-indentation))
- (`(,anchor . ,offset) (treesit--indent-1)))
+ (pcase-let* ((`(,anchor . ,offset) (treesit--indent-1)))
(when (and anchor offset)
(let ((col (+ (save-excursion
(goto-char anchor)
(current-column))
offset)))
- (if (< bol orig-pos)
- (save-excursion
- (indent-line-to col))
- (indent-line-to col))))))
+ (indent-line-to col)))))
(defvar treesit--indent-region-batch-size 400
"How many lines of indent value do we precompute.