GNU bug report logs - #51095
28.0.50; Counter-intuitive `cursor-intangible-mode' behavior

Previous Next

Package: emacs;

Reported by: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>

Date: Fri, 8 Oct 2021 14:59:01 UTC

Severity: normal

Tags: moreinfo

Found in version 28.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51095 in the body.
You can then email your comments to 51095 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Fri, 08 Oct 2021 14:59:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Brahimi Saifullah <brahimi.saifullah <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 08 Oct 2021 14:59:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; Counter-intuitive `cursor-intangible-mode' behavior
Date: Fri, 08 Oct 2021 11:35:11 -0300
Let's start with the following example:
emacs -Q
M-: (insert "|" (propertize "xxxxx" 'cursor-intangible t) "|")
M-x cursor-intangible-mode

Result:
|xxxxx|
  ^^^^^ You can't move the cursor here

What I expected:
|xxxxx|
 ^^^^^ You can't move the cursor here

To clarify, although all the `X's are set to be intangible, you can still move
your cursor to the first one.  Furthermore, even though neither `|' has a text
property, you cannot move your cursor to the last one.

I tracked this behavior to the following function:
(from cursor-sensor.el, attached for convenience)

(defun cursor-sensor--intangible-p (pos)
  (let ((p (get-pos-property pos 'cursor-intangible)))
    (if p
        (let (a b)
          (if (and (setq a (get-char-property pos 'cursor-intangible))
                   (setq b (if (> pos (point-min))
                               (get-char-property (1- pos) 'cursor-intangible)))
                   (not (eq a b)))
              ;; If we're right between two different intangible thingies,
              ;; we can stop here.  This is not quite consistent with the
              ;; interpretation of "if it's sticky, then this boundary is
              ;; itself intangible", but it's convenient (and it better matches
              ;; the behavior of `intangible', making it easier to port code).
              nil p))
      p)))

This is the result of using `get-pos-property' instead of `get-char-property'.
If my understanding is correct, the difference in the former is its handling of
stickiness.  Thus I came up with the following:

(insert "|"
        (propertize
         (concat
          (propertize "x" 'front-sticky t)
          "xxx"
          (propertize "x" 'rear-nonsticky t))
         'cursor-intangible t)
        "|")

Basically, make the first character front-sticky, and the last character
rear-nonsticky.  Now it works as expected.

The question is: Is this behavior intuitive?
Is a Lisp program supposed to know that the portion of the text it has set to
be intangible is not actually accurate and must be manually adjusted?
To me it sounds not only unintuitive, but also like a bug.



In GNU Emacs 28.0.50 (build 1, x86_64-w64-mingw32)
 of 2021-09-21 built on COMPUTADOR
Repository revision: e4a9aa940beb032e97de6d4e4a23c2c9d94fdeb6
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.19041
System Description: Microsoft Windows 10 Enterprise (v10.0.2004.19041.1237)

Configured using:
 'configure --with-native-compilation --with-json --with-imagemagick
 --without-pop'

Configured features:
ACL DBUS GIF GMP GNUTLS HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBXML2
MODULES NATIVE_COMP NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS XPM ZLIB

Important settings:
  value of $LC_CTYPE: pt_BR.UTF-8
  value of $LANG: PTB
  locale-coding-system: cp1252

Major mode: Lisp Interaction

Minor modes in effect:
  cursor-intangible-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
cursor-sensor pp cl-extra seq byte-opt gv bytecomp byte-compile cconv
cl-print time-date subr-x thingatpt help-fns radix-tree help-mode
cl-loaddefs cl-lib iso-transl tooltip eldoc electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice
button loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads w32notify dbusbind w32 lcms2
multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 79446 8863)
 (symbols 48 7032 0)
 (strings 32 23818 1385)
 (string-bytes 1 730132)
 (vectors 16 14529)
 (vector-slots 8 305875 14414)
 (floats 8 30 40)
 (intervals 56 288 1)
 (buffers 992 13))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Sat, 09 Oct 2021 13:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 51095 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
Cc: 51095 <at> debbugs.gnu.org
Subject: Re: bug#51095: 28.0.50; Counter-intuitive `cursor-intangible-mode'
 behavior
Date: Sat, 09 Oct 2021 15:17:44 +0200
Brahimi Saifullah <brahimi.saifullah <at> gmail.com> writes:

> Let's start with the following example:
> emacs -Q
> M-: (insert "|" (propertize "xxxxx" 'cursor-intangible t) "|")
> M-x cursor-intangible-mode
>
> Result:
> |xxxxx|
>   ^^^^^ You can't move the cursor here
>
> What I expected:
> |xxxxx|
>  ^^^^^ You can't move the cursor here

I can reproduce the behaviour, but unless I misunderstand something,
this seems like it's working as designed.

The cursor is really "between" two characters conceptually -- this is
easier to understand if you use a "bar" cursor.  So if you put the point
here:

|xxxxx|
 ^

then it's before the first x and after the first |.  (You can confirm by
entering a character when it's at that point.)

The behaviour at the end is more puzzling, but as you've found out, it's
because the properties don't have rear-nonsticky, so you can't put point
right after the final x.

So I think everything here is working as designed.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 09 Oct 2021 13:19:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Sat, 09 Oct 2021 18:38:01 GMT) Full text and rfc822 format available.

Message #13 received at 51095 <at> debbugs.gnu.org (full text, mbox):

From: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
To: 51095 <at> debbugs.gnu.org
Subject: 28.0.50; Counter-intuitive `cursor-intangible-mode' behavior
Date: Sat, 09 Oct 2021 15:36:38 -0300
I see, thanks for the clarification.

What really had me confused was that, when your cursor is
in that position (the first X), `describe-char' claims:
>There are text properties here:
>  cursor-intangible    t

Perhaps the manual entry explaining this property should
clarify the nuances of the usual character after point v.
this concept of point being between the characters.

Still, I find this behavior odd from an usability standpoint.
I did some grep'ing in the core and ELPA packages to see how
often the workaround of front/rear-nonsticky is used.
From a glance I could only find a couple of packages explicitly
doing that, but then again you can count the amount of packages
extensively using `cursor-intangible' on the fingers of one hand.
All in all, not a very conclusive search besides confirming
the current behavior is indeed desirable in some situations.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Fri, 15 Oct 2021 22:57:01 GMT) Full text and rfc822 format available.

Message #16 received at 51095 <at> debbugs.gnu.org (full text, mbox):

From: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 51095 <at> debbugs.gnu.org
Subject: Re: bug#51095: 28.0.50; Counter-intuitive `cursor-intangible-mode'
 behavior
Date: Fri, 15 Oct 2021 19:56:39 -0300
( I realize now I've probably failed to reply properly.
            I'm resending my previous message,
           apologies if you've gotten it already        )

---------------------------------------------------------------------

I see, thanks for the clarification.

What really had me confused was that, when your cursor is
in that position (the first X), `describe-char' claims:
>There are text properties here:
>  cursor-intangible    t

Perhaps the manual entry explaining this property should
clarify the nuances of the usual character after point v.
this concept of point being between the characters.

Still, I find this behavior odd from an usability standpoint.
I did some grep'ing in the core and ELPA packages to see how
often the workaround of front/rear-nonsticky is used.
From a glance I could only find a couple of packages explicitly
doing that, but then again you can count the amount of packages
extensively using `cursor-intangible' on the fingers of one hand.
All in all, not a very conclusive search besides confirming
the current behavior is indeed desirable in some situations.

---------------------------------------------------------------------

Addendum: If you disagree, or otherwise can't think of any further improvements
          to that section (I can't think of any tangible suggestion myself),
          feel free to close this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Sun, 14 Nov 2021 02:16:01 GMT) Full text and rfc822 format available.

Message #19 received at 51095 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
Cc: 51095 <at> debbugs.gnu.org
Subject: Re: bug#51095: 28.0.50; Counter-intuitive `cursor-intangible-mode'
 behavior
Date: Sun, 14 Nov 2021 03:15:08 +0100
Brahimi Saifullah <brahimi.saifullah <at> gmail.com> writes:

> Perhaps the manual entry explaining this property should
> clarify the nuances of the usual character after point v.
> this concept of point being between the characters.

Yup.  I've now added an explanation (and a code example) to the entry in
the manual in Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 29.1, send any further explanations to 51095 <at> debbugs.gnu.org and Brahimi Saifullah <brahimi.saifullah <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 14 Nov 2021 02:16:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51095; Package emacs. (Sun, 14 Nov 2021 22:26:02 GMT) Full text and rfc822 format available.

Message #24 received at 51095 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Brahimi Saifullah <brahimi.saifullah <at> gmail.com>
Cc: 51095 <at> debbugs.gnu.org
Subject: Re: bug#51095: 28.0.50; Counter-intuitive `cursor-intangible-mode'
 behavior
Date: Sun, 14 Nov 2021 17:25:35 -0500
> Let's start with the following example:
> emacs -Q
> M-: (insert "|" (propertize "xxxxx" 'cursor-intangible t) "|")
> M-x cursor-intangible-mode
>
> Result:
> |xxxxx|
>   ^^^^^ You can't move the cursor here
>
> What I expected:
> |xxxxx|
>  ^^^^^ You can't move the cursor here
>
> To clarify, although all the `X's are set to be intangible, you can still move
> your cursor to the first one.  Furthermore, even though neither `|' has a text
> property, you cannot move your cursor to the last one.

If you want `xxxxx` to be intangible, that means you presumably still
want to be able to move the cursor between the two `|` but the cursor
movement should be "as if" the `xxxxx` was absent (so the `xxxxx` will
be either attached to the first `|` or to the second).

If so, where do you want to place the cursor when it's between the two `|`?
One choice is to place it right after the first `|`, another is to place
it right before the second `|`.  Both choices make sense, AFAICT, and
you haven't explicitly specified which you want (other than in this bug
report, that is), so the behavior you see looks OK to me.

You can control this behavior via the stickiness property.

> Basically, make the first character front-sticky, and the last character
> rear-nonsticky.  Now it works as expected.

But now you allow the cursor to be either before the `xxxxx` or after
the `xxxxx`, so they're not really intangible any more.  It seems you
want them to be "atomic" instead, which we do not directly support (you
can simulate it by marking the first four `x` as `intangible`, for
example).

> The question is: Is this behavior intuitive?

Depends what you want, obviously.


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 13 Dec 2021 12:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 96 days ago.

Previous Next


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