Subject: Re: bug#21730: 25.0.50; Random errors in redisplay--pre-redisplay-functions

From: Eli Zaretskii <[email-masked]>
Date: Thu, 22 Oct 2015 17:40:19 +0300

> From: Michael Welsh Duggan <[email-masked]>
> Date: Thu, 22 Oct 2015 00:04:06 -0400
> 
> I don't have a recipe for this.  Every now again I get the following in
> my *Messages* buffer:
> 
>   redisplay--pre-redisplay-functions: (args-out-of-range 0)
> 
> I turned on debug-on-error, and got the following backtrace:
> 
>   Debugger entered--Lisp error: (args-out-of-range 0)
>     get-char-property(0 cursor-sensor-functions)
>     cursor-sensor--detect(#<window 224 on *Group*>)
>     run-hook-with-args(cursor-sensor--detect #<window 224 on *Group*>)
>     redisplay--pre-redisplay-functions(t)
>     apply(redisplay--pre-redisplay-functions t)
>     #[128 "\300\301\"\210\300\302\"\207" [apply 
> redisplay--pre-redisplay-functions ignore nil] 4 nil nil](t)
>     redisplay_internal\ \(C\ function\)()
> 
> This happens infrequently, about a couple of times a day.  I cannot make
> this happen on demand, but I can add debugging code if led in the
> correct direction.

Thanks for reporting this.  I'll try to help, although Stefan might
have better ideas.

>From the backtrace it is obvious that the immediate reason for the
problem is the call to 'get-char-property' with an invalid 1st argument
of zero (it's a buffer position, so should be at least 1).

Looking at 'cursor-sensor--detect', I see this:

  (defun cursor-sensor--detect (window)
    (unless cursor-sensor-inhibit
      (let* ((point (window-point window))
	     ;; It's often desirable to make the cursor-sensor-functions property
	     ;; non-sticky on both ends, but that means get-pos-property might
	     ;; never see it.
	     (new (or (get-char-property point 'cursor-sensor-functions)
		      (unless (bobp)
			(get-char-property (1- point) 'cursor-sensor-functions))))

So my guess is that the value of 'point' (the variable, not the
function) is 1, i.e. beginning of buffer, and subtracting 1 from it
produces that zero.  Then the second call to 'get-char-property' barfs
as expected.

The code tries to protect itself against such a calamity by calling
'bobp', but that function looks at the buffer's value of point, which
might be different from what 'window-point' returns.

So my advice would be to replace the call to 'bobp' with an explicit
test of the value of the local variable 'point', and see if that fixes
the problem.