Function: c-ts-mode--preproc-offset

c-ts-mode--preproc-offset is a byte-compiled function defined in c-ts-mode.el.gz.

Signature

(c-ts-mode--preproc-offset N P &rest _)

Documentation

This anchor is used for preprocessor directives.

Because node is nil at the moment of indentation, we use treesit-node-on to capture the anonymous node covering the newline. If the grand-parent of that node is the translation_unit itself, we don't indent. Otherwise, just indent one step according to the great-grand-parent indent level. The reason there is a difference between grand-parent and great-grand-parent here is that the node containing the newline is actually the parent of point at the moment of indentation.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/c-ts-mode.el.gz
;;; Indent

(defun c-ts-mode--preproc-offset (_n _p &rest _)
  "This anchor is used for preprocessor directives.

Because node is nil at the moment of indentation, we use
`treesit-node-on' to capture the anonymous node covering the
newline.  If the grand-parent of that node is the
translation_unit itself, we don't indent.  Otherwise, just indent
one step according to the great-grand-parent indent level.  The
reason there is a difference between grand-parent and
great-grand-parent here is that the node containing the newline
is actually the parent of point at the moment of indentation."
  (when-let* ((node (treesit-node-on (point) (point))))
    (if (string-equal "translation_unit"
                      (treesit-node-type
                       (treesit-node-parent
                        (treesit-node-parent node))))
        0
      c-ts-mode-indent-offset)))