0

What I want is an easy-to-use hydra for macro execution. Typically I execute a keyboard macro a few times (e), and then might want to repeat infinitely until the end of a buffer (u). Sometimes I need to search forward or backward before continuing with keyboard macro execution.

What I have is a steaming pile of not-quite-working whats-it.

I have to use foreign-keys to search. This seems wrong. Without foreign keys the searches don't accept any input. Even with, if my search term contains a hydra key, then it does that instead.

I must be doing something wrong. Please help!

(defhydra hydra-keyboard-macros (:columns 6 :foreign-keys run)
  ("e" kmacro-end-or-call-macro-repeat "execute")
  ("u" (lambda()
         (interactive)
         (let ((current-prefix-arg 0))
           (call-interactively #'kmacro-end-or-call-macro)))
   "unlimited")
  ("s" isearch-forward-regexp "search")
  ("r" isearch-backward-regexp "reverse")
  ("'" edit-last-kbd-macro "edit")
  ("q" nil "quit"))

(global-set-key (kbd "C-x e") #'hydra-keyboard-macros/kmacro-end-or-call-macro-repeat)
1

Maybe something like this will do what you want:

(defhydra hydra-keyboard-macros (:columns 6 :foreign-keys run)
  ("e" kmacro-end-or-call-macro-repeat "execute")
  ("u" (lambda()
         (interactive)
         (let ((current-prefix-arg 0))
           (call-interactively #'kmacro-end-or-call-macro)))
   "unlimited")
  ("s" (lambda ()
    (interactive)
    (isearch-forward-regexp)
    (hydra-keyboard-macros/body))  "search" :color blue)
  ("r" (lambda ()
     (interactive)
     (isearch-backward-regexp)
     (hydra-keyboard-macros/body))  "reverse" :color blue)
  ("'" edit-last-kbd-macro "edit")
  ("q" nil "quit"))

the blue head exits the hydra, and then the last command re-enters it after searching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.