From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Convert a keyboard macro to equivalent Lisp code Date: Tue, 08 Jun 2010 11:05:32 +0300 Organization: JURTA Message-ID: <87iq5uuemn.fsf@mail.jurta.org> References: <87fx11mfd3.fsf@mail.jurta.org> <87bpbn55au.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1275987509 28080 80.91.229.12 (8 Jun 2010 08:58:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Jun 2010 08:58:29 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 08 10:58:26 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OLudc-0006e9-8I for ged-emacs-devel@m.gmane.org; Tue, 08 Jun 2010 10:58:24 +0200 Original-Received: from localhost ([127.0.0.1]:39693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLuax-0003va-1K for ged-emacs-devel@m.gmane.org; Tue, 08 Jun 2010 04:55:39 -0400 Original-Received: from [140.186.70.92] (port=56082 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLuS7-0002dh-D9 for emacs-devel@gnu.org; Tue, 08 Jun 2010 04:46:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLuRw-0002xg-ED for emacs-devel@gnu.org; Tue, 08 Jun 2010 04:46:30 -0400 Original-Received: from smtp-out2.starman.ee ([85.253.0.4]:36830 helo=mx2.starman.ee) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLuRw-0002xR-54 for emacs-devel@gnu.org; Tue, 08 Jun 2010 04:46:20 -0400 X-Virus-Scanned: by Amavisd-New at mx2.starman.ee Original-Received: from mail.starman.ee (82.131.55.231.cable.starman.ee [82.131.55.231]) by mx2.starman.ee (Postfix) with ESMTP id A01AE3F407E; Tue, 8 Jun 2010 11:28:40 +0300 (EEST) In-Reply-To: (Stefan Monnier's message of "Mon, 07 Jun 2010 16:11:39 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:125630 Archived-At: >> To get useful results, some commands should provide their arguments >> explicitly in the interactive spec instead of relying on global >> variables. So instead of useless `(self-insert-command 1)' typing `A' >> will record `(self-insert-command 1 65)' with the following patch. >> The same is for isearch. > > This will break all Elisp calls to self-insert-command (grep finds more > than 100 of them in lisp/**/*.el) ;-( I don't understand how it breaks Elisp calls. The new second arg `last_char' is optional. When it's nil, this code is executed to preserve the original behavior: if (NILP (last_char)) last_char = last_command_event; Or maybe not calling `translate_char' will break `self-insert-command'? > So I think it's not an option. Better would be to have your > command-recording code provide hooks such that commands like > self-insert-command can teach it how to turn them into Elisp code (in > the case of self-insert-command it should probably use `insert'). Yes, where adding a new optional argument is impossible, it's easy to record the right command. For instance, if `self-insert-command' needs to call `translate_char' to record the right translated character, then after the call to `translate_char' in `Fself_insert_command' we could replace the recorded useless command `(self-insert-command 1)' with the right command `(insert-char 1 65)': === modified file 'src/cmds.c' --- src/cmds.c 2010-05-25 09:36:21 +0000 +++ src/cmds.c 2010-06-08 08:04:05 +0000 @@ -365,3 +370,3 @@ int character = translate_char (Vtranslation_table_for_input, XINT (last_command_event)); + if (!NILP (current_kboard->defining_kbd_macro) && ! (minibuf_level > 0)) + XSETCAR (current_kboard->Vlast_kbd_macro_command_history, + Fcons (intern ("insert-char"), + Fcons (make_number (character), Fcons (n, Qnil)))); + if (XINT (n) >= 2 && NILP (current_buffer->overwrite_mode)) { XSETFASTINT (n, XFASTINT (n) - 2); > Of course, even better would be if the code run during macro recording > is the code generated (so if the behavior is different from the normal > command's behavior, you might see it during recording). We could later add an option to verify to macro during recording. -- Juri Linkov http://www.jurta.org/emacs/