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

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

[elpa] master 9bd79da 074/348: ivy.el (ivy-set-prompt): New API


From: Oleh Krehel
Subject: [elpa] master 9bd79da 074/348: ivy.el (ivy-set-prompt): New API
Date: Sat, 8 Apr 2017 11:03:29 -0400 (EDT)

branch: master
commit 9bd79da7d9f9cac95342d729ca2f2348fde20825
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy-set-prompt): New API
    
    * ivy.el (ivy-prompt): Called to possibly update the prompt in
      `post-command-hook'.
    
    * counsel.el (counsel-prompt-function): Mark as obsolete. Will be
      removed after a few months.
    (counsel-prompt-function-default): Change from 1 arg to 0 args.
    (counsel-prompt-function-dir): Change from 1 arg to 0 args.
    (counsel-git):
    (counsel-git-grep):
    (counsel-ag): Use `ivy-set-prompt'.
    
    * Makefile: New target "obsolete". Used to check if obsolete warnings
      work properly for the current obsolete variables.
    
    * targets/obsolete-config.el: Used in conjunction with "make obsolete".
    
    Re #424
---
 Makefile                   |  3 +++
 counsel.el                 | 46 +++++++++++++++++++++++++---------------------
 ivy.el                     | 17 ++++++++++++++++-
 targets/obsolete-config.el |  4 ++++
 4 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/Makefile b/Makefile
index ca1d043..649949e 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,9 @@ compile:
 plain:
        $(emacs) -Q $(LOAD) --eval "(progn (package-initialize) (ivy-mode))" -l 
ivy-hydra.el
 
+obsolete:
+       $(emacs) -batch -l targets/obsolete-config.el
+
 clean:
        rm -f *.elc
 
diff --git a/counsel.el b/counsel.el
index 3f7396a..be8d9bf 100644
--- a/counsel.el
+++ b/counsel.el
@@ -203,9 +203,14 @@ Update the minibuffer with the amount of lines collected 
every
     (function :tag "Custom"))
   :group 'ivy)
 
-(defun counsel-prompt-function-default (prompt)
-  "Return PROMPT appended with a semicolon."
-  (format "%s: " prompt))
+(make-obsolete-variable
+ 'counsel-prompt-function
+ "Use `ivy-set-prompt' instead"
+ "0.8.0 <2016-06-20 Mon>")
+
+(defun counsel-prompt-function-default ()
+  "Return prompt appended with a semicolon."
+  (format "%s: " (ivy-state-prompt ivy-last)))
 
 (defun counsel-delete-process ()
   (let ((process (get-process " *counsel*")))
@@ -832,6 +837,7 @@ Describe the selected candidate."
   (interactive)
   (setq counsel--git-dir (locate-dominating-file
                           default-directory ".git"))
+  (ivy-set-prompt 'counsel-git counsel-prompt-function)
   (if (null counsel--git-dir)
       (error "Not in a git repository")
     (setq counsel--git-dir (expand-file-name
@@ -842,8 +848,7 @@ Describe the selected candidate."
                     "git ls-files --full-name --")
                    "\n"
                    t)))
-      (ivy-read (funcall counsel-prompt-function "Find file")
-                cands
+      (ivy-read "Find file" cands
                 :action #'counsel-git-action))))
 
 (defun counsel-git-action (x)
@@ -881,11 +886,11 @@ Describe the selected candidate."
   '("git --no-pager grep --full-name -n --no-color -i -e %S")
   "History for `counsel-git-grep' shell commands.")
 
-(defun counsel-prompt-function-dir (prompt)
-  "Return PROMPT appended with the parent directory."
+(defun counsel-prompt-function-dir ()
+  "Return prompt appended with the parent directory."
   (let ((directory counsel--git-grep-dir))
     (format "%s [%s]: "
-            prompt
+            (ivy-state-prompt ivy-last)
             (let ((dir-list (eshell-split-path directory)))
               (if (> (length dir-list) 3)
                   (apply #'concat
@@ -963,6 +968,7 @@ When CMD is a string, use it as a \"git grep\" command.
 When CMD is non-nil, prompt for a specific \"git grep\" command.
 INITIAL-INPUT can be given as the initial minibuffer input."
   (interactive "P")
+  (ivy-set-prompt 'counsel-git-grep counsel-prompt-function)
   (cond
     ((stringp cmd)
      (setq counsel-git-grep-cmd cmd))
@@ -979,17 +985,15 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
   (if (null counsel--git-grep-dir)
       (error "Not in a git repository")
     (setq counsel--git-grep-count (counsel--gg-count "" t))
-    (ivy-read
-     (funcall counsel-prompt-function "git grep")
-     'counsel-git-grep-function
-     :initial-input initial-input
-     :matcher #'counsel-git-grep-matcher
-     :dynamic-collection (> counsel--git-grep-count 20000)
-     :keymap counsel-git-grep-map
-     :action #'counsel-git-grep-action
-     :unwind #'swiper--cleanup
-     :history 'counsel-git-grep-history
-     :caller 'counsel-git-grep)))
+    (ivy-read "git grep" 'counsel-git-grep-function
+              :initial-input initial-input
+              :matcher #'counsel-git-grep-matcher
+              :dynamic-collection (> counsel--git-grep-count 20000)
+              :keymap counsel-git-grep-map
+              :action #'counsel-git-grep-action
+              :unwind #'swiper--cleanup
+              :history 'counsel-git-grep-history
+              :caller 'counsel-git-grep)))
 
 (defun counsel-git-grep-switch-cmd ()
   "Set `counsel-git-grep-cmd' to a different value."
@@ -1441,9 +1445,9 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
            (read-directory-name (concat
                                  (car (split-string counsel-ag-base-command))
                                  " in directory: ")))))
+  (ivy-set-prompt 'counsel-ag counsel-prompt-function)
   (setq counsel--git-grep-dir (or initial-directory default-directory))
-  (ivy-read (funcall counsel-prompt-function
-                     (car (split-string counsel-ag-base-command)))
+  (ivy-read (car (split-string counsel-ag-base-command))
             'counsel-ag-function
             :initial-input initial-input
             :dynamic-collection t
diff --git a/ivy.el b/ivy.el
index 6c067b3..49b4db5 100644
--- a/ivy.el
+++ b/ivy.el
@@ -186,6 +186,14 @@ Only \"./\" and \"../\" apply here. They appear in reverse 
order."
                      actions
                      (plist-get ivy--actions-list cmd))))))
 
+(defvar ivy--prompts-list nil)
+
+(defun ivy-set-prompt (caller prompt-fn)
+  "Associate CALLER with PROMPT-FN.
+PROMPT-FN is a function of no arguments that returns a prompt string."
+  (setq ivy--prompts-list
+        (plist-put ivy--prompts-list caller prompt-fn)))
+
 (defvar ivy--display-transformers-list nil
   "A list of str->str transformers per command.")
 
@@ -1975,9 +1983,16 @@ The returned value should be the updated PROMPT.")
                         `(face ivy-match-required-face ,@std-props))
   prompt)
 
+(defun ivy-prompt ()
+  "Return the current prompt."
+  (let ((fn (plist-get ivy--prompts-list (ivy-state-caller ivy-last))))
+    (if fn
+        (funcall fn)
+      ivy--prompt)))
+
 (defun ivy--insert-prompt ()
   "Update the prompt according to `ivy--prompt'."
-  (when ivy--prompt
+  (when (setq ivy--prompt (ivy-prompt))
     (unless (memq this-command '(ivy-done ivy-alt-done ivy-partial-or-done
                                  counsel-find-symbol))
       (setq ivy--prompt-extra ""))
diff --git a/targets/obsolete-config.el b/targets/obsolete-config.el
new file mode 100644
index 0000000..8d79b70
--- /dev/null
+++ b/targets/obsolete-config.el
@@ -0,0 +1,4 @@
+(add-to-list 'load-path default-directory)
+(require 'counsel)
+(setq counsel-prompt-function 'counsel-prompt-function-default)
+(byte-compile-file (expand-file-name "targets/obsolete-config.el"))



reply via email to

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