bug#3904: 23.1.50; [PATCH] keyboard translating with timer doesn't work well

Naohiro Aota <[email protected]>
Newsgroups gmane.emacs.bugs,gmane.emacs.pretest.bugs
Message-ID <[email protected]>
I found evaluating the following code outputs "abbbbb ...", and
M-x view-lossage after that shows "b b b b b ...".

(progn
  (keyboard-translate ?a ?b)
  (push ?a unread-command-events)
  (setq my-timer
  	(run-with-idle-timer 1 t (lambda () (push ?a unread-command-events)))))

This result suggests three problems.

1. If a timer handler function uses `sit-for' (or any function push a
   key to `unread-command-events'), the key would be translated once
   more.

2. idle-timer function should run "only once for each time Emacs
   becomes idle", but it seems the above function is called so many times.

3. `view-lossage' shouldn't show such stroke: "b b b b b ...".

I don't know this is the right way, but it seems the patch below solves
all the problem above.

--8<---------------cut here---------------start------------->8---
Index: src/keyboard.c
===================================================================
RCS file: /sources/emacs/emacs/src/keyboard.c,v
retrieving revision 1.1008
diff -c -r1.1008 keyboard.c
*** src/keyboard.c	3 Jul 2009 11:07:11 -0000	1.1008
--- src/keyboard.c	22 Jul 2009 17:20:11 -0000
***************
*** 2988,2993 ****
--- 2988,2994 ----
      {
        c = XCAR (Vunread_command_events);
        Vunread_command_events = XCDR (Vunread_command_events);
+       goto reread_for_input_method;
      }
  
    /* Read something from current KBOARD's side queue, if possible.  */
--8<---------------cut here---------------end--------------->8---


2009-07-22  Naohiro Aota  <[email protected]>

	* keyboard.c (read_char): When event set by a timer, sentinel or
	filter, skip keyboard translating and key recording.

Regards,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.