Function: combobulate-execute-envelope

combobulate-execute-envelope is a natively compiled function defined in combobulate-envelope.el.

Signature

(combobulate-execute-envelope ENVELOPE-NAME &optional NODE FORCE)

Documentation

Executes any envelope with a :name equal to ENVELOPE-NAME.

See combobulate-apply-envelope for more information.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-envelope.el
(defun combobulate-execute-envelope (envelope-name &optional node force)
  "Executes any envelope with a `:name' equal to ENVELOPE-NAME.

See `combobulate-apply-envelope' for more information."
  (let ((envelope (combobulate-get-envelope-by-name envelope-name))
        ;; Default to true as we'll only turn this off briefly when we
        ;; expand an envelope during a proffer preview.
        (combobulate-envelope--undo-on-quit t)
        (chosen-node) (accepted nil))
    (unless envelope
      (error "There is no such envelope registered with the name `%s'"
             envelope-name))
    (if (region-active-p)
        (combobulate-apply-envelope envelope nil t)
      (if node
          (when-let (target-pt (cdr (combobulate-apply-envelope envelope node)))
            (goto-char target-pt))
        (map-let (:nodes :shorthand :split-node) envelope
          (let* ((combobulate-envelope-static t)
                 (envelope-nodes (seq-sort #'combobulate-envelope-smart-sort
                                           (if (or nodes shorthand)
                                               (combobulate-envelope-get-applicable-nodes envelope force)
                                             ;; if we don't have any assigned envelope nodes,
                                             ;; create a proxy node at point; that node (and
                                             ;; thus `point') will instead be where the
                                             ;; envelope is inserted.
                                             (list (combobulate-proxy-node-make-point-node))))))
            ;; Walk through the collected envelope nodes and
            ;; determine if point is at the beginning of any of
            ;; them. If that is not the case, we'll create a
            ;; pseudo-node at point that extends to the farthest of
            ;; the envelope nodes.
            (when (and envelope-nodes
                       split-node
                       (not (seq-find #'combobulate-point-at-node-p envelope-nodes)))
              (let* ((source-node (or
                                   (let ((point-node (combobulate-node-at-point)))
                                     (seq-find (lambda (parent-node)
                                                 (> (combobulate-node-end parent-node)
                                                    (combobulate-node-end point-node)))
                                               (combobulate-get-parents point-node)))
                                   (car (seq-sort #'combobulate-node-larger-than-node-p
                                                  envelope-nodes))))
                     (split-node (combobulate-proxy-node-make-from-range
                                  (point)
                                  (combobulate-node-end source-node)
                                  "split-node" (format "Split %s" (combobulate-pretty-print-node-type source-node)))))
                (setq envelope-nodes (append (list split-node) envelope-nodes))))
            (setq chosen-node
                  (combobulate-proffer-choices
                   envelope-nodes
                   (lambda-slots (current-node refactor-id)
                     (combobulate-refactor (:id refactor-id)
                       (let ((ov (mark-node-highlighted current-node))
                             (combobulate-envelope--undo-on-quit nil))
                         (seq-let [[start &rest end] &rest pt]
                             (combobulate-apply-envelope envelope current-node)
                           (goto-char pt)
                           ;; lil' hack. The extent of the node is not
                           ;; the same as the envelope we just
                           ;; applied.
                           (move-overlay ov start end)))))
                   :reset-point-on-abort t
                   :reset-point-on-accept nil))
            (setq accepted t)))
        ;; here we simply repeat what ever the selected choice was, as
        ;; an explicit node skips the proffering process entirely.
        (when (and chosen-node accepted)
          (combobulate-execute-envelope envelope-name chosen-node))))))