unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* Setting cursor-type does not trigger redisplay of cursor
@ 2005-10-31 15:49 Hrvoje Niksic
  2005-11-01  9:18 ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Hrvoje Niksic @ 2005-10-31 15:49 UTC (permalink / raw)


This bug report will be sent to the Free Software Foundation,
not to your local site managers!
Please write in English, because the Emacs maintainers do not have
translators to read other languages for them.

Your bug report will be posted to the bug-gnu-emacs@gnu.org mailing list,
and to the gnu.emacs.bug news group.

In GNU Emacs 21.4.1 (i386-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2005-03-17 on trouble, modified by Debian
configured using `configure '--build=i386-linux' '--host=i386-linux' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--with-x=yes' '--with-x-toolkit=athena' 'CFLAGS=-DDEBIAN -g -O2' 'build_alias=i386-linux' 'host_alias=i386-linux''
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US
  locale-coding-system: iso-latin-1
  default-enable-multibyte-characters: t

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:

I wanted to set cursor-type off post-command-hook with the intention
of changing the cursor appearance depending on whether the point is at
the end of line/buffer or not.  (This emulates an XEmacs feature of
showing a thin cursor at the end of line.)  Something like:

(defun set-cursor-adaptive ()
  (setq cursor-type (if (eq (char-after (point)) ?\n) '(bar . 5) t)))
(add-hook 'post-command-hook 'set-cursor-adaptive)

However, it turns out that this doesn't work as well as it should --
apparently changing `cursor-type' does not affect the shape of the
cursor until after it is redrawn, either by changing the position of
point, or by redrawing the frame.  I can work around that by calling
(sit-for 0), but it seems wasteful to invoke redisplay after every
single command.  I ended up checking whether the cursor would actually
change, and calling (sit-for 0) then, like this:

(defun set-cursor-adaptive ()
  (let ((type (let ((c (char-after (point))))
		(if (or (eq c ?\n) (null c))
		    '(bar . 5)
		  t))))
    (if (not (equal cursor-type type))
	(progn
	  (setq cursor-type type)
	  (sit-for 0)))))
(add-hook 'post-command-hook 'set-cursor-adaptive)

To summarize, changing the cursor type should IMO automatically
refresh the cursor when the event loop is reentered, without the user
having to do anything special.  This would be consistent with the rest
of Emacs, which doesn't require Lisp code to explicitly trigger
redisplay -- it simply happens when necessary.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-10-31 15:49 Setting cursor-type does not trigger redisplay of cursor Hrvoje Niksic
@ 2005-11-01  9:18 ` Juri Linkov
  2005-11-01 13:51   ` Hrvoje Niksic
  2005-11-02 10:27   ` Richard M. Stallman
  0 siblings, 2 replies; 13+ messages in thread
From: Juri Linkov @ 2005-11-01  9:18 UTC (permalink / raw)
  Cc: bug-gnu-emacs

> (defun set-cursor-adaptive ()
>   (setq cursor-type (if (eq (char-after (point)) ?\n) '(bar . 5) t)))
> (add-hook 'post-command-hook 'set-cursor-adaptive)
>
> However, it turns out that this doesn't work as well as it should --
> apparently changing `cursor-type' does not affect the shape of the
> cursor until after it is redrawn, either by changing the position of
> point, or by redrawing the frame.

As I see, this works correctly in the CVS version.

BTW, I use this code to change cursor type and color:

(defun my-change-cursor ()
  "Change cursor color and type depending on insertion mode and input method."
  (set-cursor-color
   (cond (current-input-method "OrangeRed4")
         (t                    "black")))
  (set-cursor-type
   (cond (overwrite-mode       'box)
         (t                    'bar))))
(add-hook 'post-command-hook 'my-change-cursor)

There is no function `set-cursor-type' in CVS.  I use the patch below.
Note that it changes frame parameters instead of the buffer-local
variable `cursor-type'.  I think this causes less trouble.  Perhaps
this patch could be installed in CVS.

Index: lisp/frame.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/frame.el,v
retrieving revision 1.230
diff -c -r1.230 frame.el
*** lisp/frame.el	21 Oct 2005 08:27:04 -0000	1.230
--- lisp/frame.el	1 Nov 2005 09:17:22 -0000
***************
*** 903,917 ****
--- 903,928 ----
    (modify-frame-parameters (selected-frame)
  			   (list (cons 'cursor-color color-name))))
  
+ (defun set-cursor-type (cursor-type)
+   "Set the text cursor type of the selected frame to CURSOR-TYPE.
+ When called interactively, prompt for the name of the type to use.
+ To get the frame's current cursor type, use `frame-parameters'."
+   (interactive (list (intern (completing-read
+ 			      "Cursor type: "
+ 			      '("box" "hollow" "bar" "hbar" nil)))))
+   (modify-frame-parameters (selected-frame)
+ 			   (list (cons 'cursor-type cursor-type))))
+ 
  (defun set-mouse-color (color-name)
    "Set the color of the mouse pointer of the selected frame to COLOR-NAME.
  When called interactively, prompt for the name of the color to use.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-01  9:18 ` Juri Linkov
@ 2005-11-01 13:51   ` Hrvoje Niksic
  2005-11-01 20:03     ` Juri Linkov
  2005-11-02 10:27   ` Richard M. Stallman
  1 sibling, 1 reply; 13+ messages in thread
From: Hrvoje Niksic @ 2005-11-01 13:51 UTC (permalink / raw)
  Cc: bug-gnu-emacs

Juri Linkov <juri@jurta.org> writes:

>> (defun set-cursor-adaptive ()
>>   (setq cursor-type (if (eq (char-after (point)) ?\n) '(bar . 5) t)))
>> (add-hook 'post-command-hook 'set-cursor-adaptive)
>>
>> However, it turns out that this doesn't work as well as it should --
>> apparently changing `cursor-type' does not affect the shape of the
>> cursor until after it is redrawn, either by changing the position of
>> point, or by redrawing the frame.
>
> As I see, this works correctly in the CVS version.

Are you sure?  It sometimes requires a bit more testing for the bug to
appear.  Also, if you modify frame parameters off post-command-hook
with your code, that might trigger redisplay in its own right.

> There is no function `set-cursor-type' in CVS.  I use the patch
> below.  Note that it changes frame parameters instead of the
> buffer-local variable `cursor-type'.  I think this causes less
> trouble.

Why?  If anything, cursor type should be *window*-local.  Then, if you
change the cursor based on buffer contents (as my hook does), it is
wrong to modify it for the entire frame.  After all, frames can and do
have more than one window.

> + (defun set-cursor-type (cursor-type)
> +   "Set the text cursor type of the selected frame to CURSOR-TYPE.
> + When called interactively, prompt for the name of the type to use.
> + To get the frame's current cursor type, use `frame-parameters'."
> +   (interactive (list (intern (completing-read
> + 			      "Cursor type: "
> + 			      '("box" "hollow" "bar" "hbar" nil)))))
> +   (modify-frame-parameters (selected-frame)
> + 			   (list (cons 'cursor-type cursor-type))))
> + 

Setting the cursor type interactively does not appear useful.  This
command would IMHO needlessly clutter the command namespace.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-01 13:51   ` Hrvoje Niksic
@ 2005-11-01 20:03     ` Juri Linkov
  2005-11-01 21:07       ` Hrvoje Niksic
  0 siblings, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2005-11-01 20:03 UTC (permalink / raw)
  Cc: bug-gnu-emacs

>>> (defun set-cursor-adaptive ()
>>>   (setq cursor-type (if (eq (char-after (point)) ?\n) '(bar . 5) t)))
>>> (add-hook 'post-command-hook 'set-cursor-adaptive)
>>>
>>> However, it turns out that this doesn't work as well as it should --
>>> apparently changing `cursor-type' does not affect the shape of the
>>> cursor until after it is redrawn, either by changing the position of
>>> point, or by redrawing the frame.
>>
>> As I see, this works correctly in the CVS version.
>
> Are you sure?  It sometimes requires a bit more testing for the bug to
> appear.

Have you tested it in Emacs CVS?  I tried your recipe in Emacs 21.4
where I can reproduce this bug.  But in Emacs CVS the same recipe
works correctly.

>> There is no function `set-cursor-type' in CVS.  I use the patch
>> below.  Note that it changes frame parameters instead of the
>> buffer-local variable `cursor-type'.  I think this causes less
>> trouble.
>
> Why?  If anything, cursor type should be *window*-local.  Then, if you
> change the cursor based on buffer contents (as my hook does), it is
> wrong to modify it for the entire frame.  After all, frames can and do
> have more than one window.

Maybe, window-local is a better scope, but currently cursor type can
be either buffer-local or frame-local.

> Setting the cursor type interactively does not appear useful.
> This command would IMHO needlessly clutter the command namespace.

It is not very useful, but there is already a similar interactive
command `set-cursor-color', and I see no reason to have
`set-cursor-color', and not to have `set-cursor-type'.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-01 20:03     ` Juri Linkov
@ 2005-11-01 21:07       ` Hrvoje Niksic
  2005-11-01 22:08         ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: Hrvoje Niksic @ 2005-11-01 21:07 UTC (permalink / raw)
  Cc: bug-gnu-emacs

Juri Linkov <juri@jurta.org> writes:

> Have you tested it in Emacs CVS?

Sorry, not yet.  However, a friend of mine tested it with the Debian
emacs-snapshot package which is supposed to be based on Emacs CVS, and
reports a similar problem -- even with the (sit-for 0) workaround.
But I haven't checked for myself yet.

But if you see the problem with 21 and don't see it with CVS, then I
guess the bug was really fixed.  I was previously under the impression
that you *only* tried it in CVS and didn't see the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-01 21:07       ` Hrvoje Niksic
@ 2005-11-01 22:08         ` Juri Linkov
  0 siblings, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2005-11-01 22:08 UTC (permalink / raw)
  Cc: bug-gnu-emacs

> However, a friend of mine tested it with the Debian emacs-snapshot
> package which is supposed to be based on Emacs CVS, and reports
> a similar problem -- even with the (sit-for 0) workaround.
> But I haven't checked for myself yet.
>
> But if you see the problem with 21 and don't see it with CVS, then I
> guess the bug was really fixed.  I was previously under the impression
> that you *only* tried it in CVS and didn't see the bug.

First I tried it under Emacs 21.4, and after that I tried with the same
point movements in CVS, and didn't notice this bug.  However, now after
I tried more in Emacs CVS, I can reproduce this bug.  Its behavior is
different in Emacs 21.4 and CVS.  In Emacs 21.4 it failed to update the
cursor on horizontal point movements, but in Emacs CVS it doesn't update
the cursor on vertical point movements.  And yes, even (sit-for 0) doesn't
help.  So the bug is still here.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-01  9:18 ` Juri Linkov
  2005-11-01 13:51   ` Hrvoje Niksic
@ 2005-11-02 10:27   ` Richard M. Stallman
  2005-11-02 14:18     ` Hrvoje Niksic
  2005-11-03  7:54     ` Juri Linkov
  1 sibling, 2 replies; 13+ messages in thread
From: Richard M. Stallman @ 2005-11-02 10:27 UTC (permalink / raw)
  Cc: bug-gnu-emacs, hniksic

I see no need for a set-cursor-type.  It seems easy enough for people
to do that using modify-frame-parameters.

Do a lot of people really want to change this?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-02 10:27   ` Richard M. Stallman
@ 2005-11-02 14:18     ` Hrvoje Niksic
  2005-11-03  7:54       ` Juri Linkov
  2005-11-03 13:50       ` Richard M. Stallman
  2005-11-03  7:54     ` Juri Linkov
  1 sibling, 2 replies; 13+ messages in thread
From: Hrvoje Niksic @ 2005-11-02 14:18 UTC (permalink / raw)
  Cc: bug-gnu-emacs

"Richard M. Stallman" <rms@gnu.org> writes:

> I see no need for a set-cursor-type.

Note that my original bug report does not request a set-cursor-type.
I would just like Emacs to automatically "notice" a change (of any
kind) to cursor-type at the next redisplay.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-02 10:27   ` Richard M. Stallman
  2005-11-02 14:18     ` Hrvoje Niksic
@ 2005-11-03  7:54     ` Juri Linkov
  2005-11-03 21:41       ` Richard M. Stallman
  1 sibling, 1 reply; 13+ messages in thread
From: Juri Linkov @ 2005-11-03  7:54 UTC (permalink / raw)
  Cc: bug-gnu-emacs, hniksic

> I see no need for a set-cursor-type.  It seems easy enough for people
> to do that using modify-frame-parameters.

There are other functions that use modify-frame-parameters like
set-cursor-color, set-mouse-color, etc.  And why not to add
set-cursor-type too?  The only difference is that there is
a buffer-local variable cursor-type, but no cursor-color.

> Do a lot of people really want to change this?

This is an addition rather than a change.  People might want to use it
instead of (setq cursor-type ...).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-02 14:18     ` Hrvoje Niksic
@ 2005-11-03  7:54       ` Juri Linkov
  2005-11-03 13:50       ` Richard M. Stallman
  1 sibling, 0 replies; 13+ messages in thread
From: Juri Linkov @ 2005-11-03  7:54 UTC (permalink / raw)
  Cc: bug-gnu-emacs, rms

> "Richard M. Stallman" <rms@gnu.org> writes:
>
>> I see no need for a set-cursor-type.
>
> Note that my original bug report does not request a set-cursor-type.
> I would just like Emacs to automatically "notice" a change (of any
> kind) to cursor-type at the next redisplay.

If the bug you reported will not get fixed until the next release,
then it makes sense to add a new special function and suggest users
to use it instead of (setq cursor-type ...).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-02 14:18     ` Hrvoje Niksic
  2005-11-03  7:54       ` Juri Linkov
@ 2005-11-03 13:50       ` Richard M. Stallman
  2005-11-03 18:04         ` Hrvoje Niksic
  1 sibling, 1 reply; 13+ messages in thread
From: Richard M. Stallman @ 2005-11-03 13:50 UTC (permalink / raw)
  Cc: bug-gnu-emacs

    Note that my original bug report does not request a set-cursor-type.
    I would just like Emacs to automatically "notice" a change (of any
    kind) to cursor-type at the next redisplay.

Right now, what is it that you need to do
to make Emacs really display the new cursor type?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-03 13:50       ` Richard M. Stallman
@ 2005-11-03 18:04         ` Hrvoje Niksic
  0 siblings, 0 replies; 13+ messages in thread
From: Hrvoje Niksic @ 2005-11-03 18:04 UTC (permalink / raw)
  Cc: bug-gnu-emacs

"Richard M. Stallman" <rms@gnu.org> writes:

>     Note that my original bug report does not request a set-cursor-type.
>     I would just like Emacs to automatically "notice" a change (of any
>     kind) to cursor-type at the next redisplay.
>
> Right now, what is it that you need to do to make Emacs really
> display the new cursor type?

In Emacs 21, I need to call (sit-for 0) to force a redisplay.  In
Emacs 22 CVS, I am told, that doesn't work.

Both apply to setting cursor-type in post-command-hook, not to setting
it interactively with `M-: (setq cursor-type ...) RET'.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Setting cursor-type does not trigger redisplay of cursor
  2005-11-03  7:54     ` Juri Linkov
@ 2005-11-03 21:41       ` Richard M. Stallman
  0 siblings, 0 replies; 13+ messages in thread
From: Richard M. Stallman @ 2005-11-03 21:41 UTC (permalink / raw)
  Cc: bug-gnu-emacs, hniksic

    > I see no need for a set-cursor-type.  It seems easy enough for people
    > to do that using modify-frame-parameters.

    There are other functions that use modify-frame-parameters like
    set-cursor-color, set-mouse-color, etc.  And why not to add
    set-cursor-type too?

To save our time.  To keep the manual smaller.

If there is no positive reason to add something,
then we don't add it.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-11-03 21:41 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-31 15:49 Setting cursor-type does not trigger redisplay of cursor Hrvoje Niksic
2005-11-01  9:18 ` Juri Linkov
2005-11-01 13:51   ` Hrvoje Niksic
2005-11-01 20:03     ` Juri Linkov
2005-11-01 21:07       ` Hrvoje Niksic
2005-11-01 22:08         ` Juri Linkov
2005-11-02 10:27   ` Richard M. Stallman
2005-11-02 14:18     ` Hrvoje Niksic
2005-11-03  7:54       ` Juri Linkov
2005-11-03 13:50       ` Richard M. Stallman
2005-11-03 18:04         ` Hrvoje Niksic
2005-11-03  7:54     ` Juri Linkov
2005-11-03 21:41       ` Richard M. Stallman

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).