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

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

[elpa] master 6de6233 205/399: counsel.el (counsel-compile): New counsel


From: Oleh Krehel
Subject: [elpa] master 6de6233 205/399: counsel.el (counsel-compile): New counsel-compile-env helper
Date: Sat, 20 Jul 2019 14:57:24 -0400 (EDT)

branch: master
commit 6de6233995790f2a8dd53e0f68547e33e5c618bb
Author: Alex Bennée <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-compile): New counsel-compile-env helper
    
    This helper allows us to tweak counsel-compile-env. We don't use
    separate actions. We either add the environment variable if it doesn't
    already exist or remove it if it does.
    
    There is scope for better validation and dealing with setting ARCH=foo
    when we have ARCH=bar in the environment already.
---
 counsel.el | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/counsel.el b/counsel.el
index 3a6a991..0e16137 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5256,6 +5256,9 @@ Each element should be a string of the form 
ENVVARNAME=VALUE.  This
 list is passed to `compilation-environment'."
   :type '(repeat (string :tag "ENVVARNAME=VALUE")))
 
+(defvar counsel-compile-env-history nil
+  "History for `counsel-compile-env'.")
+
 (defcustom counsel-compile-make-pattern "\\`\\(?:GNUm\\|[Mm]\\)akefile\\'"
   "Regexp for matching the names of Makefiles."
   :type 'regexp)
@@ -5438,6 +5441,40 @@ specified by the `blddir' property."
             :action #'counsel-compile--action
             :caller 'counsel-compile))
 
+
+(defun counsel-compile-env--format-hint (cands)
+  "Return a formatter for compile-env CANDS."
+  (let ((rmstr
+         (propertize "remove" 'face 'font-lock-warning-face))
+        (addstr
+         (propertize "add" 'face 'font-lock-variable-name-face)))
+    (ivy--format-function-generic
+     (lambda (selected)
+       (format "%s %s"
+               (if (member selected counsel-compile-env) rmstr addstr)
+               selected))
+     #'identity
+     cands
+     "\n")))
+
+(defun counsel-compile-env--update (var)
+  "Update `counsel-compile-env' either adding or removing VAR."
+  (if (member var counsel-compile-env)
+      (setq counsel-compile-env (delete var counsel-compile-env))
+    (add-to-list 'counsel-compile-env var)))
+
+;;;###autoload
+(defun counsel-compile-env ()
+  "Update `counsel-compile-env' interactively."
+  (interactive)
+  (let ((ivy-format-function #'counsel-compile-env--format-hint))
+    (ivy-read "Compile environment variable: "
+              (delete-dups (append
+                            counsel-compile-env counsel-compile-env-history))
+              :action #'counsel-compile-env--update
+              :history 'counsel-compile-env-history
+              :caller 'counsel-compile-env)))
+
 ;;** `counsel-minor'
 (defun counsel--minor-candidates ()
   "Return completion alist for `counsel-minor'.



reply via email to

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