emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a pa


From: Alfred M. Szmidt
Subject: Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349)
Date: Sun, 04 Sep 2022 08:27:05 -0400

   >    > >     'C-x v v' on a diff buffer commits it as a patch (bug#52349)
   >    > 
   >    > Excellent!  This is going to save me a lot of work in the future.
   >
   >    Bother: This is only supported for Git, which is against the spirit of
   >    VC, and definitely against the spirit of "C-x v v".
   >
   > This is a pitty indeed.  Specially seeing that it is easy enough to
   > get this working for all VCSs.  Here is a hack I wrote ages ago, and
   > this works for just about everything, it doesn't do exactly what is
   > needed (e.g, this works on a single file basis) but it isn't too hard
   > to get that working.

   This feature looks very interesting to me.  Could it be added to vc or
   as an package to GNU ELPA?

Isn't it the same feature as being implemented (in a better manner)?

   > ===File ~/diff-commit-hunk.el===============================
   > ;;;; diff-commit-hunk.el --- commit parts of a hunk in `diff-mode'
   >
   > (require 'diff-mode)
   >
   > (defun current-buffer-file-name ()
   >   (buffer-file-name (current-buffer)))
   >
   > (defun restore-source-file ()
   >   (with-current-buffer (current-buffer)
   >     (erase-buffer)
   >     (insert-buffer "*diff-commit-hunk*")
   >     (write-file (current-buffer-file-name)))
   >   (remove-hook 'vc-checkin-hook 'restore-source-file))
   >
   > (defmacro with-original-file (&rest body)
   >   "Reverts associated source file temporarily in a `diff-mode'
   > buffer to the latest found in VCS, executes BODY and commits the
   > changes back VCS."
   >   `(progn
   >      (save-excursion
   >        (diff-goto-source)
   >        (let ((buf (current-buffer)))
   >     (with-current-buffer (get-buffer-create "*diff-commit-hunk*")
   >       (erase-buffer)
   >       (insert-buffer buf)))
   >        (vc-revert-file (current-buffer-file-name)))
   >      ,@body
   >      (save-excursion
   >        (diff-goto-source)
   >        (write-file (current-buffer-file-name))
   >        (add-hook 'vc-checkin-hook 'restore-source-file)
   >        (vc-checkin (list (current-buffer-file-name))
   >               (vc-backend (current-buffer-file-name))))))
   >
   > ;;;###autoload
   > (defun diff-commit-hunk ()
   >   "Revert associated source file to the latest version from VCS,
   > and apply (and commit) current hunk."
   >   (interactive)
   >   (with-original-file
   >    (let ((diff-advance-after-apply-hunk nil))
   >      (diff-apply-hunk))))
   >
   > ;;;###autoload
   > (defun diff-commit-all ()
   >   "Like `diff-commit-hunk', but applies all hunks in the current
   > diff buffer."
   >   (interactive)
   >   (with-original-file
   >    (goto-char (point-min))
   >    (diff-hunk-next)                        ;Skip header.
   >    (while (not (eobp))
   >      (diff-apply-hunk))))
   >
   > (define-key diff-mode-map (kbd "s-a") #'diff-commit-hunk)
   > (define-key diff-mode-map (kbd "H-a") #'diff-commit-all)
   >
   > ;;;; diff-commit-hunk.el ends here.
   > ============================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]