From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Alfred M. Szmidt" Newsgroups: gmane.emacs.devel Subject: Re: On the adoption of transient.el Date: Sat, 07 Aug 2021 21:42:33 -0400 Message-ID: References: <877di4on3d.fsf@posteo.net> <87im1oy6mw.fsf@posteo.net> <87y29hihea.fsf@posteo.net> <87sfzonu6k.fsf@ucl.ac.uk> <878s1gqlop.fsf@gmail.com> <8735ronpo0.fsf@ucl.ac.uk> <83lf5gjgtp.fsf@gnu.org> <87eeb8gdbq.fsf@telefonica.net> <877dgzebux.fsf@mail.linkov.net> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14821"; mail-complaints-to="usenet@ciao.gmane.io" Cc: ofv@wanadoo.es, emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Aug 08 03:43:21 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCXqS-0003fy-LP for ged-emacs-devel@m.gmane-mx.org; Sun, 08 Aug 2021 03:43:20 +0200 Original-Received: from localhost ([::1]:38952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCXqR-0002r7-Fh for ged-emacs-devel@m.gmane-mx.org; Sat, 07 Aug 2021 21:43:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mCXpj-0002At-4F for emacs-devel@gnu.org; Sat, 07 Aug 2021 21:42:35 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:44552) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mCXph-0006yW-AF; Sat, 07 Aug 2021 21:42:33 -0400 Original-Received: from ams by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1mCXph-000755-6H; Sat, 07 Aug 2021 21:42:33 -0400 In-Reply-To: <877dgzebux.fsf@mail.linkov.net> (message from Juri Linkov on Fri, 06 Aug 2021 02:20:06 +0300) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:272187 Archived-At: Currently I'm finishing implementation of a new vc command that will allow committing from a diff buffer. This sounds similar to my diff-commit-hunk.el hack; but it is entierly VC agonstic. So for example, after displaying all changes with e.g. 'C-x v D' you can remove some unneeded hunks (with e.g. 'M-k' 'diff-hunk-kill'), then on the remaining hunks type 'C-c C-c' in the diff buffer. It will create a usual *vc-log* buffer where typing 'C-c C-c' will commit only changes from the diff buffer. Internally it works by running three git commands: `git stash push -m stash_name -- list_of_file_names_from_diff` `cat diff_buffer.patch | git am` # should also handle return code `git stash pop -q` ===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. ============================================================