Subject: bug#17678: 24.4.50; Feature Request -- calculate new `window-start` & `window-end` before visual redisplay

From: Keith David Bershatsky <[email-masked]>
Date: Fri, 13 Jun 2014 13:21:02 -0700

Here is a first draft, which appears to correctly handle common movement through the buffer using `beginning-of-buffer`, `end-of-buffer`, and custom paragraph forward / backward function.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (defvar old-window-start nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'old-window-start)
    
    (defvar old-window-end nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'old-window-end)
    
    (defvar old-window-end-forced nil
    "This local variable is set within the `post-command-hook`; and,
    is also used by the `window-scroll-functions` hook.")
    (make-variable-buffer-local 'old-window-end-forced)
    
    (defun test-post-command-hook ()
      (when
          (and
            (not (minibufferp))
            (window-live-p (get-buffer-window (current-buffer))))
        (setq old-window-start (window-start))
        (setq old-window-end (window-end))
        (setq old-window-end-forced (window-end nil t))
        (when
            (and
              (not (< (point) old-window-start))
              (not (> (point) old-window-end))
              (not (> (point) old-window-end-forced)))
          (message (concat
            "P.C.H. -- `point`: %s | "
            "`old-window-start`: %s | "
            "`old-window-end`: %s | "
            "`old-window-end-forced`: %s")
              (point)
              old-window-start
              old-window-end
              old-window-end-forced))))
    
    (defun test-window-scroll-functions (win _start)
      "Good for things like: `beginning-of-buffer`; `end-of-buffer`; `yank`; etc"
      (when
          (and
            (not (minibufferp))
            (window-live-p (get-buffer-window (current-buffer))))
        (when
            (or
              (< (point) old-window-start)
              (> (point) old-window-end)
              (> (point) old-window-end-forced))
          (message (concat
            "W.S.F. -- `point`: %s | "
            "*new* window-start: %s | "
            "*new* window-end: %s")
              (point)
              _start
              (window-end win t)))))
    
    (define-minor-mode test-mode
    "A minor-mode for testing `window-start` and `window-end`."
      :init-value nil
      :lighter " 𝓣𝓔𝓢𝓣"
      :keymap nil
      :global nil
      (cond
        (test-mode
          (condition-case error
            (progn
              (setq scroll-conservatively 101)
              (setq scroll-margin 0)
              (add-hook 'post-command-hook 'test-post-command-hook nil t)
              (add-hook 'window-scroll-functions 'test-window-scroll-functions nil t)
              (message "Turned ON `test-mode`."))
            (error
             (test-mode 0)
             (signal (car error) (cdr error)))))
        ((not test-mode)
          (remove-hook 'post-command-hook 'test-post-command-hook t)
          (remove-hook 'window-scroll-functions 'test-window-scroll-functions t)
          (message "Turned OFF `test-mode`.") )))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;