all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Okamsn <okamsn@protonmail.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: [External] : Re: How to get keyboard macro that was just run?
Date: Sat, 01 Jul 2023 21:07:14 +0000	[thread overview]
Message-ID: <8a4ff699-00ee-1b52-bca8-9c6da882e4fe@protonmail.com> (raw)
In-Reply-To: <8bfaa1c7-ddbf-f17e-bf58-a14509d9345e@protonmail.com>

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	other threads:[~2023-07-01 21:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2023-06-18 17:13     ` Okamsn

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a4ff699-00ee-1b52-bca8-9c6da882e4fe@protonmail.com \
    --to=okamsn@protonmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.