unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: "Alfred M. Szmidt" <ams@gnu.org>
Cc: Eli Zaretskii <eliz@gnu.org>,
	 larsi@gnus.org,  juri@jurta.org, emacs-devel@gnu.org
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 07:26:47 +0000	[thread overview]
Message-ID: <874jxnha6g.fsf@posteo.net> (raw)
In-Reply-To: <E1oT1FD-0006Ip-2M@fencepost.gnu.org> (Alfred M. Szmidt's message of "Tue, 30 Aug 2022 09:25:31 -0400")

"Alfred M. Szmidt" <ams@gnu.org> writes:

>    > >     '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?

> ===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.
> ============================================================



  parent reply	other threads:[~2022-09-04  7:26 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <166171593185.16640.41619657947456727@vcs2.savannah.gnu.org>
     [not found] ` <20220828194533.23A6BC00889@vcs2.savannah.gnu.org>
2022-08-28 21:18   ` master 4803fba487 1/2: 'C-x v v' on a diff buffer commits it as a patch (bug#52349) Sean Whitton
2022-08-29  4:50     ` Manuel Uberti
2022-08-29 16:40     ` Daniel Martín
2022-08-29 14:48   ` Lars Ingebrigtsen
2022-08-29 16:46     ` Eli Zaretskii
2022-08-29 17:05       ` Dmitry Gutov
2022-08-29 17:41         ` Eli Zaretskii
2022-08-29 19:03           ` Tassilo Horn
2022-08-29 19:31             ` Eli Zaretskii
2022-08-29 20:36           ` Dmitry Gutov
2022-08-30 11:25             ` Eli Zaretskii
2022-08-30 12:35               ` Dmitry Gutov
2022-08-30 13:01                 ` Eli Zaretskii
2022-08-30 13:52                   ` Dmitry Gutov
2022-08-30 16:20                     ` Eli Zaretskii
2022-08-30 17:33                       ` Dmitry Gutov
2022-08-30 16:47                 ` Juri Linkov
2022-08-30 17:05                   ` Eli Zaretskii
2022-08-30 17:11                     ` Dmitry Gutov
2022-08-30 17:37                       ` Eli Zaretskii
2022-08-30 17:39                         ` Dmitry Gutov
2022-08-30 17:18                     ` Juri Linkov
2022-08-30  7:20         ` Juri Linkov
2022-08-30 11:54           ` Eli Zaretskii
2022-08-30 14:49             ` Sean Whitton
2022-08-30 16:39               ` Juri Linkov
2022-08-30 16:45               ` Eli Zaretskii
2022-08-31  2:38                 ` Richard Stallman
2022-08-31 15:48                 ` Jonas Bernoulli
2022-08-31  2:38               ` Richard Stallman
2022-09-01  0:32                 ` Sean Whitton
2022-09-01  0:33                   ` Sean Whitton
2022-08-30 11:56           ` Eli Zaretskii
2022-08-30 12:03           ` Dmitry Gutov
2022-09-01 20:13             ` Dmitry Gutov
2022-08-30 13:25       ` Alfred M. Szmidt
2022-08-30 13:42         ` Po Lu
2022-08-30 14:02           ` Alfred M. Szmidt
2022-10-25 19:22           ` Dmitry Gutov
2022-08-30 14:08         ` Dmitry Gutov
2022-08-30 14:20           ` Alfred M. Szmidt
2022-08-30 14:38             ` Dmitry Gutov
2022-08-30 15:16               ` Stefan Monnier
2022-08-30 15:26                 ` Dmitry Gutov
2022-08-30 15:33                   ` Lars Ingebrigtsen
2022-08-30 15:45                     ` Dmitry Gutov
2022-08-30 15:53                       ` Lars Ingebrigtsen
2022-08-30 18:36                   ` Stefan Monnier
2022-08-30 20:59                     ` Dmitry Gutov
2022-08-30 16:50                 ` Eli Zaretskii
2022-08-31  6:51                   ` Alfred M. Szmidt
2022-08-30 16:37               ` Eli Zaretskii
2022-08-30 16:45                 ` Lars Ingebrigtsen
2022-08-30 17:02                   ` Eli Zaretskii
2022-08-30 17:11                     ` Lars Ingebrigtsen
2022-08-30 17:34                       ` Eli Zaretskii
2022-08-30 17:38                         ` Lars Ingebrigtsen
2022-08-30 19:23                       ` Sean Whitton
2022-08-30 17:10                 ` Dmitry Gutov
2022-08-31  1:28               ` Po Lu
2022-08-31  2:32                 ` Dmitry Gutov
2022-08-31  6:53                   ` Juri Linkov
2022-08-31  9:55                     ` Lars Ingebrigtsen
2022-08-31 10:35                       ` Dmitry Gutov
2022-08-31 10:37                         ` Lars Ingebrigtsen
2022-08-31 11:09                           ` Dmitry Gutov
2022-08-31 15:42                             ` Lars Ingebrigtsen
2022-08-31 16:24                               ` Dmitry Gutov
2022-08-31 16:39                                 ` Lars Ingebrigtsen
2022-08-31 18:02                                   ` Dmitry Gutov
2022-09-01 10:16                                     ` Lars Ingebrigtsen
2022-09-01 11:31                                       ` Dmitry Gutov
2022-09-01 11:45                                         ` Lars Ingebrigtsen
2022-09-01 11:48                                           ` Dmitry Gutov
2022-09-01 11:57                                             ` Eli Zaretskii
2022-10-17  0:11                                             ` Dmitry Gutov
2022-10-17 19:17                                               ` Juri Linkov
2022-09-01 13:26                                           ` Robert Pluim
2022-09-01 13:28                                             ` Dmitry Gutov
2022-09-01 13:32                                               ` Robert Pluim
2022-09-03  2:51                                             ` Richard Stallman
2022-09-04 12:27                                               ` Alfred M. Szmidt
2022-08-31 11:11                     ` Dmitry Gutov
2022-08-31 16:06                       ` Juri Linkov
2022-08-31 16:21                         ` Dmitry Gutov
2022-08-31 16:36                           ` Eli Zaretskii
2022-10-16 23:53                             ` Dmitry Gutov
2022-10-16 23:54                               ` Dmitry Gutov
2022-08-31 16:41                           ` Dmitry Gutov
2022-08-31 11:23                   ` Eli Zaretskii
2022-08-31 11:57                     ` Dmitry Gutov
2022-08-31 12:36                       ` Eli Zaretskii
2022-09-04  7:26         ` Philip Kaludercic [this message]
2022-09-04 12:27           ` Alfred M. Szmidt
2022-09-04 17:07             ` Philip Kaludercic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jxnha6g.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=ams@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).