Function: just-src-edit--sync-to-original

just-src-edit--sync-to-original is a natively compiled function defined in just-ts-mode.el.

Signature

(just-src-edit--sync-to-original SAVE-FILE)

Documentation

Sync the edited content back to the original buffer.

If SAVE-FILE is non-nil, also save the original buffer.

Source Code

;; Defined in /nix/store/1vmf8s52d6vniw28ckf3szxslimhfphb-emacs-packages-deps/share/emacs/site-lisp/elpa/just-ts-mode-20260319.1513/just-ts-mode.el
(defun just-src-edit--sync-to-original (save-file)
  "Sync the edited content back to the original buffer.
If SAVE-FILE is non-nil, also save the original buffer."
  (unless (and just-src-edit--original-buffer
               (buffer-live-p just-src-edit--original-buffer))
    (error "Original buffer no longer exists"))

  (let ((content (string-trim-right (buffer-string) "\n+"))
        (original-buf just-src-edit--original-buffer)
        (beg just-src-edit--beg-marker)
        (end just-src-edit--end-marker)
        (indent just-src-edit--indentation))

    (with-current-buffer original-buf
      (save-excursion
        (let ((indented-content (just-src-edit--add-indentation content indent)))
          (goto-char beg)
          (delete-region beg end)
          (insert indented-content)
          (set-marker end (point))))

      (when save-file
        (save-buffer)))

    (set-buffer-modified-p nil)))