help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Re: How to get keyboard macro that was just run?


From: Okamsn
Subject: Re: [External] : Re: How to get keyboard macro that was just run?
Date: Sat, 01 Jul 2023 21:07:14 +0000

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]