unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* editing a VC diff to modify the current version
@ 2022-02-24  2:22 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
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: emacsq via Users list for the GNU Emacs text editor @ 2022-02-24  2:22 UTC (permalink / raw)
  To: emacsq via Users list for the GNU Emacs text editor

When I tried vscode I found an interesting feature:

When I modify a file under VC then I always make a diff before checkin to see everything is right. Sometimes the changes have a typo or a simple modification occurs to me which could be done right in the diff. 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.

Emacs' manual mentions this about editing diffs:

You can edit a Diff mode buffer like any other buffer. (If it is read-only, you need to make it writable first; see[Misc Buffer](https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-Buffer.html).) Whenever you edit a hunk, Diff mode attempts to automatically correct the line numbers in the hunk headers, to ensure that the patch remains correct, and could still be applied bypatch. To disable automatic line number correction, change the variablediff-update-on-the-flytonil.

So it seems like emacs supports the other direction, treating the diff as a patch file which can be applied to the original to get the current version.

These days comparing the current file to the last version under VC seems more usual, people more often make diffs before commit to see if their current changes are right, than doing it to make sure the patch file they create is correct.

Can emacs support the workflow described above? That is applying edits in the diff buffer automatically to the file on disk. If not then it could be a useful improvement.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editing a VC diff to modify the current version
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-02-24  2:37 UTC (permalink / raw)
  To: help-gnu-emacs

> 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.  I'd love to see such a thing added to `diff-mode`.

> So it seems like emacs supports the other direction, treating the diff as
> a patch file which can be applied to the original to get the
> current version.

Yes, most of `diff-mode` features currently available are designed to
let you change the diff before you do something with it (such as split
a hunk so as to apply/unapply only one part).
That's somewhat related to the above VSCode feature but it's indeed not
the same.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editing a VC diff to modify the current version
  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
  3 siblings, 0 replies; 5+ messages in thread
From: emacsq via Users list for the GNU Emacs text editor @ 2022-02-24  4:19 UTC (permalink / raw)
  To: emacsq via Users list for the GNU Emacs text editor

> When I modify a file under VC then I always make a diff before checkin to see everything is right. Sometimes the changes have a typo or a simple modification occurs to me which could be done right in the diff. 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.

Also, you can stage/unstage or revert selected ranges in the diff which is also handy:

https://user-images.githubusercontent.com/4114656/50283979-79913e00-044f-11e9-910f-c8b878148132.png

I'm not sure if a range here is equivalent to a diff hunk or you can stage/revert parts of a hunk which could also be useful.

I know I can split a hunk in emacs diff mode, and it also occured to me if emacs could support reverting some lines, or even just a region within lines, without having to split the hunk first manually .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editing a VC diff to modify the current version
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Prabath Liyanage @ 2022-02-24  4:29 UTC (permalink / raw)
  To: emacsq, emacsq via Users list for the GNU Emacs text editor

emacsq via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> When I tried vscode I found an interesting feature:
>
> When I modify a file under VC then I always make a diff before checkin to see everything is right. Sometimes the changes have a typo or a simple modification occurs to me which could be done right in the diff. 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.
>
> Emacs' manual mentions this about editing diffs:
>
> You can edit a Diff mode buffer like any other buffer. (If it is read-only, you need to make it writable first; see[Misc Buffer](https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-Buffer.html).) Whenever you edit a hunk, Diff mode attempts to automatically correct the line numbers in the hunk headers, to ensure that the patch remains correct, and could still be applied bypatch. To disable automatic line number correction, change the variablediff-update-on-the-flytonil.
>
> So it seems like emacs supports the other direction, treating the diff as a patch file which can be applied to the original to get the current version.
>
> These days comparing the current file to the last version under VC seems more usual, people more often make diffs before commit to see if their current changes are right, than doing it to make sure the patch file they create is correct.
>
> Can emacs support the workflow described above? That is applying edits in the diff buffer automatically to the file on disk. If not then it could be a useful improvement.

Maybe I am off the mark here, does vc-ediff/vc-diff or magit-ediff
(assuming you're using git) meet your requirements?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: editing a VC diff to modify the current version
  2022-02-24  2:22 editing a VC diff to modify the current version emacsq via Users list for the GNU Emacs text editor
                   ` (2 preceding siblings ...)
  2022-02-24  4:29 ` Prabath Liyanage
@ 2022-02-25 16:19 ` emacsq
  3 siblings, 0 replies; 5+ messages in thread
From: emacsq @ 2022-02-25 16:19 UTC (permalink / raw)
  To: emacsq via Users list for the GNU Emacs text editor

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





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-25 16:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).