Function: combobulate-refactor

combobulate-refactor is a macro defined in combobulate-manipulation.el.

Signature

(combobulate-refactor (&key (ID nil)) &rest BODY)

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-manipulation.el
(cl-defmacro combobulate-refactor ((&key (id nil)) &rest body)
  (declare (indent defun) (debug (sexp body)))
  (let ((--session (gensym))
        ;; non-nil if we're entering a session that already exists.
        (--pre-existing-session (gensym)))
    `(let ((,--pre-existing-session (combobulate-refactor--get-active-session ,id))
           (,--session (combobulate-refactor-setup ,id)))
       (cl-flet* ((add-marker (ov)
                    (overlay-put ov 'combobulate-refactor-session-id ,--session)
                    (push ov (alist-get ,--session combobulate-refactor--active-sessions))
                    ov)
                  (mark-range-move (beg end position)
                    (add-marker (combobulate--refactor-mark-move beg end position)))
                  (mark-range-deleted (beg end)
                    (add-marker (combobulate--refactor-mark-deleted beg end)))
                  (mark-range-highlighted (beg end &optional face advance)
                    (add-marker (combobulate--refactor-mark-highlighted beg end face advance)))
                  (mark-copy (start end)
                    (add-marker (combobulate--refactor-mark-copy start end 'combobulate-refactor--copied-values)))
                  (mark-node-copy (n)
                    (mark-copy (combobulate-node-start n) (combobulate-node-end n)))
                  (mark-range-indent (beg end target-pt baseline-column)
                    (add-marker (combobulate--refactor-mark-indent beg end target-pt baseline-column)))
                  (mark-node-deleted (n)
                    (add-marker (combobulate--refactor-mark-deleted (combobulate-node-start n)
                                                                    (combobulate-node-end n))))
                  (mark-range-label (beg end label &optional face before)
                    (add-marker (combobulate--refactor-mark-label beg end label face before)))
                  (mark-node-highlighted (n &optional face advance)
                    (mark-range-highlighted (combobulate-node-start n)
                                            (combobulate-node-end n)
                                            face
                                            advance))
                  (mark-cursor (pt)
                    (add-marker (combobulate--refactor-mark-cursor pt)))
                  (mark-node-cursor (n)
                    (mark-cursor (combobulate-node-start n)))
                  (mark-field (pt tag &optional text transformer-fn)
                    (add-marker (combobulate--refactor-mark-field
                                 pt tag (or text (symbol-name tag))
                                 transformer-fn)))
                  (toggle-field (pt tag)
                    (combobulate--refactor-toggle-field pt tag))
                  (update-field (tag text)
                    (seq-filter
                     (lambda (ov) (let ((actions (overlay-get ov 'combobulate-refactor-action)))
                               (combobulate--refactor-update-field ov tag text)))
                     (alist-get ,--session combobulate-refactor--active-sessions)))
                  (mark-point (&optional pt)
                    (add-marker (combobulate--refactor-mark-position (or pt (point)))))
                  (rollback ()
                    (combobulate-refactor-delete-session ,--session))
                  (commit ()
                    (setq combobulate-refactor--copied-values nil)
                    (mapc (lambda (ov) (combobulate--refactor-commit ov t))
                          (seq-sort (lambda (a b)
                                      (and a b
                                           (overlayp a)
                                           (overlayp b)
                                           (> (or (overlay-start a) 0)
                                              (or (overlay-end b) 0))))
                                    (alist-get ,--session combobulate-refactor--active-sessions)))
                    ;; clean up.
                    (rollback)))
         (condition-case err
             (prog1 (combobulate-atomic-change-group
                      ,@body)
               (when (and (alist-get ,--session combobulate-refactor--active-sessions)
                          (not ,--pre-existing-session))
                 (prog1
                     (signal 'combobulate-refactor-uncommitted-changes
                             (list (format "Uncommitted changes in session `%s'" ,--session)))
                   (combobulate-refactor-delete-session ,--session))))
           (t (rollback) (signal (car err) (cdr err))))))))