[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: editing a VC diff to modify the current version
From: |
emacsq |
Subject: |
Re: editing a VC diff to modify the current version |
Date: |
Fri, 25 Feb 2022 16:19:01 +0000 |
> > 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)))))