Function: apheleia--create-rcs-patch

apheleia--create-rcs-patch is a natively compiled function defined in apheleia-formatters.el.

Signature

(apheleia--create-rcs-patch OLD-BUFFER NEW-BUFFER REMOTE CALLBACK)

Documentation

Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER.

Once finished, invoke CALLBACK with a buffer containing the patch as its sole argument.

See apheleia--run-formatters for a description of REMOTE.

Source Code

;; Defined in /nix/store/lwcwryzabcmvjcwwzzs65jrwf7p7d7cs-emacs-packages-deps/share/emacs/site-lisp/elpa/apheleia-20260915.1628/apheleia-formatters.el
(defun apheleia--create-rcs-patch (old-buffer new-buffer remote callback)
  "Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER.
Once finished, invoke CALLBACK with a buffer containing the patch
as its sole argument.

See `apheleia--run-formatters' for a description of REMOTE."
  (apheleia--log
   'rcs "Creating RCS patch between buffers with %d and %d bytes"
   (buffer-size old-buffer) (buffer-size new-buffer))
  ;; Make sure at least one of the two buffers is saved to a file. The
  ;; other one we can feed on stdin.
  (let ((old-fname
         (with-current-buffer old-buffer
           (and (not (buffer-modified-p)) buffer-file-name)))
        (new-fname
         (with-current-buffer new-buffer
           (and (not (buffer-modified-p)) buffer-file-name)))
        ;; Place any temporary files we must delete in here.
        (clear-files nil)
        (run-on-remote (and (eq apheleia-remote-algorithm 'remote)
                            remote)))
    (cl-labels ((;; Weird indentation because of differences in Emacs
                 ;; indentation algorithm between 27 and 28
                 apheleia--make-temp-file-for-rcs-patch
                 (buffer &optional fname)
                 ;; Ensure there's a file with the contents of `buffer' on the
                 ;; target machine. `fname', if given, refers to an existing
                 ;; file that may not exist on the target machine and needs
                 ;; to be copied over.
                 (let ((fname-remote (and fname (file-remote-p fname))))
                   (when (or (not fname)
                             (not (equal run-on-remote fname-remote)))
                     (setq fname
                           (apheleia--make-temp-file run-on-remote "apheleia"))
                     (push fname clear-files)
                     (with-current-buffer buffer
                       (apheleia--write-region-silently
                        (point-min) (point-max) fname)))
                   (apheleia-formatters-local-buffer-file-name fname))))
      ;; Ensure file is on target right machine, or create a copy of it.
      (when old-fname
        (setq old-fname
              (apheleia--make-temp-file-for-rcs-patch old-buffer old-fname)))
      (when new-fname
        (setq new-fname
              (apheleia--make-temp-file-for-rcs-patch new-buffer new-fname)))
      ;; When neither files have an open file-handle, create one.
      (unless (or old-fname new-fname)
        (setq new-fname (apheleia--make-temp-file-for-rcs-patch new-buffer))))

    (let ((ctx (apheleia-formatter--context)))
      (setf (apheleia-formatter--name ctx) nil ; Skip logging on failure
            (apheleia-formatter--arg1 ctx)
            ;; Search gdiff in PATH, else use diff, useful for BSD
            (if (executable-find "gdiff") "gdiff"
              "diff")
            (apheleia-formatter--argv ctx) `("--rcs"
                                             "--strip-trailing-cr"
                                             "--text"
                                             "--"
                                             ,(or old-fname "-")
                                             ,(or new-fname "-"))
            (apheleia-formatter--remote ctx) remote
            (apheleia-formatter--stdin ctx)
            (if new-fname old-buffer new-buffer))

      (apheleia--execute-formatter-process
       :ctx ctx
       :callback callback
       :ensure
       (lambda ()
         (dolist (file clear-files)
           (ignore-errors
             (delete-file file))))
       ;; Exit status is 0 if no changes, 1 if some changes, and 2 if
       ;; error.
       :exit-status (lambda (status) (memq status '(0 1)))))))