unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Cursor positioning with `after-string' overlays
Date: Fri, 02 Apr 2010 14:17:31 -0400	[thread overview]
Message-ID: <jwvpr2hohlj.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83ljd6w9p1.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 02 Apr 2010 11:16:42 +0300")

>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> writes:

>> From: Stefan Monnier <monnier@iro.umontreal.ca>
>> Date: Thu, 01 Apr 2010 18:06:26 -0400
>> Cc: emacs-devel@gnu.org
>> 
>> > found.  IOW, exact match wins over all other considerations.  Since
>> > C-f from the second `o' moves point to buffer position to which `b'
>> > corresponds exactly, that is where the trunk version puts the cursor.
>> 
>> But depending on the insertion-type of the end marker of your overlay,
>> text inserted "at point" will be inserted (visually) between the o and
>> the - rather than between the - and the b, so while this choice would
>> sometimes be correct, it's sometimes incorrect.

> Sorry, I don't understand the specific situation.  In my example, when
> the cursor is on `b', insertion happens between `-' and `b', which is
> visually correct.  Can you modify my example to create the situation
> you are describing?  Then I could try to reason about it and perhaps
> modify the code if necessary.

Try:

    (let ((pos (goto-char (point-max))))
      (insert "foobar")
      (overlay-put
	(make-overlay (+ pos 2) (+ pos 3) nil nil t)
	'after-string (propertize "-" 'cursor t)))

(i.e. I added "nil nil t" to the call to make-overlay).

> In any case, do you really think that being unable to put the cursor
> on `b' (with the old code) is correct behavior?

No.  The old behavior had its share of problems as well.

>> That's why we have the `cursor' property (although admittedly, for
>> this particular use, the insertion-type of the marker should already
>> provide the needed info).
> What do you mean by ``the insertion-type of the marker''?

I hope the sample code above makes it more clear (I'm talking about the
marker-insertion-type of the underlying/implicit markers used as end
points of the overlay).  For text-properties it's called stickiness.

>> One use case is when you simply want to control where the cursor is
>> displayed on a piece of text that's not in the buffer (typically an
>> after-string).  In such a case, without any extra information, it would
>> not be incorrect to place the cursor before the after-string, or after
>> the after-string or anywhere in between.  So the `cursor' property
>> allows to specify the intended behavior (e.g. the after-string has the
>> form "()" and you want the cursor to appear in between the two parens).
> This may make sense when the string is displayed _instead_ of some
> portion of the buffer, or perhaps when we have a single buffer
> position that uses up several columns on display, like in Kim's
> example with a TAB in Cua Mode.

Exactly, yes.

> But if you type C-f, which moves point to the next buffer position,
> and the glyph produced from that buffer position is displayed on the
> screen, how can it be TRT not to place the cursor on that glyph?

See my sample code above again or think of the minibuffer messages
during completion: depending on the particular case, the intention of
the text inserted via an after-string may be to appear "before" or
"after" the cursor.

>> The other use case is when the cursor positioning code gets it wrong
>> because it works at too low a level (typically the after-string or
>> similar thingy is on an overlay with carefully chosen stickiness which
>> should make it clear whether the cursor should come before or after the
>> string, but the cursor positioning code only gets to see a "flattened"
>> representation of the text, so it can't know the stickiness property).
> I think this kind of problems should be fixed, not worked around with
> the `cursor' property.  The cursor-positioning code does not work only
> on glyphs, it does search the buffer for `display' properties and
> overlays, so whatever information is available in the buffer, the
> cursor-positioning code can get at it.

IIRC last time I looked at it, it would require a significant
restructuring to get the needed information.  I can't remember the
details, but I seem to remember that one of the problem is that at the
moment we handle the cursor position all we know is "we're displaying
string S", so we know the text displayed comes from a string rather than
from a buffer, but we don't know where that string comes from: we've
forgotten all about whether it's from a display property, or an overlay,
so we can't check the corresponding stickiness/insertion-type.


        Stefan




  reply	other threads:[~2010-04-02 18:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-01 13:15 Cursor positioning with `after-string' overlays Eli Zaretskii
2010-04-01 21:54 ` Kim F. Storm
2010-04-02  7:53   ` Eli Zaretskii
2010-04-02  8:54     ` Eli Zaretskii
2010-04-02 10:24       ` Kim F. Storm
2010-04-01 22:06 ` Stefan Monnier
2010-04-02  8:16   ` Eli Zaretskii
2010-04-02 18:17     ` Stefan Monnier [this message]
2010-04-02 18:38       ` Eli Zaretskii
2010-04-02 20:35         ` Stefan Monnier
2010-04-02 21:16           ` Eli Zaretskii
2010-04-03  1:21             ` Stefan Monnier
2010-04-03  7:26               ` Eli Zaretskii
2010-04-03  7:30               ` redisplay code is ugly (was: Cursor positioning with `after-string' overlays) Eli Zaretskii
2010-04-03 10:42               ` Cursor positioning with `after-string' overlays Eli Zaretskii
2010-04-03 10:28       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvpr2hohlj.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).