* Convert an existing keyboard macro to elisp code? @ 2012-08-03 15:10 Thorsten Jolitz 2012-08-03 16:33 ` PJ Weisberg ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Thorsten Jolitz @ 2012-08-03 15:10 UTC (permalink / raw) To: help-gnu-emacs Hi List, I cite from the http://www.emacswiki.org/emacs/KeyboardMacrosTricks page, where somebody posted exactly the same question that came to my mind today: ,------------------------------------------------------------------- | Is there a way to convert an existing keyboard macro to elisp code? | | You can do this with M-x insert-kbd-macro but the result is | probably not to your liking. If I do: | | C-x ( | C-n | foo | C-x ) | M-x name-last-kbd-macro RET newline-and-foo | M-x insert-kbd-macro RET newline-and-foo RET | | emacs will insert the following into the buffer: | | (fset 'newline-and-foo | "\C-nfoo") | | I would very much like to be able to insert something like this: | | (defun newline-and-foo () | (interactive) | (next-line) | (insert "foo")) | | But it appears emacs does not have this feature. `------------------------------------------------------------------- Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE IT YOURSELF'). Since Emacs is a pretty dynamic project, I thought I give it another try on the mailing list - maybe this feature request has been implemented in the meantime by somebody? -- cheers, Thorsten ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-03 15:10 Convert an existing keyboard macro to elisp code? Thorsten Jolitz @ 2012-08-03 16:33 ` PJ Weisberg 2012-08-03 17:00 ` Yuri Khan ` (2 more replies) [not found] ` <mailman.6259.1344011630.855.help-gnu-emacs@gnu.org> 2012-08-04 16:51 ` Suvayu Ali 2 siblings, 3 replies; 8+ messages in thread From: PJ Weisberg @ 2012-08-03 16:33 UTC (permalink / raw) To: help-gnu-emacs On Fri, Aug 3, 2012 at 8:10 AM, Thorsten Jolitz <tjolitz@googlemail.com> wrote: > Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE > IT YOURSELF'). > > Since Emacs is a pretty dynamic project, I thought I give it another try > on the mailing list - maybe this feature request has been implemented in > the meantime by somebody? If it were just a matter of reading the key sequence and mapping it to functions it wouldn't be too bad, but the more I think about this, the more it seems like a rat hole. How would you translate (fset 'my-macro [?\M-x ?m ?a ?g tab ?i ?t tab ?s ?t tab ?t tab return ?m ?a tab return]) into (defun my-macro () (interactive) (magit-status "c:/Users/PJ/Documents/magit/")) ? You would need to know what auto-completion happened when the user pressed tab, and then you would need to know how the function translated its user input into interactive arguments. I don't think there's a way to do it without running the macro and (somehow) watching what happens. And that could have unpleasant side effects. And this particular example wouldn't even be portable, since when I type "M-x magit-status RET magit RET", Magit actually does some magic to translate that into a full path. So on my other machine, the proper definition of that macro would be (defun my-macro () (interactive) (magit-status "/home/pj/source-code/magit")) And that doesn't even take into account different keymaps. -PJ Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-03 16:33 ` PJ Weisberg @ 2012-08-03 17:00 ` Yuri Khan 2012-08-03 18:16 ` Thorsten Jolitz 2012-08-04 6:13 ` Andreas Röhler 2 siblings, 0 replies; 8+ messages in thread From: Yuri Khan @ 2012-08-03 17:00 UTC (permalink / raw) To: PJ Weisberg; +Cc: help-gnu-emacs On Fri, Aug 3, 2012 at 11:33 PM, PJ Weisberg <pj@irregularexpressions.net> wrote: > If it were just a matter of reading the key sequence and mapping it to > functions it wouldn't be too bad, but the more I think about this, the > more it seems like a rat hole. How would you translate > > (fset 'my-macro > [?\M-x ?m ?a ?g tab ?i ?t tab ?s ?t tab ?t tab return ?m ?a tab return]) Additionally, a macro may switch the currently active mode, e.g. by visiting a new file or switching windows/frames/buffers. The translating code won’t see it without actually executing the macro. No, this facility has to be in the core to be any effective. And, it works that way in (gasp!) Word and Excel, and I can say it is not at all always what is wanted. E.g. a dumb purely key-based macro can initiate a command that wants further user input and finish, leaving it up to the user to deal with that interactively. A smart macro, however, is incomplete until the user completes the additional input (e.g. by clicking OK in an Excel find-and-replace dialog) — as far as the macro recorder is concerned, you haven’t even started doing anything yet; if your intent was to open a dialog with a few fields pre-populated with some specific values, tough luck. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-03 16:33 ` PJ Weisberg 2012-08-03 17:00 ` Yuri Khan @ 2012-08-03 18:16 ` Thorsten Jolitz 2012-08-04 6:13 ` Andreas Röhler 2 siblings, 0 replies; 8+ messages in thread From: Thorsten Jolitz @ 2012-08-03 18:16 UTC (permalink / raw) To: help-gnu-emacs PJ Weisberg <pj@irregularexpressions.net> writes: > On Fri, Aug 3, 2012 at 8:10 AM, Thorsten Jolitz > <tjolitz@googlemail.com> wrote: > If it were just a matter of reading the key sequence and mapping it to > functions it wouldn't be too bad, but the more I think about this, the > more it seems like a rat hole. I guess you are right, unfortunately, if it were easy and feasable, such an opportunity to convert users into 'programmers' would probably not have been missed until now. But the idea has its charme, though. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-03 16:33 ` PJ Weisberg 2012-08-03 17:00 ` Yuri Khan 2012-08-03 18:16 ` Thorsten Jolitz @ 2012-08-04 6:13 ` Andreas Röhler 2 siblings, 0 replies; 8+ messages in thread From: Andreas Röhler @ 2012-08-04 6:13 UTC (permalink / raw) To: help-gnu-emacs Am 03.08.2012 18:33, schrieb PJ Weisberg: > On Fri, Aug 3, 2012 at 8:10 AM, Thorsten Jolitz <tjolitz@googlemail.com> wrote: >> Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE >> IT YOURSELF'). >> >> Since Emacs is a pretty dynamic project, I thought I give it another try >> on the mailing list - maybe this feature request has been implemented in >> the meantime by somebody? > > If it were just a matter of reading the key sequence and mapping it to > functions it wouldn't be too bad, but the more I think about this, the > more it seems like a rat hole. How would you translate > > (fset 'my-macro > [?\M-x ?m ?a ?g tab ?i ?t tab ?s ?t tab ?t tab return ?m ?a tab return]) > > into > > (defun my-macro () > (interactive) > (magit-status "c:/Users/PJ/Documents/magit/")) > > ? > > You would need to know what auto-completion happened when the user > pressed tab, and then you would need to know how the function > translated its user input into interactive arguments. I don't think > there's a way to do it without running the macro and (somehow) > watching what happens. And that could have unpleasant side effects. > > And this particular example wouldn't even be portable, since when I > type "M-x magit-status RET magit RET", Magit actually does some magic > to translate that into a full path. So on my other machine, the > proper definition of that macro would be > > (defun my-macro () > (interactive) > (magit-status "/home/pj/source-code/magit")) > > > And that doesn't even take into account different keymaps. > > -PJ > Hi, so you might get different code when calling from different circumstances. Which wouldn't hinder to notate a would-be-executed code from a point of interest. Basically IMHO such a thing is feasible. Andreas > Gehm's Corollary to Clark's Law: Any technology distinguishable from > magic is insufficiently advanced. > > ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.6259.1344011630.855.help-gnu-emacs@gnu.org>]
* Re: Convert an existing keyboard macro to elisp code? [not found] ` <mailman.6259.1344011630.855.help-gnu-emacs@gnu.org> @ 2012-08-04 9:48 ` Raffaele Ricciardi 2012-08-04 16:39 ` Thorsten Jolitz 0 siblings, 1 reply; 8+ messages in thread From: Raffaele Ricciardi @ 2012-08-04 9:48 UTC (permalink / raw) To: help-gnu-emacs On 08/03/2012 05:33 PM, PJ Weisberg wrote:> On Fri, Aug 3, 2012 at 8:10 AM, Thorsten Jolitz <tjolitz@googlemail.com> wrote: >> Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE >> IT YOURSELF'). >> >> Since Emacs is a pretty dynamic project, I thought I give it another try >> on the mailing list - maybe this feature request has been implemented in >> the meantime by somebody? > > If it were just a matter of reading the key sequence and mapping it to > functions it wouldn't be too bad, but the more I think about this, the > more it seems like a rat hole. How would you translate > > (fset 'my-macro > [?\M-x ?m ?a ?g tab ?i ?t tab ?s ?t tab ?t tab return ?m ?a tab return]) > > into > > (defun my-macro () > (interactive) > (magit-status "c:/Users/PJ/Documents/magit/")) > > ? > > You would need to know what auto-completion happened when the user > pressed tab, and then you would need to know how the function > translated its user input into interactive arguments. I don't think > there's a way to do it without running the macro and (somehow) > watching what happens. And that could have unpleasant side effects. > > And this particular example wouldn't even be portable, since when I > type "M-x magit-status RET magit RET", Magit actually does some magic > to translate that into a full path. So on my other machine, the > proper definition of that macro would be > > (defun my-macro () > (interactive) > (magit-status "/home/pj/source-code/magit")) > > > And that doesn't even take into account different keymaps. > > -PJ > > Gehm's Corollary to Clark's Law: Any technology distinguishable from > magic is insufficiently advanced. > Be stumped: C-h f command-history C-h v command-history Emacs already keeps track of commands that read input from terminal, I don't see the reason it couldn't keep track of all commands, as the third-party library mwe-log-commands.el does it, while discarding the arguments. Maybe Emacs does it already in some other variable I don't know. Regarding commands requiring further input and possibly performing conversions on their own, Emacs could feed them the same input you did. Of course, the resulting translation will be context-sensitive just like the original macro was. Adjustments to make the code portable would be up to the user. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-04 9:48 ` Raffaele Ricciardi @ 2012-08-04 16:39 ` Thorsten Jolitz 0 siblings, 0 replies; 8+ messages in thread From: Thorsten Jolitz @ 2012-08-04 16:39 UTC (permalink / raw) To: help-gnu-emacs Raffaele Ricciardi <rfflrccrd@gmail.com> writes: > Be stumped: > > C-h f command-history > C-h v command-history Thats quite helpfull, thanks. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Convert an existing keyboard macro to elisp code? 2012-08-03 15:10 Convert an existing keyboard macro to elisp code? Thorsten Jolitz 2012-08-03 16:33 ` PJ Weisberg [not found] ` <mailman.6259.1344011630.855.help-gnu-emacs@gnu.org> @ 2012-08-04 16:51 ` Suvayu Ali 2 siblings, 0 replies; 8+ messages in thread From: Suvayu Ali @ 2012-08-04 16:51 UTC (permalink / raw) To: help-gnu-emacs On Fri, Aug 03, 2012 at 05:10:42PM +0200, Thorsten Jolitz wrote: > > Unfortunately, the answer was more a less a 'NO'(or 'YOU HAVE TO WRITE > IT YOURSELF'). > You can always name the macro and save the lisp as a command in your init file. M-x kmacro-name-last-macro RET <somename> M-x insert-kbd-macro RET <abovename> HTH -- Suvayu Open source is the future. It sets us free. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-08-04 16:51 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-08-03 15:10 Convert an existing keyboard macro to elisp code? Thorsten Jolitz 2012-08-03 16:33 ` PJ Weisberg 2012-08-03 17:00 ` Yuri Khan 2012-08-03 18:16 ` Thorsten Jolitz 2012-08-04 6:13 ` Andreas Röhler [not found] ` <mailman.6259.1344011630.855.help-gnu-emacs@gnu.org> 2012-08-04 9:48 ` Raffaele Ricciardi 2012-08-04 16:39 ` Thorsten Jolitz 2012-08-04 16:51 ` Suvayu Ali
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).