From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: yzhh Newsgroups: gmane.emacs.devel Subject: Re: Is there a plan to record kbd macro as elisp code? Date: Sun, 28 Oct 2007 06:49:13 +0000 (UTC) Message-ID: References: <87y7doxmcw.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1193554178 9509 80.91.229.12 (28 Oct 2007 06:49:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 28 Oct 2007 06:49:38 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 28 07:49:40 2007 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.50) id 1Im1xr-0008T0-NV for ged-emacs-devel@m.gmane.org; Sun, 28 Oct 2007 07:49:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Im1xi-00022r-M4 for ged-emacs-devel@m.gmane.org; Sun, 28 Oct 2007 02:49:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Im1xe-00020W-Pf for emacs-devel@gnu.org; Sun, 28 Oct 2007 02:49:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Im1xd-0001xQ-9o for emacs-devel@gnu.org; Sun, 28 Oct 2007 02:49:26 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Im1xc-0001x6-Up for emacs-devel@gnu.org; Sun, 28 Oct 2007 02:49:25 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Im1xc-0004OG-MN for emacs-devel@gnu.org; Sun, 28 Oct 2007 02:49:24 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Im1xa-000331-Su for emacs-devel@gnu.org; Sun, 28 Oct 2007 02:49:23 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Im1xX-0007iI-IB for emacs-devel@gnu.org; Sun, 28 Oct 2007 06:49:19 +0000 Original-Received: from 211.90.238.185 ([211.90.238.185]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Oct 2007 06:49:19 +0000 Original-Received: from yezonghui by 211.90.238.185 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Oct 2007 06:49:19 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: main.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 211.90.238.185 (Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-0etch1+lenny1)) X-detected-kernel: by mx20.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-detected-kernel: by monty-python.gnu.org: 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:81918 Archived-At: Juri Linkov jurta.org> writes: > > I think what was expected was to first record a keyboard macro and later to > > turn that into elisp code. > > That's was exactly my first attempt when I tried to implement this feature. > However, this approach doesn't work because a macro highly depends on its > context, and will fail when repeating it in different buffers, modes, etc. I agree. Keymap changes caused by mode/buffer changes DURING the recording can messup the "translation". So I didn't try this in the first place :) > > Another approach is to use a pre-command-hook to record the value of > > `this-command' for each command run. > > After failing with the first approach, I tried to do this, but this doesn't > work because `this-command' doesn't record the arguments of the last > command. So when I added a new variable `this-command-args' that records > the arguments of the command being executed, this approach produced > good results. > > Also I added a new variable `last-kbd-macro-commands', and a new command > `insert-last-kbd-macro-commands' to convert the recorded commands with > their arguments to a Lisp function. A change in isearch was also required > to convert all isearch subcommands into one search function. This approach looks quite promising. I vote for this. > Since yzhh doesn't want to post his code, I will post mine. > I ask yzhh to comment on this code, compare with his own, > and suggest further improvements: Great work Juri! I'm actually busy on work these days. As soon as I have time I'll investigate your code and give any suggestion I can. Hope this will progress into something in the emacs CVS. And inspired by you and others, I post my code here. Basically, I did these: Add a variable (V)kbd-macro-command-history, insert commands into it on ervey ocurrence of possible insertion into command-history (that's guarded by record_flag), when defining-kbd-macro is on. So it's not complete. You have to M-x eval-expression kbd-macro-command-history to see the recorded thing, in reverse order. And its length is guarded by history-length. regards, yzhh