[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: |
Tue, 30 Aug 2022 09:25:31 -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.
===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.
============================================================
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), (continued)
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/29
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Eli Zaretskii, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Eli Zaretskii, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Juri Linkov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Eli Zaretskii, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Sean Whitton, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Eli Zaretskii, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349),
Alfred M. Szmidt <=
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Po Lu, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Alfred M. Szmidt, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Alfred M. Szmidt, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Stefan Monnier, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Lars Ingebrigtsen, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Dmitry Gutov, 2022/08/30
- Re: master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349), Lars Ingebrigtsen, 2022/08/30