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

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

[elpa] externals/ivy-hydra d18ec97 338/395: counsel.el (compile-command)


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra d18ec97 338/395: counsel.el (compile-command): better handle our metadata
Date: Thu, 25 Feb 2021 08:32:33 -0500 (EST)

branch: externals/ivy-hydra
commit d18ec97cbdceacda84c30ba7cbda39d594cd79bd
Author: Alex Bennée <alex.bennee@linaro.org>
Commit: Alex Bennée <alex.bennee@linaro.org>

    counsel.el (compile-command): better handle our metadata
    
    Editing compile commands (for example to add env variables) is a bit
    fiddly, especially for one offs. Override the default ivy behaviour
    for M-i with a counsel-compile aware version of ivy-insert-current
    that knows how to handle the metadata in the properties.
---
 counsel.el | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/counsel.el b/counsel.el
index 0b23abc..687de60 100644
--- a/counsel.el
+++ b/counsel.el
@@ -6502,9 +6502,35 @@ specified by the `blddir' property."
              (compile cmd)
           (remove-hook 'compilation-start-hook 
#'counsel-compile--update-history))))))
 
+(defun counsel-compile-edit-command ()
+  "Insert current compile command into mini-buffer for editing.
+
+This mirrors the behaviour of `ivy-insert-current' but with specific
+handling for the counsel-compile metadata."
+  (interactive)
+  (delete-minibuffer-contents)
+  (let* ((cmd (ivy-state-current ivy-last))
+         (blddir (get-text-property 0 'blddir cmd)))
+    (when blddir
+      (setq counsel-compile--current-build-dir blddir))
+    (if (get-char-property 0 'cmd cmd)
+        (insert (substring-no-properties
+                 cmd 0 (next-single-property-change 0 'cmd cmd)))
+      (substring-no-properties last 0 end))))
+
+;; Currently the only thing we do is override ivy's default insert
+;; operation which doesn't include the metadata we want.
+(defvar counsel-compile-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "M-i") #'counsel-compile-edit-command)
+    map)
+  "Additional ivy keybindings during command selection")
+
 ;;;###autoload
 (defun counsel-compile (&optional dir)
-  "Call `compile' completing with smart suggestions, optionally for DIR."
+  "Call `compile' completing with smart suggestions, optionally for DIR.
+
+Additional actions:\\<ivy-minibuffer-map>"
   (interactive)
   (setq counsel-compile--current-build-dir (or dir
                                                (counsel--compile-root)
@@ -6512,6 +6538,7 @@ specified by the `blddir' property."
   (ivy-read "Compile command: "
             (delete-dups (counsel--get-compile-candidates dir))
             :action #'counsel-compile--action
+            :keymap counsel-compile-map
             :caller 'counsel-compile))
 
 (ivy-add-actions



reply via email to

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