Subject: bug#33871: 27.0.50; Revert Dired window saved in window configuration

From: martin rudalics <[email-masked]>
Date: Mon, 19 Feb 2024 10:42:46 +0100

> Ok, let's add the WINDOW argument.  This means that most hooks
 > will need to call 'with-selected-window' explicitly.  But maybe
 > there will be hooks that don't need to select a window.

(setq-default window-set-context-function
               (lambda (w)
		(let ((point (window-point w)))
		  (with-current-buffer (window-buffer w)
                     `((front-context-string
                        . ,(buffer-substring-no-properties
                            point (min (+ point 16) (point-max))))
                       (rear-context-string
                        . ,(buffer-substring-no-properties
                            point (max (- point 16) (point-min)))))))))

should suffice to make 'buffer-substring-no-properties' work.  Note that
if you select the window beforehand, 'selected-window' will not return a
meaningful value in the body of the function called.  This is a problem
of many "hooks" like 'mode-line-format' or 'window-configuration-hook'.
The comfort you get comes at the price of a lack of generality.

martin