emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/helm 0a91c4c799 2/2: Add new action to kmacro source


From: ELPA Syncer
Subject: [nongnu] elpa/helm 0a91c4c799 2/2: Add new action to kmacro source
Date: Sat, 20 May 2023 05:00:01 -0400 (EDT)

branch: elpa/helm
commit 0a91c4c7993e30536e016160e5ed941b185c4857
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>

    Add new action to kmacro source
---
 helm-ring.el | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/helm-ring.el b/helm-ring.el
index 924c67608b..56d67f587c 100644
--- a/helm-ring.el
+++ b/helm-ring.el
@@ -550,15 +550,44 @@ See (info \"(emacs) Keyboard Macros\") for detailed 
infos."
              "Delete marked macros"
              'helm-kbd-macro-delete-macro
              "Edit marked macro"
-             'helm-kbd-macro-edit-macro)
+             'helm-kbd-macro-edit-macro
+             "Insert kbd macro"
+             'helm-kbd-macro-insert-macro)
             :group 'helm-ring)
           :buffer "*helm kmacro*")))
 
-(defun helm-kbd-macro-execute (candidate)
-  ;; Move candidate on top of list for next use.
+(defun helm-kbd-macro-make-current (candidate)
+  "Make CANDIDATE macro the current one."
   (setq kmacro-ring (delete candidate kmacro-ring))
   (kmacro-push-ring)
-  (kmacro-split-ring-element candidate)
+  (kmacro-split-ring-element candidate))
+
+(defun helm-kbd-macro-insert-macro (candidate)
+  "Insert macro at point in `helm-current-buffer'."
+  (let ((desc (read-string "Describe macro briefly: "))
+        name key)
+    (while (fboundp (setq name (intern (read-string "New name for macro: "))))
+      (message "Symbol `%s' already exists, choose another name" name)
+      (sit-for 1.5))
+    (helm-kbd-macro-make-current candidate)
+    (kmacro-name-last-macro name)
+    (when (y-or-n-p "Bind macro to a new key?")
+      (helm-awhile (key-binding
+                    (setq key (read-key-sequence-vector "Bind macro to key: 
")))
+        (message "`%s' already run command `%s', choose another one"
+                 (help-key-description key nil) it)
+        (sit-for 1.5))
+      (global-set-key key name))
+    (with-helm-current-buffer
+      (insert (format ";; %s%s\n"
+                      desc
+                      (and key (format " (bound to `%s')"
+                                       (help-key-description key nil)))))
+      (insert-kbd-macro name (not (null key))))))
+
+(defun helm-kbd-macro-execute (candidate)
+  ;; Move candidate on top of list for next use.
+  (helm-kbd-macro-make-current candidate)
   (kmacro-exec-ring-item
    candidate helm-current-prefix-arg))
 



reply via email to

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