Subject: Re: bug#21313: 25.0.50; Strange errors from dbus-handle-event

From: Tassilo Horn <[email-masked]>
Date: Sat, 03 Oct 2015 10:10:58 +0200

Eli Zaretskii <[email-masked]> writes:

> Fmake_vector needs a Lisp integer as its first argument, i.e. you need
> to use make_number.  (And I'd suggest to use Qnil or some other Lisp
> object as the second, not a C zero, although currently Qnil's value is
> indeed zero.)

Ah, ok.  And then Vth_event_buffer_idx also needs to be a Lisp integer.
So I tried this:

--8<---------------cut here---------------start------------->8---
diff --git a/src/keyboard.c b/src/keyboard.c
index 966af69..fce819c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3412,6 +3412,12 @@ kbd_buffer_nr_stored (void)
 void
 kbd_buffer_store_event (register struct input_event *event)
 {
+  Faset (Vth_event_buffer, Vth_event_buffer_idx, make_lispy_event (event));
+  if (Vth_event_buffer_idx == make_number (99))
+    Vth_event_buffer_idx = make_number (0);
+  else
+    Vth_event_buffer_idx = call2 (Qplus, Vth_event_buffer, make_number (1));
+
   kbd_buffer_store_event_hold (event, 0);
 }
 
@@ -11131,6 +11137,14 @@ syms_of_keyboard (void)
   defsubr (&Sposn_at_point);
   defsubr (&Sposn_at_x_y);
 
+  DEFVAR_LISP ("th-input-event-buffer", Vth_event_buffer,
+              doc: /* The last 100 events.  */);
+  Vth_event_buffer = Fmake_vector(make_number (100), Qnil);
+
+  DEFVAR_LISP ("th-input-event-buffer-idx", Vth_event_buffer_idx,
+              doc: /* Current index in th-event-buffer.  */);
+  Vth_event_buffer_idx = make_number (0);
+
   DEFVAR_LISP ("last-command-event", last_command_event,
                     doc: /* Last input event that was part of a command.  */);
 
--8<---------------cut here---------------end--------------->8---

But then I get:

--8<---------------cut here---------------start------------->8---
In toplevel form:
notifications.el:37:1:Error: Wrong type argument: number-or-marker-p, [(dbus-event :system 2 2 "org.freedesktop.DBus" nil nil nil dbus-call-method-handler) nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil]
Makefile:269: recipe for target 'notifications.elc' failed
make[2]: *** [notifications.elc] Error 1
make[2]: *** Waiting for unfinished jobs....
  ELC      pcmpl-linux.elc

In pcomplete/tar:
pcmpl-gnu.el:162:47:Warning: \u2018pcomplete-suffix-list\u2019 is an obsolete variable
    (as of 24.1).
make[2]: Leaving directory '/home/horn/Repos/el/emacs-debug/lisp'
Makefile:292: recipe for target 'compile-main' failed
make[1]: *** [compile-main] Error 2
make[1]: Leaving directory '/home/horn/Repos/el/emacs-debug/lisp'
Makefile:385: recipe for target 'lisp' failed
make: *** [lisp] Error 2
--8<---------------cut here---------------end--------------->8---

I guess that naive approach won't work because make_lispy_event is not
free of side-effects.  It actually modifies the event so calling it
twice per event has negative consequences.

Well, I now try following Michaels suggesting of reverting this one
commit about `unread-command-events'.

Bye,
Tassilo