From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#20454: 24.4; Emacs keyboard macros not working correctly Date: Wed, 29 Apr 2015 19:51:07 +0300 Message-ID: <83ioceubd0.fsf@gnu.org> References: <982083367.276894.1430282967819.JavaMail.yahoo@mail.yahoo.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1430326403 32702 80.91.229.3 (29 Apr 2015 16:53:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Apr 2015 16:53:23 +0000 (UTC) Cc: 20454@debbugs.gnu.org To: Leo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 29 18:53:12 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YnVEV-0002Wd-2x for geb-bug-gnu-emacs@m.gmane.org; Wed, 29 Apr 2015 18:53:11 +0200 Original-Received: from localhost ([::1]:40119 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnVEU-0005mG-CL for geb-bug-gnu-emacs@m.gmane.org; Wed, 29 Apr 2015 12:53:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnVEP-0005m0-UP for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2015 12:53:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnVEM-0005KG-NP for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2015 12:53:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46656) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnVEM-0005KC-Jw for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2015 12:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YnVEM-0004Nd-AM for bug-gnu-emacs@gnu.org; Wed, 29 Apr 2015 12:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Apr 2015 16:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20454 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20454-submit@debbugs.gnu.org id=B20454.143032634216790 (code B ref 20454); Wed, 29 Apr 2015 16:53:02 +0000 Original-Received: (at 20454) by debbugs.gnu.org; 29 Apr 2015 16:52:22 +0000 Original-Received: from localhost ([127.0.0.1]:56631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YnVDi-0004Mk-26 for submit@debbugs.gnu.org; Wed, 29 Apr 2015 12:52:22 -0400 Original-Received: from mtaout28.012.net.il ([80.179.55.184]:43699) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YnVDe-0004MV-Qw for 20454@debbugs.gnu.org; Wed, 29 Apr 2015 12:52:20 -0400 Original-Received: from conversion-daemon.mtaout28.012.net.il by mtaout28.012.net.il (HyperSendmail v2007.08) id <0NNK00000UIKVD00@mtaout28.012.net.il> for 20454@debbugs.gnu.org; Wed, 29 Apr 2015 19:50:01 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout28.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NNK00H76URDWM90@mtaout28.012.net.il>; Wed, 29 Apr 2015 19:50:01 +0300 (IDT) In-reply-to: <982083367.276894.1430282967819.JavaMail.yahoo@mail.yahoo.com> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:102243 Archived-At: > Date: Wed, 29 Apr 2015 04:49:27 +0000 (UTC) > From: Leo > > (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 moves cursor forward by 1 word > 2 moves cursor forward by 1 word > 3 moves cursor forward by 1 word > 4 moves cursor forward by 1 word > > Case Define macro by using Result when pressing > # this key sequence: again: > ---- --------------------- -------------------- > 11 moves cursor forward by 1 word > 12 nothing > 13 nothing > 14 nothing > 15 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)