all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Convert a keyboard macro to equivalent Lisp code
Date: Tue, 08 Jun 2010 11:05:32 +0300	[thread overview]
Message-ID: <87iq5uuemn.fsf@mail.jurta.org> (raw)
In-Reply-To: <jwvd3w2boak.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 07 Jun 2010 16:11:39 -0400")

>> 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/



  reply	other threads:[~2010-06-08  8:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-05 19:57 Convert a keyboard macro to equivalent Lisp code Juri Linkov
2010-06-07  9:27 ` Richard Stallman
2010-06-07  9:27 ` Richard Stallman
2010-06-07 13:36   ` Stefan Monnier
2010-06-07 18:33   ` Juri Linkov
2010-06-07 18:35 ` Juri Linkov
2010-06-07 20:11   ` Stefan Monnier
2010-06-08  8:05     ` Juri Linkov [this message]
2010-06-09  1:36       ` Stefan Monnier
2010-06-09  8:34         ` Juri Linkov
2010-06-09 14:17           ` Stefan Monnier

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=87iq5uuemn.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.