all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: yzhh <yezonghui@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Is there a plan to record kbd macro as elisp code?
Date: Sun, 28 Oct 2007 06:49:13 +0000 (UTC)	[thread overview]
Message-ID: <loom.20071028T062307-553@post.gmane.org> (raw)
In-Reply-To: 87y7doxmcw.fsf@jurta.org

Juri Linkov <juri <at> 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

  parent reply	other threads:[~2007-10-28  6:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-27  9:28 Is there a plan to record kbd macro as elisp code? yzhh
2007-10-27 15:48 ` Robert J. Chassell
2007-10-27 17:30   ` yzhh
2007-10-27 18:01     ` Drew Adams
2007-10-28 13:50       ` Richard Stallman
2007-10-27 20:04     ` Stefan Monnier
2007-10-27 21:22       ` Kim F. Storm
2007-10-28 13:50         ` Richard Stallman
2007-10-28 22:00           ` Kim F. Storm
2007-10-29  5:20             ` yzhh
2007-10-29  9:22             ` Richard Stallman
2007-10-29  9:22             ` Richard Stallman
2007-10-27 21:45       ` Juri Linkov
2007-10-28  1:14         ` Stefan Monnier
2007-10-28  1:34           ` Juri Linkov
2007-10-29  0:11             ` Richard Stallman
2007-10-28  6:49         ` yzhh [this message]
2007-10-28  7:13           ` yzhh
2007-10-28 10:54           ` Juri Linkov
2007-10-28 13:50         ` Richard Stallman
2007-10-28 15:09           ` Juri Linkov
2007-10-29  9:21             ` Richard Stallman
2007-10-28 16:13           ` yzhh
2007-10-28 16:48             ` Juri Linkov
2007-10-29  9:21             ` Richard Stallman
2007-10-30 14:14               ` Juri Linkov
2007-10-31  7:46                 ` Richard Stallman
2007-10-27 19:26   ` Jay Belanger
2007-10-27 16:20 ` Drew Adams
2007-10-27 17:13   ` yzhh
2007-10-27 17:40     ` Drew Adams
2007-10-27 18:05       ` yzhh
2007-10-27 19:22       ` Robert J. Chassell
2007-10-27 20:11         ` Drew Adams
2007-10-28 13:50   ` Richard Stallman
2007-10-28 16:45     ` Juri Linkov
2007-10-29  6:41 ` Klaus Zeitler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20071028T062307-553@post.gmane.org \
    --to=yezonghui@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.