Function: combobulate-procedure--mark-nodes

combobulate-procedure--mark-nodes is a natively compiled function defined in combobulate-procedure.el.

Signature

(combobulate-procedure--mark-nodes NODES &key MATCH-TYPES DISCARD-TYPES (DEFAULT-MARK '@match) (KEEP-ANONYMOUS nil) (OVERWRITE nil))

Documentation

Mark NODES with MATCH-TYPES and DISCARD-TYPES.

MATCH-TYPES and DISCARD-TYPES are lists of node types to match or discard, respectively.

If a node type is not in either list, it is marked with DEFAULT-MARK.

If the NODES are already marked, and OVERWRITE is non-nil, then overwrite the existing marks.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-procedure.el
(cl-defun combobulate-procedure--mark-nodes (nodes &key match-types discard-types
                                                   (default-mark '@match)
                                                   (keep-anonymous nil)
                                                   (overwrite nil))
  "Mark NODES with MATCH-TYPES and DISCARD-TYPES.

MATCH-TYPES and DISCARD-TYPES are lists of node types to match or
discard, respectively.

If a node type is not in either list, it is marked with
DEFAULT-MARK.

If the NODES are already marked, and OVERWRITE is non-nil, then
overwrite the existing marks."
  ;; The shorthand variable, `procedure-discard-rules', contains rules
  ;; we must add to the discard types check. This is usually just
  ;; `comment' as line-comments trip up tree-sitter, but other
  ;; languages may introduce their own rules.
  ;;
  ;; However, if the user specifically ASKS for a discard type, then
  ;; we should respect that and not discard it.
  (when combobulate-procedure-apply-shared-discard-rules
    (setq discard-types (append discard-types
                                (combobulate-procedure-expand-rules
                                 (combobulate-read procedure-discard-rules))))
    (when match-types (setq discard-types (seq-difference match-types discard-types))))
  (let ((marked-nodes))
    (pcase-dolist ((or `(,existing-mark . ,node) node) nodes)
      (let ((type (combobulate-node-type node)))
        (push
         (cons (if (and existing-mark (not overwrite))
                   existing-mark
                 (cond
                  ((or (member type match-types)
                       (and (combobulate-node-anonymous-p node)
                            keep-anonymous))
                   '@match)
                  ((member type discard-types) '@discard)
                  (existing-mark existing-mark)
                  (t default-mark)))
               node)
         marked-nodes)))
    (reverse marked-nodes)))