Subject: Proposed patch for doc of posn-window and code of posn-set-point to handle frame arguments

From: Robert Weiner <[email-masked]>
Date: Wed, 27 Sep 2017 12:01:50 -0400

The doc for posn-window is incomplete.  posn-set-point does not handle drag
events whose end point argument is a frame, rather than a window.
This patch fixes both of these.  Read the code of posn-set-point to ensure
the logic is right in terms of using frame-selected-window.

This diff is against subr.el in Emacs 25.3 but I see none of this has yet
changed in Emacs 26 either, so it is still applicable.

*** subr.el.gz 2017-09-27 11:50:06.000000000 -0400
--- subr-new.el.gz 2017-09-27 11:50:06.000000000 -0400
***************
*** 1090,1096 ****
  The following accessor functions are used to access the elements
  of the position:

! `posn-window': The window the event is in.
  `posn-area': A symbol identifying the area the event occurred in,
  or nil if the event occurred in the text area.
  `posn-point': The buffer position of the event.
--- 1090,1096 ----
  The following accessor functions are used to access the elements
  of the position:

! `posn-window': The window or frame of the event end.
  `posn-area': A symbol identifying the area the event occurred in,
  or nil if the event occurred in the text area.
  `posn-point': The buffer position of the event.
***************
*** 1141,1148 ****

  (defsubst posn-window (position)
    "Return the window in POSITION.
! POSITION should be a list of the form returned by the `event-start'
! and `event-end' functions."
    (nth 0 position))

  (defsubst posn-area (position)
--- 1141,1149 ----

  (defsubst posn-window (position)
    "Return the window in POSITION.
! If POSITION is outside the frame where the event was initiated, return
! that frame instead.  POSITION should be a list of the form returned by
! the `event-start' and `event-end' functions."
    (nth 0 position))

  (defsubst posn-area (position)
***************
*** 1169,1177 ****
  (defun posn-set-point (position)
    "Move point to POSITION.
  Select the corresponding window as well."
!   (if (not (windowp (posn-window position)))
!       (error "Position not in text area of window"))
!   (select-window (posn-window position))
    (if (numberp (posn-point position))
        (goto-char (posn-point position))))

--- 1170,1182 ----
  (defun posn-set-point (position)
    "Move point to POSITION.
  Select the corresponding window as well."
!   (if (framep (posn-window position))
!       (progn (if (not (windowp (frame-selected-window (posn-window
position))))
! (error "Position not in text area of window"))
!      (select-window (frame-selected-window (posn-window position))))
!     (if (not (windowp (posn-window position)))
! (error "Position not in text area of window"))
!     (select-window (posn-window position)))
    (if (numberp (posn-point position))
        (goto-char (posn-point position))))