unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Recording a macro that preserves timing
@ 2012-10-04 10:21 Juha Nieminen
  2012-10-04 11:50 ` Doug Lewan
  2012-10-04 13:33 ` Stefan Monnier
  0 siblings, 2 replies; 3+ messages in thread
From: Juha Nieminen @ 2012-10-04 10:21 UTC (permalink / raw)
  To: help-gnu-emacs

I can record (and then replay) keyboard macros in emacs. However, I would
like a variant that also records the timing between the keypresses so
that when it's played back, it does the exact same thing as when recording,
with the same timing.

Then I would like to be able to play said macro with a speed factor. In
other words, I would like to be able to multiply all the recorded timings
by a value (so that if I multiply them eg. by 0.5 the macro will play at
twice the original speed).

If possible, it would be nice if this macro could be saved to a file
where it could be edited by hand (to eg. add or modify timings). In fact,
it would be really great if it was saved in a format that would allow
defining different factors for different groups of recorded keypresses
(so that by editing the file I could define "this part should be played
back with a factor of 0.5, this part with a factor of 0.2, etc.")

How difficult would such elisp code be to make?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Recording a macro that preserves timing
  2012-10-04 10:21 Recording a macro that preserves timing Juha Nieminen
@ 2012-10-04 11:50 ` Doug Lewan
  2012-10-04 13:33 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Lewan @ 2012-10-04 11:50 UTC (permalink / raw)
  To: Juha Nieminen, help-gnu-emacs@gnu.org

Juha,

On occasion I've wanted such a thing too, but never looked into it.

From the emacs lisp Info on "Keyboard Macros", their definition is controlled by the variable defining-kbd-macro which comes from the C code. So, that would be the place to look.

I find it (defining_kbd_macro in C) in keyboard.c and macros.c. It only appears 18 times, so it shouldn't be *too* hard to copy or mimic or modify to meet your needs. You'd also have to consider doing corresponding work with kmacro.el (and maybe other places too).

With respect to editing: "C-x C-k e runs the command edit-kbd-macro,...."

You can save that definition and do whatever you need to with it. Indeed, the annotations in the keyboard macro editor generally give enough good hints that you could convert it into LISP, which would let you do very general programming with it.

I hope this helps.

,Doug

Afterthought: By "*too* hard" I mean that I'm guessing it would take under a week of full time development. It might be a few hours, but I've never touched emacs' C code. 
I didn't see anything like this in the emacs TODO list. Perhaps you could make a feature request to bug-gnu-emacs@gnu.org.

> -----Original Message-----
> From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org
> [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On
> Behalf Of Juha Nieminen
> Sent: Thursday, 2012 October 04 06:22
> To: help-gnu-emacs@gnu.org
> Subject: Recording a macro that preserves timing
> 
> I can record (and then replay) keyboard macros in emacs. However, I
> would
> like a variant that also records the timing between the keypresses so
> that when it's played back, it does the exact same thing as when
> recording,
> with the same timing.
> 
> Then I would like to be able to play said macro with a speed factor. In
> other words, I would like to be able to multiply all the recorded
> timings
> by a value (so that if I multiply them eg. by 0.5 the macro will play
> at
> twice the original speed).
> 
> If possible, it would be nice if this macro could be saved to a file
> where it could be edited by hand (to eg. add or modify timings). In
> fact,
> it would be really great if it was saved in a format that would allow
> defining different factors for different groups of recorded keypresses
> (so that by editing the file I could define "this part should be played
> back with a factor of 0.5, this part with a factor of 0.2, etc.")
> 
> How difficult would such elisp code be to make?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Recording a macro that preserves timing
  2012-10-04 10:21 Recording a macro that preserves timing Juha Nieminen
  2012-10-04 11:50 ` Doug Lewan
@ 2012-10-04 13:33 ` Stefan Monnier
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2012-10-04 13:33 UTC (permalink / raw)
  To: help-gnu-emacs

> How difficult would such elisp code be to make?

Not sure.  I'd recommend you look at kmacro.el.
I'd suggest you change kmacro-start-macro to add a pre-command-hook that
records the time of every command, and then in kmacro-end-macro record
those timings alongside the actual macro.

Maybe you could combine the two into a normal macro, but this requires
some trick because macros contain sequences of *events* (like
key-presses) rather than commands, so you can't directly add code
into them.
But you could use a special `macro-wait' event, and add a binding for it
in the global-map.

Otherwise, you'll need to write a new function to run your macros.


        Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-04 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-04 10:21 Recording a macro that preserves timing Juha Nieminen
2012-10-04 11:50 ` Doug Lewan
2012-10-04 13:33 ` Stefan Monnier

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).