From: storm@cua.dk (Kim F. Storm)
To: rms@gnu.org
Cc: yezonghui@gmail.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: Is there a plan to record kbd macro as elisp code?
Date: Sun, 28 Oct 2007 23:00:52 +0100 [thread overview]
Message-ID: <87ve8qyk4r.fsf@kfs-lx.testafd.dk> (raw)
In-Reply-To: <E1Im8XJ-0000uK-CL@fencepost.gnu.org> (Richard Stallman's message of "Sun\, 28 Oct 2007 09\:50\:41 -0400")
Richard Stallman <rms@gnu.org> writes:
> Which reminds me that there is a big difference between replaying a keyboard
> macro and running the corresponding functions as a single command:
>
> - the pre-command-hook and post-command-hook are run for each key in
> the keyboard macro, but only once for the single command.
>
> This doesn't mean that the elisp code cannot be equivalent to the keyboard
> macro, but it may be much harder to do right.
>
> There are various ideas of what is "right" for such a conversion.
> I think the converted code should ignore these hooks, and if the
> results are different, in most cases that will make sense.
Maybe, but there are many things that can go wrong...
Perhaps some of the work could be done by analyzing the undo
history ...
> Delete Selection mode is an exception. In Delete Selection mode,
> if these hooks are not run, the results will clearly be wrong.
> The same may be true of CUA mode.
It is even more complex I think:
With CUA mode, the interpretation of C-x and C-c depends on
whether the region is active or not. That is not done through
pre-command-hook (but setting/extending the region is), but rather
through the keymaps which are active at the time.
> The conversion program could test for the presence of these specific
> hook functions in pre-command-hook, and generate appropriate code in
> the output Lisp function.
This will only work if the conversion is done while recording the
keyboard macro - as one keystroke may modify the hooks.
> Rather than calling these hook functions
> before each command, it should call them only in the places where they
> would do real work. And it wouldn't call the same function, but
> rather a related one. Here's what it could look like:
>
> (put 'delete-selection-pre-hook 'lisp-conversion-function
> (lambda (function)
> (let ((type (and (symbolp this-command)
> (get this-command 'delete-selection))))
> (when type
> `(delete-selection-pre-command-processing ,type)))))
>
> where `delete-selection-pre-command-processing' would be
> a new function that does the same work as `delete-selection-pre-hook'
> but gets `type' as an argument.
That might work.
IMO, the only real solution is to record the elisp code while recording
the keyboard macro - as it is possible to cather for changes in
the mark-active state and insert suitable set-mark commands etc.
Still, I fail to see the real need for the functionality.
It may be ok as a way to get a starting point for an editing command,
but only very trivial functions can be written that way anyway - and
they are just as well written and saved as a series of keystrokes as
they do now.
--
Kim F. Storm <storm@cua.dk> http://www.cua.dk
next prev parent reply other threads:[~2007-10-28 22:00 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 [this message]
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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ve8qyk4r.fsf@kfs-lx.testafd.dk \
--to=storm@cua.dk \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=rms@gnu.org \
--cc=yezonghui@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).