all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* read-event and unexpected buffer changes
@ 2013-04-28 20:41 Julien Danjou
  2013-05-23 17:31 ` Stefan Monnier
  2013-05-27 11:59 ` read-event and unexpected buffer changes Michael Albinus
  0 siblings, 2 replies; 9+ messages in thread
From: Julien Danjou @ 2013-04-28 20:41 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1485 bytes --]

Hi there,

I'm having a nasty bug and just spent an hour tracking it down.

I'm using `erc-desktop-notifications' to get IRC messages sent with my
nickname over D-Bus using `notifications-notify'. This function calls
`dbus-call-method' which contains the following snippet at the end:

    (with-timeout ((if timeout (/ timeout 1000.0) 25))
      (while (eq (gethash key dbus-return-values-table :ignore) :ignore)
	(let ((event (let (unread-command-events) (read-event nil nil 0.1))))
	  (when (and event (not (ignore-errors (dbus-check-event event))))
	    (setq unread-command-events
		  (append unread-command-events (list event)))))))

This `read-event' call causes me trouble. Basically what happens, is
that it changes the ERC buffer in a very subtle way so that the last
line is then on top. Basically, the buffer is supposed to be shown as:

/-----
| <jd> ohla
| <foo> hey
| <foo> how are you jd?
| [#bar]
\-----

But because of this `read-event' call, the buffer is "recentered to the
top" and I finally see this instead:

/-----
| <foo> how are you jd?
| [#bar]
|
| 
\-----

Which is utterly inconvenient. I've tried adding `save-excursion' around
(read-event), but that doesn't change anything. I wonder what this
function can do that changes the buffer, and in any way, that doesn't
look like an expected and right side effect.

Hint?
-- 
Julien Danjou
# Free Software hacker # freelance consultant
# http://julien.danjou.info

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: read-event and unexpected buffer changes
  2013-04-28 20:41 read-event and unexpected buffer changes Julien Danjou
@ 2013-05-23 17:31 ` Stefan Monnier
  2013-05-24 12:22   ` Michael Albinus
  2013-05-27 11:59 ` read-event and unexpected buffer changes Michael Albinus
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-05-23 17:31 UTC (permalink / raw)
  To: emacs-devel

> 	(let ((event (let (unread-command-events) (read-event nil nil 0.1))))
> 	  (when (and event (not (ignore-errors (dbus-check-event event))))
> 	    (setq unread-command-events
> 		  (append unread-command-events (list event)))))))

Why not use sit-for?

> But because of this `read-event' call, the buffer is "recentered to the
> top" and I finally see this instead:

The only expected side-effect is a redisplay (which could also trigger
things like jit-lock).

> Hint?

Sorry,


        Stefan



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

* Re: read-event and unexpected buffer changes
  2013-05-23 17:31 ` Stefan Monnier
@ 2013-05-24 12:22   ` Michael Albinus
  2013-05-24 15:48     ` DBus events processing (was: read-event and unexpected buffer changes) Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2013-05-24 12:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> 	(let ((event (let (unread-command-events) (read-event nil nil 0.1))))
>> 	  (when (and event (not (ignore-errors (dbus-check-event event))))
>> 	    (setq unread-command-events
>> 		  (append unread-command-events (list event)))))))
>
> Why not use sit-for?

<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11447#26>

>         Stefan

Best regards, Michael.



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

* DBus events processing (was: read-event and unexpected buffer changes)
  2013-05-24 12:22   ` Michael Albinus
@ 2013-05-24 15:48     ` Stefan Monnier
  2013-05-24 22:08       ` DBus events processing Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2013-05-24 15:48 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

>>> (let ((event (let (unread-command-events) (read-event nil nil 0.1))))
>>> (when (and event (not (ignore-errors (dbus-check-event event))))
>>> (setq unread-command-events
>>> (append unread-command-events (list event)))))))
>> Why not use sit-for?
> <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11447#26>

Ah, right!
Thinking about this problem some more, I think the problem is that dbus
events should be processed during sit-for, just like process filters are
run there.

DBus events come concurrently with keyboard&mouse events and then we
forcefully linearize them into the event queue, which is not right in
your case where you want to process the dbus events before the user's
key presses.

So we should change the C code for our dbus interface.  It could either
be shoehorned into the way process filters/sentinels are handled, or we
could add a secondary event queue for "asynchronous events".


        Stefan



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

* Re: DBus events processing
  2013-05-24 15:48     ` DBus events processing (was: read-event and unexpected buffer changes) Stefan Monnier
@ 2013-05-24 22:08       ` Michael Albinus
  2013-05-25  1:54         ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2013-05-24 22:08 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

> So we should change the C code for our dbus interface.  It could either
> be shoehorned into the way process filters/sentinels are handled, or we
> could add a secondary event queue for "asynchronous events".

Gimme some days, I'll try to understand how it works with process events.

However, I don't know whether such a change would solve Julien's problem.

>         Stefan

Best regards, Michael.



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

* Re: DBus events processing
  2013-05-24 22:08       ` DBus events processing Michael Albinus
@ 2013-05-25  1:54         ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2013-05-25  1:54 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

> However, I don't know whether such a change would solve Julien's problem.

It probably won't.  I just hijacked that part of your thread by focusing
on another part (hence the subject modification).


        Stefan



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

* Re: read-event and unexpected buffer changes
  2013-04-28 20:41 read-event and unexpected buffer changes Julien Danjou
  2013-05-23 17:31 ` Stefan Monnier
@ 2013-05-27 11:59 ` Michael Albinus
  2013-05-27 12:28   ` Julien Danjou
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2013-05-27 11:59 UTC (permalink / raw)
  To: emacs-devel

Julien Danjou <julien@danjou.info> writes:

> Hi there,

Hi,

> I'm using `erc-desktop-notifications' to get IRC messages sent with my
> nickname over D-Bus using `notifications-notify'. This function calls
> `dbus-call-method' which contains the following snippet at the end:
>
>     (with-timeout ((if timeout (/ timeout 1000.0) 25))
>       (while (eq (gethash key dbus-return-values-table :ignore) :ignore)
> 	(let ((event (let (unread-command-events) (read-event nil nil 0.1))))
> 	  (when (and event (not (ignore-errors (dbus-check-event event))))
> 	    (setq unread-command-events
> 		  (append unread-command-events (list event)))))))
>
> This `read-event' call causes me trouble. Basically what happens, is
> that it changes the ERC buffer in a very subtle way so that the last
> line is then on top.
>
> Hint?

Does the following patch suffices?

--8<---------------cut here---------------start------------->8---
*** /home/albinmic/src/emacs/lisp/net/dbus.el.~112739~    2013-05-27 13:51:51.844960427 +0200
--- /home/albinmic/src/emacs/lisp/net/dbus.el          2013-05-27
13:51:33.992671583 +0200
***************
*** 270,276 ****
      ;; default 25".  Events which are not from D-Bus must be restored.
      (with-timeout ((if timeout (/ timeout 1000.0) 25))
        (while (eq (gethash key dbus-return-values-table :ignore) :ignore)
!       (let ((event (let (unread-command-events) (read-event nil nil 0.1))))
          (when (and event (not (ignore-errors (dbus-check-event event))))
            (setq unread-command-events
                  (append unread-command-events (list event)))))))
--- 270,277 ----
      ;; default 25".  Events which are not from D-Bus must be restored.
      (with-timeout ((if timeout (/ timeout 1000.0) 25))
        (while (eq (gethash key dbus-return-values-table :ignore) :ignore)
!       (let ((event (let ((inhibit-redisplay t) unread-command-events)
!                      (read-event nil nil 0.1))))
          (when (and event (not (ignore-errors (dbus-check-event event))))
            (setq unread-command-events
                  (append unread-command-events (list event)))))))
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.



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

* Re: read-event and unexpected buffer changes
  2013-05-27 11:59 ` read-event and unexpected buffer changes Michael Albinus
@ 2013-05-27 12:28   ` Julien Danjou
  2013-05-27 12:42     ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Julien Danjou @ 2013-05-27 12:28 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 269 bytes --]

On Mon, May 27 2013, Michael Albinus wrote:

Hi Michael,

> Does the following patch suffices?

Yes indeed, it fixes the problem as far as I can tell!

Thanks!

-- 
Julien Danjou
// Free Software hacker / freelance consultant
// http://julien.danjou.info

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: read-event and unexpected buffer changes
  2013-05-27 12:28   ` Julien Danjou
@ 2013-05-27 12:42     ` Michael Albinus
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Albinus @ 2013-05-27 12:42 UTC (permalink / raw)
  To: emacs-devel

Julien Danjou <julien@danjou.info> writes:

> Hi Michael,

Hi Julien,

>> Does the following patch suffices?
>
> Yes indeed, it fixes the problem as far as I can tell!

Thanks for confirmation. I don't use erc myself, so I couldn't check.

The patch is committed to the trunk. I'll continue to investigate
Stefan's proposal about changed D-Bus event handling.

> Thanks!

Best regards, Michael.



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

end of thread, other threads:[~2013-05-27 12:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-28 20:41 read-event and unexpected buffer changes Julien Danjou
2013-05-23 17:31 ` Stefan Monnier
2013-05-24 12:22   ` Michael Albinus
2013-05-24 15:48     ` DBus events processing (was: read-event and unexpected buffer changes) Stefan Monnier
2013-05-24 22:08       ` DBus events processing Michael Albinus
2013-05-25  1:54         ` Stefan Monnier
2013-05-27 11:59 ` read-event and unexpected buffer changes Michael Albinus
2013-05-27 12:28   ` Julien Danjou
2013-05-27 12:42     ` Michael Albinus

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.