* How to get keyboard macro that was just run? @ 2023-06-18 14:28 Okamsn 2023-06-18 15:53 ` Eduardo Ochs 0 siblings, 1 reply; 7+ messages in thread From: Okamsn @ 2023-06-18 14:28 UTC (permalink / raw) To: help-gnu-emacs Hello, The package Meow has commands to play back a keyboard macro at multiple locations, but these commands are limited to running the last defined keyboard macro. I am wondering whether there is a way that it could play back the keyboard macro that was just run for the other locations by hooking into or advising some feature. My hope is that it would then be able to work automatically with commands like `consult-kmacro`, which allows one to run a keyboard macro by selecting it using completion, without first having to rotate the `kmacro-ring`. I have tried checking the value of `executing-kbd-macro` in `kbd-macro-termination-hook`, but the value was nil. Does Emacs make this information available? Thank you. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to get keyboard macro that was just run? 2023-06-18 14:28 How to get keyboard macro that was just run? Okamsn @ 2023-06-18 15:53 ` Eduardo Ochs 2023-06-18 17:05 ` Okamsn 0 siblings, 1 reply; 7+ messages in thread From: Eduardo Ochs @ 2023-06-18 15:53 UTC (permalink / raw) To: Okamsn; +Cc: help-gnu-emacs Hi Okamsn, try to run this with C-x C-e: (insert (format "\n\%S\n" `(setq last-kbd-macro (kbd ,(format-kbd-macro last-kbd-macro))))) it's roughly the trick that I use to save and edit keyboard macros, but stripped out of all the cruft... Cheers, Eduardo Ochs http://anggtwu.net/#eev On Sun, 18 Jun 2023 at 11:30, Okamsn <okamsn@protonmail.com> wrote: > > Hello, > > The package Meow has commands to play back a keyboard macro at multiple > locations, but these commands are limited to running the last defined > keyboard macro. > > I am wondering whether there is a way that it could play back the > keyboard macro that was just run for the other locations by hooking into > or advising some feature. My hope is that it would then be able to work > automatically with commands like `consult-kmacro`, which allows one to > run a keyboard macro by selecting it using completion, without first > having to rotate the `kmacro-ring`. > > I have tried checking the value of `executing-kbd-macro` in > `kbd-macro-termination-hook`, but the value was nil. > > Does Emacs make this information available? > > Thank you. > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to get keyboard macro that was just run? 2023-06-18 15:53 ` Eduardo Ochs @ 2023-06-18 17:05 ` Okamsn 2023-06-18 17:13 ` [External] : " Drew Adams 2023-06-18 17:13 ` Okamsn 0 siblings, 2 replies; 7+ messages in thread From: Okamsn @ 2023-06-18 17:05 UTC (permalink / raw) To: Eduardo Ochs; +Cc: help-gnu-emacs On 2023-06-18 15:53 UTC, Eduardo Ochs wrote: > Hi Okamsn, > try to run this with C-x C-e: > > (insert (format "\n\%S\n" > `(setq last-kbd-macro (kbd ,(format-kbd-macro last-kbd-macro))))) > > it's roughly the trick that I use to save and edit keyboard macros, > but stripped out of all the cruft... > Cheers, > Eduardo Ochs > http://anggtwu.net/#eev Thank you for the response. I know that the variable `last-kbd-macro` contains the last keyboard macro that was defined, but I am interested in programmatically knowing the last keyboard macro that was run, just after it is run. For example, `consult-kmacro` selects a keyboard macro from `kmacro-ring`, converts that macro to a function, and then runs function. In this way, it does not change the value of `last-kbd-macro`, as far as I'm aware. ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [External] : Re: How to get keyboard macro that was just run? 2023-06-18 17:05 ` Okamsn @ 2023-06-18 17:13 ` Drew Adams 2023-06-18 17:50 ` Okamsn 2023-06-18 17:13 ` Okamsn 1 sibling, 1 reply; 7+ messages in thread From: Drew Adams @ 2023-06-18 17:13 UTC (permalink / raw) To: Okamsn, Eduardo Ochs; +Cc: help-gnu-emacs@gnu.org I may be misunderstanding, but is there a reason you don't just name the keyboard macro you want to reuse multiple times? ___ kmacro-name-last-macro is an interactive compiled Lisp function in ‘kmacro.el’. It is bound to C-x C-k n. (kmacro-name-last-macro SYMBOL) For more information see the manuals. Assign a name to the last keyboard macro defined. Argument SYMBOL is the name to define. The symbol's function definition becomes the keyboard macro string. Such a "function" cannot be called from Lisp, but it is a valid editor command. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [External] : Re: How to get keyboard macro that was just run? 2023-06-18 17:13 ` [External] : " Drew Adams @ 2023-06-18 17:50 ` Okamsn 2023-07-01 21:07 ` Okamsn 0 siblings, 1 reply; 7+ messages in thread From: Okamsn @ 2023-06-18 17:50 UTC (permalink / raw) To: Drew Adams, Eduardo Ochs; +Cc: help-gnu-emacs@gnu.org On 2023-06-18 17:13 UTC, Drew Adams wrote: > I may be misunderstanding, but is there a > reason you don't just name the keyboard > macro you want to reuse multiple times? > ___ > > kmacro-name-last-macro is an interactive compiled Lisp function in > ‘kmacro.el’. > > It is bound to C-x C-k n. > > (kmacro-name-last-macro SYMBOL) > > For more information see the manuals. > > Assign a name to the last keyboard macro defined. > Argument SYMBOL is the name to define. > The symbol's function definition becomes the keyboard macro string. > Such a "function" cannot be called from Lisp, but it is a valid editor command. Hello Drew, I will try to explain in more detail. In the package Meow, there is a feature to play easily keyboard macros at multiple locations. It does this by running the most recently defined keyboard macro at point using `execute-kbd-macro` and then running the command again at each of the other locations. That feature is described here: https://github.com/meow-edit/meow/blob/master/EXPLANATION.org#multiedit I think that this is an interesting idea, but it is currently limited to running the macro in `last-kbd-macro`. In Consult, there exists the command `consult-kmacro`, which can be used to easily and quickly run kmacros that are not in `last-kbd-macro`. This is better for using a kmacro that I defined a while ago and now wish to use again, without having to first find it by cycling the kmacro ring (and then maybe naming it if I think I will want to use it more frequently next, as you suggest). `consult-kmacro` is easier for one-off-ish re-uses. I proposed changes to `consult-kmacro` that would make it easier to advise for use with Meow's "beacons" (https://github.com/minad/consult/pull/813). However, Consult's author wanted to know whether this integration could happen without making changes in Consult. For that, I am here asking whether it is possible to get information about a kmacro that was just run, so that I could feed that information to Meow for running at its "beacons". If possible, I am still not sure whether that would be the right path forward, because Meow also uses kmacros to run commands bound to the conventional keys, such as `C-w` for cutting commands. So, I suspect that advising `execute-kbd-macro` would be too much and break things. Right now, though, I am just trying to find if there is a better way to get the info about the kmacro. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [External] : Re: How to get keyboard macro that was just run? 2023-06-18 17:50 ` Okamsn @ 2023-07-01 21:07 ` Okamsn 0 siblings, 0 replies; 7+ messages in thread From: Okamsn @ 2023-07-01 21:07 UTC (permalink / raw) Cc: help-gnu-emacs@gnu.org On 2023-06-18 17:50 UTC, Okamsn wrote: > On 2023-06-18 17:13 UTC, Drew Adams wrote: >> I may be misunderstanding, but is there a >> reason you don't just name the keyboard >> macro you want to reuse multiple times? >> ___ >> >> kmacro-name-last-macro is an interactive compiled Lisp function in >> ‘kmacro.el’. >> >> It is bound to C-x C-k n. >> >> (kmacro-name-last-macro SYMBOL) >> >> For more information see the manuals. >> >> Assign a name to the last keyboard macro defined. >> Argument SYMBOL is the name to define. >> The symbol's function definition becomes the keyboard macro string. >> Such a "function" cannot be called from Lisp, but it is a valid editor command. > > Hello Drew, > > I will try to explain in more detail. > > In the package Meow, there is a feature to play easily keyboard macros > at multiple locations. It does this by running the most recently defined > keyboard macro at point using `execute-kbd-macro` and then running the > command again at each of the other locations. > > That feature is described here: > https://github.com/meow-edit/meow/blob/master/EXPLANATION.org#multiedit > > I think that this is an interesting idea, but it is currently limited to > running the macro in `last-kbd-macro`. > > In Consult, there exists the command `consult-kmacro`, which can be used > to easily and quickly run kmacros that are not in `last-kbd-macro`. This > is better for using a kmacro that I defined a while ago and now wish to > use again, without having to first find it by cycling the kmacro ring > (and then maybe naming it if I think I will want to use it more > frequently next, as you suggest). `consult-kmacro` is easier for > one-off-ish re-uses. > > I proposed changes to `consult-kmacro` that would make it easier to > advise for use with Meow's "beacons" > (https://github.com/minad/consult/pull/813). However, Consult's author > wanted to know whether this integration could happen without making > changes in Consult. > > For that, I am here asking whether it is possible to get information > about a kmacro that was just run, so that I could feed that information > to Meow for running at its "beacons". > > If possible, I am still not sure whether that would be the right path > forward, because Meow also uses kmacros to run commands bound to the > conventional keys, such as `C-w` for cutting commands. So, I suspect > that advising `execute-kbd-macro` would be too much and break things. > Right now, though, I am just trying to find if there is a better way to > get the info about the kmacro. > > > For the record, the creator of Consult recommended using the `:state` setting in `consult-customize`, which if a function that, among other things, receives the selected candidate. This is what I am using: (consult-customize consult-kmacro :state (lambda (action cand) (when (and (eq action 'return) cand (meow-beacon-mode-p)) (run-at-time 0 nil (lambda () (with-undo-amalgamate ;; Following `meow-beacon-apply-kmacro'. (meow--switch-state 'normal) (let ((arg current-prefix-arg)) (funcall cand arg) (meow--beacon-apply-command (lambda () (interactive) (funcall cand arg)))) (meow--switch-state 'beacon)))) (signal 'quit nil)))) This is not as general, but it works well for my case. Thank you for the suggestions. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to get keyboard macro that was just run? 2023-06-18 17:05 ` Okamsn 2023-06-18 17:13 ` [External] : " Drew Adams @ 2023-06-18 17:13 ` Okamsn 1 sibling, 0 replies; 7+ messages in thread From: Okamsn @ 2023-06-18 17:13 UTC (permalink / raw) To: Eduardo Ochs; +Cc: help-gnu-emacs On 2023-06-18 17:05 UTC, Okamsn wrote: > On 2023-06-18 15:53 UTC, Eduardo Ochs wrote: >> Hi Okamsn, >> try to run this with C-x C-e: >> >> (insert (format "\n\%S\n" >> `(setq last-kbd-macro (kbd ,(format-kbd-macro last-kbd-macro))))) >> >> it's roughly the trick that I use to save and edit keyboard macros, >> but stripped out of all the cruft... >> Cheers, >> Eduardo Ochs >> http://anggtwu.net/#eev > > Thank you for the response. I know that the variable `last-kbd-macro` > contains the last keyboard macro that was defined, but I am interested > in programmatically knowing the last keyboard macro that was run, just > after it is run. > > For example, `consult-kmacro` selects a keyboard macro from > `kmacro-ring`, converts that macro to a function, and then runs > function. In this way, it does not change the value of `last-kbd-macro`, > as far as I'm aware. > > I realize now that the problem is more complicated than I first thought, because Meow also uses keyboard macros in other ways, so just advising `execute-kbd-macro` would affect things indiscriminately. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-07-01 21:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-06-18 14:28 How to get keyboard macro that was just run? Okamsn 2023-06-18 15:53 ` Eduardo Ochs 2023-06-18 17:05 ` Okamsn 2023-06-18 17:13 ` [External] : " Drew Adams 2023-06-18 17:50 ` Okamsn 2023-07-01 21:07 ` Okamsn 2023-06-18 17:13 ` Okamsn
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).