unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: emacsq <laszlomail@protonmail.com>
To: emacsq via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: editing a VC diff to modify the current version
Date: Fri, 25 Feb 2022 16:19:01 +0000	[thread overview]
Message-ID: <apoW1mfaIT1YhQWDLxYp966AhR-xHSBxwDnotJ6i-wpX54JSYleHUp-N1Rs0WQntZakJkaQc8tmTO2LK3u8EI35_1wrRQ8R4aWvJfkKb7Ss=@protonmail.com> (raw)
In-Reply-To: <LAbyoVNVIvBhIG9719Ay1kXiXj1KXRwWwUPuNLXN1UMSfcf06ZUjnSnBBm9a6Cj04nHftMNaiZhQGUX8jmozQ5LeWqZ2IqQbXmQi6dw1hdA=@protonmail.com>

> > With vscode you can actually edit the diff and the changes are
> > reflected back to the current version, so you don't have to go back to
> > the file, do the modifications, make a diff again to see everything is
> > right, etc.
>
> Sounds like a great feature.

Here's a quick hack for emacs. If you activate this then after making the
diff editable you can make simple fixes in the diff and they are reflected
back to the current file. Adding newlines doesn't seem to work, but
fixing typos, making edits within lines do.

If one mainly uses diffs to review changes before committing then automatic
saving of the current file can also be added, so one doesn't have to go
back to the file just to save the changes made in the diff.

(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)))))





      parent reply	other threads:[~2022-02-25 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24  2:22 editing a VC diff to modify the current version emacsq via Users list for the GNU Emacs text editor
2022-02-24  2:37 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-02-24  4:19 ` emacsq via Users list for the GNU Emacs text editor
2022-02-24  4:29 ` Prabath Liyanage
2022-02-25 16:19 ` emacsq [this message]

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='apoW1mfaIT1YhQWDLxYp966AhR-xHSBxwDnotJ6i-wpX54JSYleHUp-N1Rs0WQntZakJkaQc8tmTO2LK3u8EI35_1wrRQ8R4aWvJfkKb7Ss=@protonmail.com' \
    --to=laszlomail@protonmail.com \
    --cc=help-gnu-emacs@gnu.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.
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).