branch: master commit ae05765add1f3bc90421f033ff408fb93eba03a1 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Allow to customize the initial input for all commands * 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 | 8 +++----- ivy.el | 8 ++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/counsel.el b/counsel.el index a2657b9..abd1fe4 100644 --- a/counsel.el +++ b/counsel.el @@ -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 07ad9bf..c4ff814 100644 --- 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