Function: combobulate--refactor-commit

combobulate--refactor-commit is a natively compiled function defined in combobulate-manipulation.el.

Signature

(combobulate--refactor-commit OV &optional DESTROY-OVERLAY)

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-manipulation.el
(defun combobulate--refactor-commit (ov &optional destroy-overlay)
  (if-let ((actions (overlay-get ov 'combobulate-refactor-actions)))
      (let* ((buf (overlay-buffer ov))
             (ov-start (overlay-start ov))
             (ov-end (overlay-end ov)))
        (when buf
          (dolist (action actions)
            (when combobulate-debug
              (princ (format "action: %s (ov %s)\n" action ov)))
            (pcase action
              (`(copy-region ,target-var)
               (push (buffer-substring-no-properties
                      (max (point-min) ov-start)
                      (min (point-max) (save-excursion
                                         (goto-char ov-end)
                                         (cond
                                          ((looking-at "\n") (1+ ov-end))
                                          ((looking-at " ") (+
                                                             (- (match-end 0)
                                                                (match-beginning 0))
                                                             ov-end))
                                          (t ov-end)))))
                     (symbol-value target-var)))
              (`(move ,beg ,end ,position)
               (let ((pos position)
                     (trailing-newlines (combobulate-count-lines-ahead end)))
                 (save-excursion
                   (goto-char position)
                   (combobulate--place-node-or-text
                    position
                    (prog1 (combobulate--delete-text beg end t t)
                      (goto-char pos))
                    nil
                    (> trailing-newlines 1)))))
              ('(delete-region)
               ;; detect single-char overlays with newlines.
               (unless (string-blank-p (buffer-substring ov-start ov-end))
                 (delete-region ov-start ov-end)))
              (`(indent ,pt ,baseline-column)
               (combobulate-indent-region ov-start ov-end pt baseline-column))
              ('(set-point)
               (goto-char ov-start))
              (`(field . ,_))
              ;; do nothing - their action is part of the overlay
              ('(highlighted))
              ('(labelled))
              ('(cursor))
              (_ (error "Unknown refactor commit action `%s'" action)))))
        (when destroy-overlay
          (delete-overlay ov)))
    (error "Overlay `%s' does not have a `combobulate-refactor-action's property" ov)))