Subject: bug#19012: 25.0.50; `help-window-select'

From: martin rudalics <[email-masked]>
Date: Sat, 15 Nov 2014 12:24:17 +0100

> 1. The `temp-buffer-*-hook's are not only about showing *Help*.
 >     That workaround thus affects more than it should.

`temp-buffer-window-setup-hook' is run with *Help* current.  So you
won't have any problems discriminating this special case.

 > 2. Users of `w32*' should not need to do that explicitly
 >     themselves.  Perhaps Emacs can do the equivalent, itself (but
 >     limited to *Help*, not affecting all temp buffer display).

I cannot possibly use a feature like `w32-grab-focus-on-raise' whose
semantics I neither understand nor can reenact in my environment in the
frame/window code of Emacs.

But we could change `help-window-setup' as follows:

(defun help-window-setup (window &optional value)
   "Set up help window WINDOW for `with-help-window'.
WINDOW is the window used for displaying the help buffer.
Return VALUE."
   (let* ((help-buffer (when (window-live-p window)
			(window-buffer window)))
	 (help-setup (when (window-live-p window)
		       (car (window-parameter window 'quit-restore)))))
     (when help-buffer
       ;; Handle `help-window-point-marker'.
       (when (eq (marker-buffer help-window-point-marker) help-buffer)
	(set-window-point window help-window-point-marker)
	;; Reset `help-window-point-marker'.
	(set-marker help-window-point-marker nil))

       (cond
        ((or (eq window (selected-window))
	    (and (or (eq help-window-select t)
		     (eq help-setup 'frame)
		     (and (eq help-window-select 'other)
			  (eq (window-frame window) (selected-frame))
			  (> (length (window-list nil 'no-mini)) 2)))
		 (select-window window)))
	(when help-window-select
	  (select-frame-set-input-focus (window-frame window)))
	;; The help window is or gets selected ...
	(help-window-display-message
	 (cond
	  ((eq help-setup 'window)
	   ;; ... and is new, ...
	   "Type \"q\" to delete help window")
	  ((eq help-setup 'frame)
	   "Type \"q\" to quit the help frame")
	  ((eq help-setup 'other)
	   ;; ... or displayed some other buffer before.
	   "Type \"q\" to restore previous buffer"))
	 window t))
        ((and (eq (window-frame window) (selected-frame))
	     (= (length (window-list nil 'no-mini)) 2))
	;; There are two windows on the help window's frame and the
	;; other one is the selected one.
	(help-window-display-message
	 (cond
	  ((eq help-setup 'window)
	   "Type \\[delete-other-windows] to delete the help window")
	  ((eq help-setup 'other)
	   "Type \"q\" in help window to restore its previous buffer"))
	 window 'other))
        (t
	;; The help window is not selected ...
	(help-window-display-message
	 (cond
	  ((eq help-setup 'window)
	   ;; ... and is new, ...
	   "Type \"q\" in help window to delete it")
	  ((eq help-setup 'other)
	   ;; ... or displayed some other buffer before.
	   "Type \"q\" in help window to restore previous buffer"))
	 window))))
     ;; Return VALUE.
     value))

martin