unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#54975: Allow editing diffs for conveniently fixing typos in the modified file right in the diff buffer
@ 2022-04-16 18:11 emacsq via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; only message in thread
From: emacsq via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-04-16 18:11 UTC (permalink / raw)
  To: 54975

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-16 18:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-16 18:11 bug#54975: Allow editing diffs for conveniently fixing typos in the modified file right in the diff buffer emacsq via Bug reports for GNU Emacs, the Swiss army knife of text editors

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