Subject: bug#24804: closed (Re: bug#24804: 25.1; posn-at-point erroneously signals an error)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 29 Oct 2016 22:04:02 +0000

Your bug report

#24804: 25.1; posn-at-point erroneously signals an error

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
24804: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=24804
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#24804: 25.1; posn-at-point erroneously signals an error
From: Eli Zaretskii <[email-masked]>
To: Andreas Politz <[email-masked]>
Cc: [email-masked]
Date: Sun, 30 Oct 2016 01:03:17 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Andreas Politz <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 29 Oct 2016 22:33:00 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > Done.  Let me know if something else should be done before closing
> > this bug.
> 
> Nothing.  I'm not clear about the general semantics of this function,
> but we don't need to discuss this right now.

OK, I'm therefore closing the bug (and the two merged with it).
People who think there are still leftovers are welcome to reopen with
details.

As for your questions about the semantics, I suggest to start a
discussion on emacs-devel.

Thanks.

Subject: 25.1; posn-at-point erroneously signals an error
From: Andreas Politz <[email-masked]>
To: [email-masked]
Date: Wed, 26 Oct 2016 21:43:27 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

The documentation of the function posn-at-point states

"Return nil if position is not visible in window.",

but it may also signal an error in this case.  This happens, if
Fpos_visible_in_window_p returns a list of (X Y RTOP RBOT ROWH VPOS)
and at least Y is negative (which indicates, that pos is not visible
IIUC).  The error is then signaled by Fposn_at_x_y, which only accpets
non-negative numbers (neglecting the exceptional case of -1 for X).

I think this function should include a similar test for y, as is already
in place for x, returning nil if it is negative (see below).

diff --git a/src/keyboard.c b/src/keyboard.c
index bb411e7..215fcb9 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -10791,9 +10791,10 @@ The `posn-' functions access elements of such lists.  */)
       Lisp_Object x = XCAR (tem);
       Lisp_Object y = XCAR (XCDR (tem));
 
-      /* Point invisible due to hscrolling?  X can be -1 when a
-	 newline in a R2L line overflows into the left fringe.  */
-      if (XINT (x) < -1)
+      /* Point invisible due to hscrolling or vscrolling?  X can be -1
+	 when a newline in a R2L line overflows into the left
+	 fringe.  */
+      if (XINT (x) < -1 || XINT (y) < 0)
 	return Qnil;
       tem = Fposn_at_x_y (x, y, window, Qnil);
     }

--

Reproducing this state may be a little bit tricky, anyway evaluate the
following lines, starting with `emacs -Q'.

(defvar img "foo.png");; The image should be taller then the window
                      ;; it's displayed in.
(setq debug-on-error t)
(find-file img)
(redisplay t)         ;; If in batch mode.
(image-scroll-up 999)
;; The image should be scrolled to the bottom now, while point equals 1.
(posn-at-point (point-max) (selected-window))

--

Note, that this bug may make switching buffers difficult in certain
situations, as was reported here:
https://github.com/politza/pdf-tools/issues/200

-ap