GNU bug report logs - #8627
24.0.50: cursor property behaves irregularly in before-strings

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Alp Aker <aker@HIDDEN>; dated Fri, 6 May 2011 00:02:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 8627 <at> debbugs.gnu.org:


Received: (at 8627) by debbugs.gnu.org; 29 May 2011 20:55:05 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun May 29 16:55:05 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QQn0q-0002Ua-Qa
	for submit <at> debbugs.gnu.org; Sun, 29 May 2011 16:55:05 -0400
Received: from mtaout22.012.net.il ([80.179.55.172])
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <eliz@HIDDEN>) id 1QQn0o-0002U5-F8
	for 8627 <at> debbugs.gnu.org; Sun, 29 May 2011 16:55:03 -0400
Received: from conversion-daemon.a-mtaout22.012.net.il by
	a-mtaout22.012.net.il (HyperSendmail v2007.08) id
	<0LLZ001005VQYP00@HIDDEN> for
	8627 <at> debbugs.gnu.org; Sun, 29 May 2011 23:54:39 +0300 (IDT)
Received: from HOME-C4E4A596F7 ([77.126.255.155]) by a-mtaout22.012.net.il
	(HyperSendmail v2007.08) with ESMTPA id
	<0LLZ00NDR63233R0@HIDDEN>;
	Sun, 29 May 2011 23:54:39 +0300 (IDT)
Date: Sun, 29 May 2011 23:54:45 +0300
From: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#8627: 24.0.50: cursor property behaves irregularly
	in	before-strings
In-reply-to: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
X-012-Sender: halo1@HIDDEN
To: Alp Aker <aker@HIDDEN>
Message-id: <8362otgrca.fsf@HIDDEN>
References: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
X-Spam-Score: -2.1 (--)
X-Debbugs-Envelope-To: 8627
Cc: 8627 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
Reply-To: Eli Zaretskii <eliz@HIDDEN>
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -2.1 (--)

> Date: Thu, 05 May 2011 20:01:00 -0400 (EDT)
> From: Alp Aker <aker@HIDDEN>
> 
> However, when used with overlay before-strings (or after-strings), the 
> cursor property appears to behave in ways that aren't consonant with the 
> docs and that don't follow a consistent pattern.

I took a quick look at this bug.  I must say I wish this feature were
never introduced into Emacs: it is hackyish, its implementation is
kludgey, and supporting it in the bidirectional display engine will be
a PITA.  It also makes no sense at all in some use cases.  E.g., if
you put a `cursor' property with an integer value of 1 on either a
before-string or an after-string, the cursor will never be positioned
on the character at point, although it is clearly visible.  And if the
value is greater than 1, the cursor will appear to be "stuck" for that
many C-f keypresses.  I'm sure some users will think it's a bug.

Anyway, I will eventually fix the code to do what it did in Emacs 23,
with one exception:

> (3) But if the before-string contains a newline, the cursor property 
> appears to be ignored regardless of location and regardless of whether the 
> value of the cursor property is numeric or merely non-nil.  With the 
> overlay still in the middle of the line:
> 
>    (setq str3 (concat str1 "\nWWW")
>          str4 (concat str2 "\nWWW"))
>    (overlay-put olay 'before-string str3)
>    (goto-char (overlay-start olay))
>    (overlay-put olay 'before-string str4)
>    (goto-char (overlay-start olay))
> 
> the cursor appears after the before string, for both types of property 
> value.

This cannot possibly work, not without rewriting the Emacs display
engine in ways I don't intend to.  Quite simply, you cannot put the
`cursor' property on a newline that belongs to a string, because a
newline, obviously, doesn't have a graphic representation (a glyph) on
the screen, it just causes Emacs to continue drawing on the next
screen line.

The function that decides where to position the cursor scans the
glyphs on the line that contains point, looking for a glyph that came
from some string position that has a non-nil `cursor' property.  If it
finds such a glyph, it then does what you expect.  But it will never
find a glyph that corresponds to a newline, and so the `cursor'
property on a newline that comes from a before- or after-string will
never be noticed.  It is effectively lost in the data structure
(called a `glyph matrix') which Emacs uses to draw and redraw the
screen.

In fact, with a newline from a string, Emacs doesn't even consider the
screen line where you wanted it to put the cursor be a candidate for
drawing the cursor, because the newline moves the buffer position
"covered" by the overlay to the next screen line.

I will eventually update the documentation with this caveat.

It's too bad that this is exactly the feature that you needed, but you
will have to rethink how to get the same effect.  I suggest putting
the overlay on some different character in the string, and giving the
`cursor' property a value > 1, maybe that will do what you want
(although I admit that I don't quite understand your exact situation).

> In any case, it would appear that either the treatment of before-strings 
> and after-strings should be changed so that the cursor property works with 
> them as it does with strings that come from display properties

That's not possible, because there's a fundamental difference between
the `display' properties whose values are strings and before- and
after-string properties: the former are _replacing_ properties,
i.e. these strings are displayed _instead_ of the buffer text covered
by the property/overlay.  By contrast, before- and after-strings do
not replace the text that is covered by the overlay.  The code that
treats these two use cases is thus different in pretty much
fundamental ways.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.

Message received at 8627 <at> debbugs.gnu.org:


Received: (at 8627) by debbugs.gnu.org; 7 May 2011 07:26:40 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 07 03:26:40 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QIbuO-0003c3-61
	for submit <at> debbugs.gnu.org; Sat, 07 May 2011 03:26:40 -0400
Received: from mtaout23.012.net.il ([80.179.55.175])
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <eliz@HIDDEN>) id 1QIbuL-0003bn-KH
	for 8627 <at> debbugs.gnu.org; Sat, 07 May 2011 03:26:34 -0400
Received: from conversion-daemon.a-mtaout23.012.net.il by
	a-mtaout23.012.net.il (HyperSendmail v2007.08) id
	<0LKT00H00DQ4HB00@HIDDEN> for
	8627 <at> debbugs.gnu.org; Sat, 07 May 2011 10:26:26 +0300 (IDT)
Received: from HOME-C4E4A596F7 ([84.228.234.175]) by a-mtaout23.012.net.il
	(HyperSendmail v2007.08) with ESMTPA id
	<0LKT00HLUE01FH50@HIDDEN>;
	Sat, 07 May 2011 10:26:26 +0300 (IDT)
Date: Sat, 07 May 2011 10:26:28 +0300
From: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#8627: 24.0.50: cursor property behaves irregularly in
	before-strings
In-reply-to: <Pine.GSO.4.63.1105061714480.3338@HIDDEN>
X-012-Sender: halo1@HIDDEN
To: Alp Aker <aker@HIDDEN>
Message-id: <83d3jvkm3f.fsf@HIDDEN>
References: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
	<831v0cm6pl.fsf@HIDDEN> <jwvd3jw2b0v.fsf-monnier+emacs@HIDDEN>
	<Pine.GSO.4.63.1105061714480.3338@HIDDEN>
X-Spam-Score: -1.8 (-)
X-Debbugs-Envelope-To: 8627
Cc: 8627 <at> debbugs.gnu.org, monnier@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
Reply-To: Eli Zaretskii <eliz@HIDDEN>
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -1.8 (-)

> Date: Fri, 06 May 2011 17:17:16 -0400 (EDT)
> From: Alp Aker <aker@HIDDEN>
> Cc: Eli Zaretskii <eliz@HIDDEN>, 8627 <at> debbugs.gnu.org
> 
> Does that qualify as a use case?

Yes, of course.

Thanks for the other info.  I will take a look.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.

Message received at 8627 <at> debbugs.gnu.org:


Received: (at 8627) by debbugs.gnu.org; 6 May 2011 21:17:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 06 17:17:26 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QISOr-0006IF-NZ
	for submit <at> debbugs.gnu.org; Fri, 06 May 2011 17:17:25 -0400
Received: from exprod7og115.obsmtp.com ([64.18.2.217])
	by debbugs.gnu.org with smtp (Exim 4.69)
	(envelope-from <aker@HIDDEN>) id 1QISOp-0006I2-Io
	for 8627 <at> debbugs.gnu.org; Fri, 06 May 2011 17:17:24 -0400
Received: from mb2i1.ns.pitt.edu ([136.142.11.153]) by
	exprod7ob115.postini.com ([64.18.6.12]) with SMTP
	ID DSNKTcRlXQAxlcxpZ3Z7JwFrRoh0VxE6Mo8X@HIDDEN;
	Fri, 06 May 2011 14:17:23 PDT
Received: from unixs1.cis.pitt.edu ([136.142.4.246])
	by pitt.edu (PMDF V6.3-x11 #31505)
	with ESMTP id <0LKS00LC8LSSNE@HIDDEN> for
	8627 <at> debbugs.gnu.org; Fri, 06 May 2011 17:17:16 -0400 (EDT)
Date: Fri, 06 May 2011 17:17:16 -0400 (EDT)
From: Alp Aker <aker@HIDDEN>
Subject: Re: bug#8627: 24.0.50: cursor property behaves irregularly in
	before-strings
In-reply-to: <jwvd3jw2b0v.fsf-monnier+emacs@HIDDEN>
X-X-Sender: aker@HIDDEN
To: Stefan Monnier <monnier@HIDDEN>
Message-id: <Pine.GSO.4.63.1105061714480.3338@HIDDEN>
MIME-version: 1.0
Content-type: TEXT/PLAIN; format=flowed; charset=US-ASCII
References: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
	<831v0cm6pl.fsf@HIDDEN> <jwvd3jw2b0v.fsf-monnier+emacs@HIDDEN>
X-Spam-Score: -6.6 (------)
X-Debbugs-Envelope-To: 8627
Cc: 8627 <at> debbugs.gnu.org, Eli Zaretskii <eliz@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -6.6 (------)

>> But if the before-string contains a newline, the cursor property
>> appears to be ignored.
>
> I will take a look at fixing this, but can you show a real-life use
> case where this is needed?

I ran into the need while working on this package:

   emacswiki.org/emacs/FillColumnIndicator

It shades the area past the fill column by putting overlays on newlines 
(if you look at the screenshot it'll be obvious how it works).  In a few 
edge cases it would be useful to be able to display a newline that's not 
part of the buffer content.  For example, if the last line of the buffer 
doesn't end in a newline, then no fill-column shading appears on that line 
(since there's no newline to propertize).  I'd like to put an overlay at 
point-max with an after-string containing a propertized newline character, 
so that the fill-column shading can appear on the last line of the buffer. 
But I can't do so, because the newline in the after-string causes any 
cursor property in it to be ignored, and so cursor motion at the end of 
the buffer becomes deranged.  (Display strings won't do here, because I 
don't want to replace the display of any characters in the buffer.)

Does that qualify as a use case?

I might as well also mention, at least for the record, another (minor) 
issue with cursor properties in before-strings that I came across:  If the 
position with the cursor property is out of sight because of horizontal 
scrolling, then the property is ignored, even when auto-hscroll-mode is 
enabled.  Perhaps it would make more sense to respect the cursor property 
when auto-hscroll-mode is non-nil, and adjust hscrolling to bring the 
requested cursor position into view?

Here's a test case:

(progn
   (setq auto-hscroll-mode t)
   ;; A line of text, moving to the end of which will trigger hscrolling.
   (insert (make-string (+ hscroll-margin (window-width) 5) ?X))
   (setq m (point-marker))
   (insert "\n\n")
   (setq o (make-overlay (1- (point)) (point)))
   ;; Request that cursor be at bol, but make the before-string long
   ;; enough that if the cursor property is ignored we won't return from
   ;; hscrolling.
   (overlay-put o
                'before-string
                (concat
                 (propertize " " 'cursor 1)
                 (make-string (window-width) 32)))
   (goto-char m)
   (redisplay)
   (forward-line 1))

After evaluation the cursor will be at the end of the before-string, 
rather than at the requested position.  (This happens with 22 and 23 as 
well.)









Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.

Message received at 8627 <at> debbugs.gnu.org:


Received: (at 8627) by debbugs.gnu.org; 6 May 2011 13:53:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 06 09:53:43 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QILTR-00049A-Al
	for submit <at> debbugs.gnu.org; Fri, 06 May 2011 09:53:43 -0400
Received: from fencepost.gnu.org ([140.186.70.10])
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <monnier@HIDDEN>) id 1QILTQ-00048y-1A
	for 8627 <at> debbugs.gnu.org; Fri, 06 May 2011 09:53:40 -0400
Received: from 121-249-126-200.fibertel.com.ar ([200.126.249.121]:41001
	helo=ceviche.home)
	by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
	(Exim 4.71) (envelope-from <monnier@HIDDEN>)
	id 1QILTJ-0006ty-7y; Fri, 06 May 2011 09:53:33 -0400
Received: by ceviche.home (Postfix, from userid 20848)
	id 9A66F66168; Fri,  6 May 2011 10:53:30 -0300 (ART)
From: Stefan Monnier <monnier@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#8627: 24.0.50: cursor property behaves irregularly
	in	before-strings
Message-ID: <jwvd3jw2b0v.fsf-monnier+emacs@HIDDEN>
References: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
	<831v0cm6pl.fsf@HIDDEN>
Date: Fri, 06 May 2011 10:53:30 -0300
In-Reply-To: <831v0cm6pl.fsf@HIDDEN> (Eli Zaretskii's message of "Fri, 06 May
	2011 14:03:34 +0300")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -6.0 (------)
X-Debbugs-Envelope-To: 8627
Cc: 8627 <at> debbugs.gnu.org, Alp Aker <aker@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -6.0 (------)

> Note that, crucially, the before-string and after-string properties
> are not described in this section.  They are described elsewhere,
> where the `cursor' property is not mentioned.  So I wonder if the
> `cursor' property was really supposed to work with before-strings and
> after-strings...

The only use of `cursor' of which I remember is in minibuffer-message,
on an after-string.  It's used when we display " [Sole completion]" and
such messages.
So, yes, it's supposed to work on before/after-strings ;-)


        Stefan




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.

Message received at 8627 <at> debbugs.gnu.org:


Received: (at 8627) by debbugs.gnu.org; 6 May 2011 11:03:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri May 06 07:03:43 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QIIow-0007ye-Nb
	for submit <at> debbugs.gnu.org; Fri, 06 May 2011 07:03:42 -0400
Received: from mtaout22.012.net.il ([80.179.55.172])
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <eliz@HIDDEN>) id 1QIIou-0007yR-AT
	for 8627 <at> debbugs.gnu.org; Fri, 06 May 2011 07:03:41 -0400
Received: from conversion-daemon.a-mtaout22.012.net.il by
	a-mtaout22.012.net.il (HyperSendmail v2007.08) id
	<0LKR00L00T7VYM00@HIDDEN> for
	8627 <at> debbugs.gnu.org; Fri, 06 May 2011 14:03:34 +0300 (IDT)
Received: from HOME-C4E4A596F7 ([84.228.234.175]) by a-mtaout22.012.net.il
	(HyperSendmail v2007.08) with ESMTPA id
	<0LKR00JV0TDWT5N0@HIDDEN>;
	Fri, 06 May 2011 14:03:34 +0300 (IDT)
Date: Fri, 06 May 2011 14:03:34 +0300
From: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#8627: 24.0.50: cursor property behaves irregularly
	in	before-strings
In-reply-to: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
X-012-Sender: halo1@HIDDEN
To: Alp Aker <aker@HIDDEN>
Message-id: <831v0cm6pl.fsf@HIDDEN>
References: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
X-Spam-Score: -2.1 (--)
X-Debbugs-Envelope-To: 8627
Cc: 8627 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
Reply-To: Eli Zaretskii <eliz@HIDDEN>
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -2.1 (--)

> Date: Thu, 05 May 2011 20:01:00 -0400 (EDT)
> From: Alp Aker <aker@HIDDEN>
> 
> The documentation for the cursor property (info node "(elisp) Special 
> Properties") states that:
> 
> "Normally, the cursor is displayed at the end of any overlay and text 
> property strings present at the current buffer position.  You can place 
> the cursor on any desired character of these strings by giving that 
> character a non-`nil' `cursor' text property."
> 
> And then follows the description of using integer values for the cursor 
> property to make it applicable to a range of buffer positions other than 
> the range between the overlay's start and end.

Note that, crucially, the before-string and after-string properties
are not described in this section.  They are described elsewhere,
where the `cursor' property is not mentioned.  So I wonder if the
`cursor' property was really supposed to work with before-strings and
after-strings...

> However, when used with overlay before-strings (or after-strings), the 
> cursor property appears to behave in ways that aren't consonant with the 
> docs and that don't follow a consistent pattern.

It looks like it was never supported consistently, ever since the
`cursor' property was introduced (in Emacs 22.1).

> (1) Insert some boilerplate text to interact with.
> 
>    (save-excursion
>      (goto-char (point-min))
>      (insert "Lorem ipsum dolor sit amet.\n"))
> 
> Make an overlay and give it a before-string with a non-nil cursor property 
> on one character:
> 
>    (setq olay (make-overlay 5 6)
>          str1 (concat "XX"
>                       (propertize "Y" 'cursor t)
>                       "ZZ"))
>    (overlay-put olay 'before-string str1)
> 
> If one now does:
> 
>    (goto-char (overlay-start olay))
> 
> the cursor property is ignored; the cursor appears after the 
> before-string.

This works as expected in Emacs 23, so it must be some problem with
the bidi-aware redisplay in Emacs 24.  I will take a look when I have
time; thanks for a clear test case.

> (3) But if the before-string contains a newline, the cursor property 
> appears to be ignored regardless of location and regardless of whether the 
> value of the cursor property is numeric or merely non-nil.

This never worked, I tested it in Emacs 22.1, and it behaves like this
as well.

I will take a look at fixing this, bat can you show a real-life use
case where this is needed?

> I started to read through xdisp.c to make some sense of this, but I'm too 
> new to Emacs's internals to be able to follow much of the display routine. 
> I did observe, though, that cursor_row_p only checks display properties, 
> and doesn't appear to check before-strings and after-strings.

It may come as a surprise, but the implementation of display
properties is very different from that of before-string and
after-string properties.  It's a small wonder they don't behave
similarly.

> In any case, it would appear that either the treatment of before-strings 
> and after-strings should be changed so that the cursor property works with 
> them as it does with strings that come from display properties, or the 
> documentation should be amended to make clear that that it can't be 
> expected to do so.  (In the latter case, it would still seem desirable 
> that cursor properties in before- and after-strings behave systematically, 
> which isn't currently the case.)

It sounds like it works in most use cases, so fixing the
implementation is probably a better alternative.




Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 6 May 2011 00:01:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 05 20:01:17 2011
Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1QI8Ts-0001CQ-SQ
	for submit <at> debbugs.gnu.org; Thu, 05 May 2011 20:01:17 -0400
Received: from eggs.gnu.org ([140.186.70.92])
	by debbugs.gnu.org with esmtp (Exim 4.69)
	(envelope-from <aker@HIDDEN>) id 1QI8Tr-0001CB-8N
	for submit <at> debbugs.gnu.org; Thu, 05 May 2011 20:01:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <aker@HIDDEN>) id 1QI8Tl-0000OD-Co
	for submit <at> debbugs.gnu.org; Thu, 05 May 2011 20:01:10 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED
	autolearn=unavailable version=3.3.1
Received: from lists.gnu.org ([140.186.70.17]:38497)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <aker@HIDDEN>) id 1QI8Tl-0000O9-BC
	for submit <at> debbugs.gnu.org; Thu, 05 May 2011 20:01:09 -0400
Received: from eggs.gnu.org ([140.186.70.92]:49726)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <aker@HIDDEN>) id 1QI8Tk-0005OQ-AV
	for bug-gnu-emacs@HIDDEN; Thu, 05 May 2011 20:01:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <aker@HIDDEN>) id 1QI8Tj-0000Nw-6P
	for bug-gnu-emacs@HIDDEN; Thu, 05 May 2011 20:01:08 -0400
Received: from exprod7og109.obsmtp.com ([64.18.2.171]:32997)
	by eggs.gnu.org with smtp (Exim 4.71) (envelope-from <aker@HIDDEN>)
	id 1QI8Ti-0000Np-Ts
	for bug-gnu-emacs@HIDDEN; Thu, 05 May 2011 20:01:07 -0400
Received: from mb1i1.ns.pitt.edu ([136.142.11.152]) by
	exprod7ob109.postini.com ([64.18.6.12]) with SMTP
	ID DSNKTcM6PxCjivk6wDsYcRSTf25FQqD0fjFX@HIDDEN;
	Thu, 05 May 2011 17:01:06 PDT
Received: from unixs1.cis.pitt.edu ([136.142.4.246])
	by pitt.edu (PMDF V6.3-x11 #31505)
	with ESMTP id <0LKQ00K49YPRJE@HIDDEN> for
	bug-gnu-emacs@HIDDEN; Thu, 05 May 2011 20:01:03 -0400 (EDT)
Date: Thu, 05 May 2011 20:01:00 -0400 (EDT)
From: Alp Aker <aker@HIDDEN>
Subject: 24.0.50: cursor property behaves irregularly in before-strings
X-X-Sender: aker@HIDDEN
To: bug-gnu-emacs@HIDDEN
Message-id: <Pine.GSO.4.63.1105051941210.27255@HIDDEN>
MIME-version: 1.0
Content-type: TEXT/PLAIN; format=flowed; charset=US-ASCII
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older,
	4)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3)
X-Received-From: 140.186.70.17
X-Spam-Score: -6.6 (------)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/pipermail/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -6.6 (------)

The documentation for the cursor property (info node "(elisp) Special 
Properties") states that:

"Normally, the cursor is displayed at the end of any overlay and text 
property strings present at the current buffer position.  You can place 
the cursor on any desired character of these strings by giving that 
character a non-`nil' `cursor' text property."

And then follows the description of using integer values for the cursor 
property to make it applicable to a range of buffer positions other than 
the range between the overlay's start and end.

However, when used with overlay before-strings (or after-strings), the 
cursor property appears to behave in ways that aren't consonant with the 
docs and that don't follow a consistent pattern.

Here's a recipe for producing the variety of observed behaviors.  (I use 
before-strings, but using after-strings gives similar results.)

(1) Insert some boilerplate text to interact with.

   (save-excursion
     (goto-char (point-min))
     (insert "Lorem ipsum dolor sit amet.\n"))

Make an overlay and give it a before-string with a non-nil cursor property 
on one character:

   (setq olay (make-overlay 5 6)
         str1 (concat "XX"
                      (propertize "Y" 'cursor t)
                      "ZZ"))
   (overlay-put olay 'before-string str1)

If one now does:

   (goto-char (overlay-start olay))

the cursor property is ignored; the cursor appears after the 
before-string.  However, if the before-string appears before a newline, 
the cursor property is respected:

   (save-excursion
     (goto-char (point-min))
     (search-forward "\n")
     (move-overlay olay (1- (point)) (point)))
   (goto-char (overlay-start olay))

The cursor now appears at the propertized character in the before-string.

(2)  Now give the overlay a before-string one of whose characters has a 
numeric cursor property:

   (setq str2 (concat "XX"
                      (propertize "Y" 'cursor 1)
                      "ZZ"))
   (overlay-put olay 'before-string str2)

In this case, the property is respected regardless of location.  With the 
overlay still at the newline:

   (goto-char (overlay-start olay))

and in the middle of a row:

   (move-overlay olay 5 6)
   (goto-char (overlay-start olay))

the cursor appears at the propertized character in the before-string.

(3) But if the before-string contains a newline, the cursor property 
appears to be ignored regardless of location and regardless of whether the 
value of the cursor property is numeric or merely non-nil.  With the 
overlay still in the middle of the line:

   (setq str3 (concat str1 "\nWWW")
         str4 (concat str2 "\nWWW"))
   (overlay-put olay 'before-string str3)
   (goto-char (overlay-start olay))
   (overlay-put olay 'before-string str4)
   (goto-char (overlay-start olay))

the cursor appears after the before string, for both types of property 
value.  Now moving the overlay back to the newline:

   (save-excursion
     (goto-char (point-min))
     (search-forward "\n")
     (move-overlay olay (1- (point)) (point)))
   (goto-char (overlay-start olay))
   (overlay-put olay 'before-string str3)
   (goto-char (overlay-start olay))

the cursor property is again ignored, in both cases.

I started to read through xdisp.c to make some sense of this, but I'm too 
new to Emacs's internals to be able to follow much of the display routine. 
I did observe, though, that cursor_row_p only checks display properties, 
and doesn't appear to check before-strings and after-strings.

In any case, it would appear that either the treatment of before-strings 
and after-strings should be changed so that the cursor property works with 
them as it does with strings that come from display properties, or the 
documentation should be amended to make clear that that it can't be 
expected to do so.  (In the latter case, it would still seem desirable 
that cursor properties in before- and after-strings behave systematically, 
which isn't currently the case.)







Acknowledgement sent to Alp Aker <aker@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs@HIDDEN:
bug#8627; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 31 Oct 2014 17:00:04 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.