]> code.delx.au - gnu-emacs-elpa/commitdiff
Allow to customize the initial input for all commands
authorOleh Krehel <ohwoeowho@gmail.com>
Mon, 15 Jun 2015 08:06:24 +0000 (10:06 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Mon, 15 Jun 2015 08:06:24 +0000 (10:06 +0200)
* ivy.el (ivy-initial-inputs-alist): New defvar. Customize this to get
  an initial input in any command.
(ivy-read): Unless INTIAL-INPUT is given, look it up in
`ivy-initial-inputs-alist' based on `this-command'.

* counsel.el (counsel-M-x-initial-input): Remove defcustom. It's
  superseded by `ivy-initial-inputs-alist'.
(counsel-M-x): Update.

Fixes #140

counsel.el
ivy.el

index a2657b9ceea1c5dc7cacd33e92d212ee6cafba4e..abd1fe4d5ec0fa30d65438ddc018767fec077176 100644 (file)
@@ -501,16 +501,14 @@ If a command is bound, add it's binding after it."
                cands
                "\n")))
 
-(defcustom counsel-M-x-initial-input "^"
-  "Initial input for `counsel-M-x'."
-  :group 'ivy)
-
 ;;;###autoload
 (defun counsel-M-x (&optional initial-input)
   "Ivy version of `execute-extended-command'.
 Optional INITIAL-INPUT is the initial input in the minibuffer."
   (interactive)
-  (setq initial-input (or initial-input counsel-M-x-initial-input))
+  (unless initial-input
+    (setq initial-input (cdr (assoc this-command
+                                    ivy-initial-inputs-alist))))
   (let ((ivy-format-function #'counsel--format-function-M-x)
         (cands obarray)
         (pred 'commandp)
diff --git a/ivy.el b/ivy.el
index 07ad9bff7e658fb736bb50ea72995f6bd0325fca..c4ff81419286bbbc17815199b9120c335d4b7016 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -614,6 +614,11 @@ The matches will be filtered in a sequence, you can mix the
 regexps that should match and that should not match as you
 like.")
 
+(defvar ivy-initial-inputs-alist
+  '((org-refile . "^")
+    (counsel-M-x . "^"))
+  "Command to initial input table.")
+
 (defcustom ivy-sort-max-size 30000
   "Sorting won't be done for collections larger than this."
   :type 'integer)
@@ -675,6 +680,9 @@ MATCHER can completely override matching.
 
 DYNAMIC-COLLECTION is a function to call to update the list of
 candidates with each input."
+  (unless initial-input
+    (setq initial-input (cdr (assoc this-command
+                                    ivy-initial-inputs-alist))))
   (setq ivy-last
         (make-ivy-state
          :prompt prompt