Function: combobulate-build-nested-query

combobulate-build-nested-query is a natively compiled function defined in combobulate-navigation.el.

Signature

(combobulate-build-nested-query NODES &optional INSERT-FN)

Documentation

Build a nested query from NODES and call INSERT-FN for each one.

The output is of the form:

  (A (B (C (D))))

Where NODES is a list of (A B C D) and query is a valid combobulate-query-search query.

The INSERT-FN is called with the following arguments:

        (INSERT-FN NODE REST-NODES BEFORE CT)

Where NODE is the current node; REST-NODES is the rest of the nodes to be processed; BEFORE indicates whether the function is called before NODE or after NODE; and CT is the number of nodes processed so far as an integer, with the inner-most node (the car in NODES) being 0.

The INSERT-FN should return a list (or nil, in which case nothing is inserted) to be *spliced into* into the query at that position. The nodes can be symbols, strings, or a list of the two.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-navigation.el
(defun combobulate-build-nested-query (nodes &optional insert-fn)
  "Build a nested query from NODES and call INSERT-FN for each one.

The output is of the form:

  (A (B (C (D))))

Where NODES is a list of (A B C D) and query is a valid
`combobulate-query-search' query.

The INSERT-FN is called with the following arguments:

        (INSERT-FN NODE REST-NODES BEFORE CT)

Where NODE is the current node; REST-NODES is the rest of the
nodes to be processed; BEFORE indicates whether the function is
called before NODE or after NODE; and CT is the number of nodes
processed so far as an integer, with the inner-most node (the
`car' in NODES) being 0.

The INSERT-FN should return a list (or nil, in which case nothing
is inserted) to be *spliced into* into the query at that
position.  The nodes can be symbols, strings, or a list of the
two."
  (let ((acc) (n) (ct 0) (insert-fn (or insert-fn #'ignore)))
    (while nodes
      (let ((node (pop nodes)))
        (setq n (pcase node
                  ((and (pred consp) n))
                  ((and (pred stringp) n) (make-symbol n))
                  ((and (pred symbolp) n) n)
                  ((and (pred combobulate-node-p) n)
                   (combobulate-query--node-type n))
                  ((and (pred combobulate-proxy-node-p) n)
                   (combobulate-query--node-type n))
                  (_ (error "Unknown node type"))))
        (setq acc (cons n (seq-remove
                           #'null `(,@(funcall insert-fn node nodes t ct)
                                    ,acc
                                    ,@(funcall insert-fn node nodes nil ct)))))
        (cl-incf ct)))
    acc))