Function: combobulate-procedure-apply-activation-nodes

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

Signature

(combobulate-procedure-apply-activation-nodes ACTIVATION-NODES ACTION-NODE)

Documentation

Apply ACTIVATION-NODES to NODE.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-procedure.el
(defun combobulate-procedure-apply-activation-nodes (activation-nodes action-node)
  "Apply ACTIVATION-NODES to NODE."
  (let ((result (combobulate-procedure-result-create
                 :activation-node nil
                 :action-node action-node
                 :parent-node nil
                 :matched-activation nil
                 :selected-nodes nil
                 :matched-selection nil)))
    (catch 'done
      (dolist (activation-node activation-nodes)
        (map-let (:nodes :position :has-parent :has-ancestor :has-fields)
            activation-node
          ;; Expand the rules in `:nodes' and determine if any of them match
          (let ((action-node-type (combobulate-node-type action-node))
                (expanded-nodes (combobulate-procedure-expand-rules nodes))
                (parent-node))
            (when (and
                   ;; action-node-type must be one of the expanded rules
                   (member action-node-type expanded-nodes)
                   ;; Position should be at the start of the node;
                   ;; inside the node, but not at the end nor the
                   ;; beginning; or either.
                   (cond
                    ((or (eq position 'any) (null position))
                     (or (combobulate-point-at-beginning-of-node-p action-node)
                         (combobulate-point-in-node-range-p action-node)))
                    ((eq position 'in)
                     (and (combobulate-point-in-node-range-p action-node)
                          ;; `combobulate-point-in-node-range-p' is non-nil if
                          ;; we're at the start of the node, but that is
                          ;; not allowed here.
                          (not (combobulate-point-at-beginning-of-node-p action-node))))
                    ((eq position 'at)
                     (combobulate-point-at-beginning-of-node-p action-node))
                    (t (error "Unknown `:position' specifier `%s'" position)))
                   (or (and has-fields (combobulate-procedure-apply-has-field has-fields action-node))
                       (not has-fields))
                   ;; If `:has-parent' or `:has-ancestor' is
                   ;; specified, then check the parents of the
                   ;; action node.
                   (or (and has-parent
                            (setq parent-node (combobulate-procedure-apply-has-parent
                                               has-parent action-node)))
                       (and has-ancestor
                            (setq parent-node (combobulate-procedure-apply-has-ancestor
                                               has-ancestor action-node)))
                       ;; If none of the :has-* conditions are specified,
                       ;; then we can just continue.
                       (not (or has-parent has-ancestor))))
              (setf (combobulate-procedure-result-activation-node result) activation-node
                    (combobulate-procedure-result-parent-node result) parent-node
                    (combobulate-procedure-result-matched-activation result) t)
              (throw 'done result))))))))