Function: c-ts-common--standalone-predicate

c-ts-common--standalone-predicate is a byte-compiled function defined in c-ts-common.el.gz.

Signature

(c-ts-common--standalone-predicate NODE)

Documentation

Return an anchor if NODE is on the start of a line.

Return nil if not. Handles method chaining. Caller needs to cal save-excursion.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-common.el.gz
(defun c-ts-common--standalone-predicate (node)
  "Return an anchor if NODE is on the start of a line.

Return nil if not.  Handles method chaining.  Caller needs to cal
`save-excursion'."
  (goto-char (treesit-node-start node))
  (or (and (looking-back (rx bol (* whitespace) (? "."))
                         (line-beginning-position))
           (point))
      ;; The above check is not enough, because often in a method
      ;; chaining, the method name is part of a node, and the arg list
      ;; is another node:
      ;;
      ;;     func       ---> func.method is one node.
      ;;     .method({
      ;;       return 1;     ({ return 1; }) is another node
      ;;     })
      ;;
      ;; So when we go up the parse tree, we go through the block
      ;; ({...}), then the next parent is already the whole call
      ;; expression, and we never stops at the beginning of "method".
      ;; Therefore we need this heuristic.
      (and (progn (back-to-indentation)
                  (eq (char-after) ?.))
           (point))))