Function: majutsu-blob-edit--write-contents

majutsu-blob-edit--write-contents is a natively compiled function defined in majutsu-file.el.

Signature

(majutsu-blob-edit--write-contents)

Documentation

Apply blob edits through `jj diffedit` and finish save.

This function is used from write-contents-functions in editable blob mode.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-file.el
(defun majutsu-blob-edit--write-contents ()
  "Apply blob edits through `jj diffedit` and finish save.
This function is used from `write-contents-functions' in editable blob mode."
  (if (not majutsu-blob-edit-mode)
      nil
    (unless (and majutsu-buffer-blob-root
                 majutsu-buffer-blob-path
                 majutsu-buffer-blob-revision)
      (user-error "Missing blob context for editable save"))
    (let ((current (buffer-substring-no-properties (point-min) (point-max))))
      (if (equal current majutsu-blob-edit--original-content)
          (progn
            (set-buffer-modified-p nil)
            (majutsu-blob-edit-mode -1)
            t)
        (let ((exit (majutsu-blob-edit--apply-diffedit current)))
          (if (zerop exit)
              (progn
                (when-let* ((rev-info (majutsu-file--resolve-single-rev-info
                                       majutsu-buffer-blob-revset))
                            (new-change (plist-get rev-info :change-id)))
                  (setq majutsu-buffer-blob-revision new-change)
                  (setq majutsu-buffer-blob-change-id new-change)
                  (setq majutsu-buffer-blob-commit-id (plist-get rev-info :commit-id))
                  (majutsu-file--refresh-buffer-name))
                (setq majutsu-blob-edit--original-content current)
                (set-buffer-modified-p nil)
                (majutsu-blob-edit-mode -1)
                (setq-local majutsu-buffer-blob-content-hash
                            (secure-hash 'sha1 current))
                (message "Blob edits applied via jj diffedit")
                t)
            (user-error "Failed to apply blob edits (exit %s)" exit)))))))