all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#20454: 24.4; Emacs keyboard macros not working correctly
@ 2015-04-29  4:49 Leo
  2015-04-29 16:51 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Leo @ 2015-04-29  4:49 UTC (permalink / raw)
  To: 20454

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

Hello,
I'm reporting the following bug that I found in Emacs. The textbelow lines up better with a monospace font. So if you want,
you could copy and paste it into an emacs buffer to see thetext aligned correctly.

Keyboard macros not working correctly
------------------------------------
Emacs has a problem when defining a keyboard macro using <f3>
and <f4>. If the macro contains a key sequence consisting of
a prefix key followed by an ASCII-character key, there is no
problem. However, if the key following the prefix key is
something other than an single character, such as a function
key, a keypad key, or an arrow key, the defined macro doesn't
work when it is subsequently executed with <f4>. And, there
is no error message. See details below.

Platform & Emacs version
------------------------
   GNU Emacs 24.4.1 (i686-pc-mingw32)
      of 2014-10-24 on LEG570
      Configured using: `configure --prefix=/c/usr'
   Windows 7 Home Premium (64-bit) - version 6.1.7600
   Intel Core i7 CPU - 1.73 GHz - 6 GB RAM
   ASUS Notebook G73Jw

Started Emacs at Command Prompt with this command:
--------------------------------------------------
   run_emacs.bat -Q

Executed this lisp code in *Scratch* buffer:
--------------------------------------------
   (progn
      (setq f5-key-map (make-sparse-keymap "F5-Key-prefix"))
      (define-key global-map [f5] f5-key-map)

      (define-key f5-key-map [(g)]   'forward-word)
      (define-key f5-key-map [f6]    'forward-word)
      (define-key f5-key-map [kp-4]  'forward-word)
      (define-key f5-key-map [right] 'forward-word)
   )

Case  This key
  #    sequence      Produces this result
----  --------      --------------------
  1   <f5> <g>      moves cursor forward by 1 word
  2   <f5> <f6>     moves cursor forward by 1 word
  3   <f5> <kp-4>   moves cursor forward by 1 word
  4   <f5> <right>  moves cursor forward by 1 word

Case   Define macro by using         Result when pressing
  #     this key sequence:             <f4> again:
----   ---------------------         --------------------
 11    <f3> <f5> <g> <f4>            moves cursor forward by 1 word
 12    <f3> <f5> <f6> <f4>           nothing
 13    <f3> <f5> <kp-4> <f4>         nothing
 14    <f3> <f5> <right> <f4>        nothing
 15    <f3> <f5> <f6> <right> <f4>   moves cursor forward by 1 word

Cases #12, #13, and #14 do not work at all. Nothing happens, and
there is no error message.

Case #11 is the only case where the macro works correctly.

Even though the macro in case #15 appears to work, it isn't working
correctly. It should move the cursor forward by one word AND one
character, but it only moves by one word. My guess is that, in
case #15 (as in case #12), the key <f6> is being ignored.

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

In an effort to help debug case #15, I executed this
additional lisp code in the *scratch* buffer:

   (progn
      (defun define-macro-f8 () ""
         (interactive) (name-last-kbd-macro 'macro-f8))
      (defun insert-macro-f8 () ""
         (interactive) (insert-kbd-macro 'macro-f8))
      (define-key global-map [f7] 'define-macro-f8)
      (define-key global-map [f8] 'macro-f8)
      (define-key global-map [f9] 'insert-macro-f8)
   )

Whereupon, this key sequence puts the macro (from case #15) into <f8>:

   <f3> <f5> <f6> <right> <f4> <f7>

Then, every time I press <f8>, the cursor moves forward, as before, by
one word (NOT one word and one character, as it should). And then,
when I press <f9>, this macro definition is inserted into the buffer:

   (fset 'macro-f8 [f5 right])

As you can see, the <f6> key is missing.

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

By the way, I tried something similar in Xemacs, and it has no
problem defining keyboard macros containing the same key sequences.
So, probably, my platform is not causing the problem.

Thank you.
Best regards,Leo

[-- Attachment #2: Type: text/html, Size: 8351 bytes --]

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

* bug#20454: 24.4; Emacs keyboard macros not working correctly
  2015-04-29  4:49 bug#20454: 24.4; Emacs keyboard macros not working correctly Leo
@ 2015-04-29 16:51 ` Eli Zaretskii
  2015-05-08  9:16   ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2015-04-29 16:51 UTC (permalink / raw)
  To: Leo; +Cc: 20454

> Date: Wed, 29 Apr 2015 04:49:27 +0000 (UTC)
> From: Leo <used_to_be_leo@yahoo.com>
> 
> (progn
> (setq f5-key-map (make-sparse-keymap "F5-Key-prefix"))
> (define-key global-map [f5] f5-key-map)
> 
> (define-key f5-key-map [(g)] 'forward-word)
> (define-key f5-key-map [f6] 'forward-word)
> (define-key f5-key-map [kp-4] 'forward-word)
> (define-key f5-key-map [right] 'forward-word)
> )
> 
> Case This key
> # sequence Produces this result
> ---- -------- --------------------
> 1 <f5> <g> moves cursor forward by 1 word
> 2 <f5> <f6> moves cursor forward by 1 word
> 3 <f5> <kp-4> moves cursor forward by 1 word
> 4 <f5> <right> moves cursor forward by 1 word
> 
> Case Define macro by using Result when pressing
> # this key sequence: <f4> again:
> ---- --------------------- --------------------
> 11 <f3> <f5> <g> <f4> moves cursor forward by 1 word
> 12 <f3> <f5> <f6> <f4> nothing
> 13 <f3> <f5> <kp-4> <f4> nothing
> 14 <f3> <f5> <right> <f4> nothing
> 15 <f3> <f5> <f6> <right> <f4> moves cursor forward by 1 word
> 
> Cases #12, #13, and #14 do not work at all. Nothing happens, and
> there is no error message.

If you display the macro after defining it, e.g. with
kmacro-view-macro, or even simply evaluate kmacro-ring, you will see
that only f5 gets recorded there, the following function keys don't.
Only in the "f5 g" case will you see the 'g' in the macro.  That's why
the macro cannot be executed: there's only a prefix key there.

This happens because of the following trick we play in
read_char_minibuf_menu_prompt, which is a function we call whenever a
key we read is a prefix key:

      /* Make believe it's not a keyboard macro in case the help char
	 is pressed.  Help characters are not recorded because menu prompting
	 is not used on replay.  */
      orig_defn_macro = KVAR (current_kboard, defining_kbd_macro);
      kset_defining_kbd_macro (current_kboard, Qnil);
      do
	obj = read_char (commandflag, Qnil, Qt, 0, NULL);
      while (BUFFERP (obj));
      kset_defining_kbd_macro (current_kboard, orig_defn_macro);

      if (!INTEGERP (obj) || XINT (obj) == -2)
        return obj;

If 'obj' that we read is not a character (as is the case with f6 and
any other function key -- they are symbols), we return here without
recording the key in the macro, as we disabled that recording by
temporarily setting defining_kbd_macro to nil.

The trivial patch below fixes this, but before pushing it, I'd like
Stefan and others to eyeball this, in case there be dragons.

Btw, this has been broken "forever": I see it in Emacs 21.4.

--- src/keyboard.c~0	2015-04-26 07:42:05 +0300
+++ src/keyboard.c	2015-04-29 16:27:42 +0300
@@ -8708,7 +8708,11 @@ read_char_minibuf_menu_prompt (int comma
       kset_defining_kbd_macro (current_kboard, orig_defn_macro);
 
       if (!INTEGERP (obj) || XINT (obj) == -2)
-        return obj;
+	{
+	  if (!NILP (KVAR (current_kboard, defining_kbd_macro)))
+	    store_kbd_macro_char (obj);
+	  return obj;
+	}
 
       if (! EQ (obj, menu_prompt_more_char)
 	  && (!INTEGERP (menu_prompt_more_char)





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

* bug#20454: 24.4; Emacs keyboard macros not working correctly
  2015-04-29 16:51 ` Eli Zaretskii
@ 2015-05-08  9:16   ` Eli Zaretskii
  2015-05-08 17:44     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2015-05-08  9:16 UTC (permalink / raw)
  To: used_to_be_leo; +Cc: 20454-done

> Date: Wed, 29 Apr 2015 19:51:07 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: 20454@debbugs.gnu.org
> 
> The trivial patch below fixes this, but before pushing it, I'd like
> Stefan and others to eyeball this, in case there be dragons.

No comments, so I pushed that fix, and I'm closing the bug report.





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

* bug#20454: 24.4; Emacs keyboard macros not working correctly
  2015-05-08  9:16   ` Eli Zaretskii
@ 2015-05-08 17:44     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2015-05-08 17:44 UTC (permalink / raw)
  To: 20454; +Cc: used_to_be_leo

>> The trivial patch below fixes this, but before pushing it, I'd like
>> Stefan and others to eyeball this, in case there be dragons.
> No comments, so I pushed that fix, and I'm closing the bug report.

Sorry, dropped the ball again.  Yes, it looks OK.
Not sure if it's "the right way to fix it" because this code is too
delicate for its own good, but it's a good enough way,


        Stefan





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

end of thread, other threads:[~2015-05-08 17:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-29  4:49 bug#20454: 24.4; Emacs keyboard macros not working correctly Leo
2015-04-29 16:51 ` Eli Zaretskii
2015-05-08  9:16   ` Eli Zaretskii
2015-05-08 17:44     ` Stefan Monnier

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.