unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: emacsq via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 54975@debbugs.gnu.org
Subject: bug#54975: Allow editing diffs for conveniently fixing typos in the modified file right in the diff buffer
Date: Sat, 16 Apr 2022 18:11:41 +0000	[thread overview]
Message-ID: <8rrjr29NBSKGou_PjjyQeWGVN5_wlpYrCGGyk9xY3RnfWF69VXcT9bRUCcDS2ZxM3QxgKNpkUCsV04Ga40eDBDMwO1fJyY-c_6uCMb92eAM=@protonmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1563 bytes --]

One of the main usage of diff is perusing changes before committing (commit commands usually pop up a diff buffer showing the changes) . When doing this one often finds typos, small things to fix in the diff, so one has to go back the file, fix it, do a diff/commit again to see the changes, etc.

To make this case more convenient, allow editing of diffs with the changes reflected in the original file.

The key 'e' is unused in diff mode, so like in occur it can turn on editing mode for the diff buffer. When the user edits the diff, the changes are reflected in the original file. C-c C-c ends the edit mode and also saves the the modified file, so the user doesn't have to manually switch to the file to save it, before committing, for example.

Here's a simple proof of concept code with advice which demonstrates the feature (going to to edit mode and saving are not included, only the reflection of the changes, so you have to toggle the diff buffer to writable first):

(advice-add 'diff-after-change-function :after 'my-diff-after-change-function)
;;(advice-remove 'diff-after-change-function 'my-diff-after-change-function)

(defun my-diff-after-change-function (start end len)
(ignore-errors
(if (eq len 0) ;; insertion
(if (eq ?- (char-after (line-beginning-position)))
(message "changes in deleted parts are not reflected")

(let ((text (buffer-substring-no-properties start end)))
(save-selected-window
(diff-goto-source)
(forward-char (- (length text)))
(insert text))))

;; deletion
(save-selected-window
(diff-goto-source)
(delete-char len)))))

[-- Attachment #2: Type: text/html, Size: 2664 bytes --]

                 reply	other threads:[~2022-04-16 18:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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='8rrjr29NBSKGou_PjjyQeWGVN5_wlpYrCGGyk9xY3RnfWF69VXcT9bRUCcDS2ZxM3QxgKNpkUCsV04Ga40eDBDMwO1fJyY-c_6uCMb92eAM=@protonmail.com' \
    --to=bug-gnu-emacs@gnu.org \
    --cc=54975@debbugs.gnu.org \
    --cc=laszlomail@protonmail.com \
    /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).