Subject: bug#65380: [PATCH] Add command to copy contents in a diff-mode buffer

From: Eli Zaretskii <[email-masked]>
Date: Sun, 18 Aug 2024 18:43:36 +0300

> From: Philip Kaludercic <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Sun, 18 Aug 2024 15:29:25 +0000
> 
> > +          ;; copy the text between hunks
> > +          (let (start)
> > +            (save-window-excursion
> > +              (save-excursion
> > +                (forward-line -1)
> > +                (diff-goto-source)
> > +                (forward-line +1)
> > +                (setq start (point))))
> 
> One issue I still have here is that the `forwarad-line' might scroll the
> window, which `save-window-excursion' doesn't restore.

I don't understand what you are saying here.  As long as a Lisp
program runs and doesn't force redisplay (via sit-for or explicit
calls to 'redisplay' or somesuch), forwarad-line cannot cause any
scroll of the window, because what scrolls the window is redisplay
when it kicks in and finds that point is outside of the window.  So if
the above code takes care to restore point before it finishes, the
window won't scroll.  Or what am I missing?

> To fix this I have written a general macro for subr.el to restore
> the scroll position:

Let's first make sure we understand what happens here before we add
such a macro.  (It also has some conceptual problems of its own, but
let's defer that until we actually sure it is needed.)