(define-key map (kbd "C-M-p") 'ivy-previous-line-and-call)
(define-key map (kbd "M-q") 'ivy-toggle-regexp-quote)
(define-key map (kbd "M-j") 'ivy-yank-word)
+ (define-key map (kbd "C-o") 'hydra-ivy/body)
map)
"Keymap used in the minibuffer.")
+(autoload 'hydra-ivy/body "ivy-hydra" "" t)
(defvar ivy-mode-map
(let ((map (make-sparse-keymap)))
:matcher (ivy-state-matcher ivy-last)
:dynamic-collection (ivy-state-dynamic-collection ivy-last)))
+(defvar ivy-calling nil
+ "When non-nil, call the current action when `ivy--index' changes.")
+
+(defun ivy-set-index (index)
+ "Set `ivy--index' to INDEX."
+ (setq ivy--index index)
+ (when ivy-calling
+ (ivy--exhibit)
+ (ivy-call)))
+
(defun ivy-beginning-of-buffer ()
"Select the first completion candidate."
(interactive)
- (setq ivy--index 0))
+ (ivy-set-index 0))
(defun ivy-end-of-buffer ()
"Select the last completion candidate."
(interactive)
- (setq ivy--index (1- ivy--length)))
+ (ivy-set-index (1- ivy--length)))
(defun ivy-scroll-up-command ()
"Scroll the candidates upward by the minibuffer height."
(interactive)
- (setq ivy--index (min (+ ivy--index ivy-height)
- (1- ivy--length))))
+ (ivy-set-index (min (+ ivy--index ivy-height)
+ (1- ivy--length))))
(defun ivy-scroll-down-command ()
"Scroll the candidates downward by the minibuffer height."
(interactive)
- (setq ivy--index (max (- ivy--index ivy-height)
- 0)))
+ (ivy-set-index (max (- ivy--index ivy-height)
+ 0)))
(defun ivy-next-line (&optional arg)
"Move cursor vertically down ARG candidates."
(interactive "p")
(setq arg (or arg 1))
- (cl-incf ivy--index arg)
- (when (> ivy--index (1- ivy--length))
- (if ivy-wrap
- (ivy-beginning-of-buffer)
- (setq ivy--index (1- ivy--length)))))
+ (let ((index (+ ivy--index arg)))
+ (if (> index (1- ivy--length))
+ (if ivy-wrap
+ (ivy-beginning-of-buffer)
+ (ivy-set-index (1- ivy--length)))
+ (ivy-set-index index))))
(defun ivy-next-line-or-history (&optional arg)
"Move cursor vertically down ARG candidates.
"Move cursor vertically up ARG candidates."
(interactive "p")
(setq arg (or arg 1))
- (cl-decf ivy--index arg)
- (when (< ivy--index 0)
- (if ivy-wrap
- (ivy-end-of-buffer)
- (setq ivy--index 0))))
+ (let ((index (- ivy--index arg)))
+ (if (< index 0)
+ (if ivy-wrap
+ (ivy-end-of-buffer)
+ (ivy-set-index 0))
+ (ivy-set-index index))))
(defun ivy-previous-line-or-history (arg)
"Move cursor vertically up ARG candidates.
(ivy-previous-history-element 1))
(ivy-previous-line arg))
+(defun ivy-toggle-calling ()
+ "Flip `ivy-calling'"
+ (interactive)
+ (when (setq ivy-calling (not ivy-calling))
+ (ivy-call)))
+
+(defun ivy-call ()
+ "Call the current action without exiting completion."
+ (when (ivy-state-action ivy-last)
+ (with-selected-window (ivy-state-window ivy-last)
+ (funcall (ivy-state-action ivy-last) ivy--current))))
+
(defun ivy-next-line-and-call (&optional arg)
"Move cursor vertically down ARG candidates.
Call the permanent action if possible."
(interactive "p")
(ivy-next-line arg)
(ivy--exhibit)
- (when (ivy-state-action ivy-last)
- (with-selected-window (ivy-state-window ivy-last)
- (funcall (ivy-state-action ivy-last) ivy--current))))
+ (ivy-call))
(defun ivy-previous-line-and-call (&optional arg)
"Move cursor vertically down ARG candidates.
(interactive "p")
(ivy-previous-line arg)
(ivy--exhibit)
- (when (ivy-state-action ivy-last)
- (with-selected-window (ivy-state-window ivy-last)
- (funcall (ivy-state-action ivy-last) ivy--current))))
+ (ivy-call))
(defun ivy-previous-history-element (arg)
"Forward to `previous-history-element' with ARG."
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)
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
(setq ivy--regexp-quote 'regexp-quote)
(setq ivy--old-text "")
(setq ivy-text "")
+ (setq ivy-calling nil)
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
(defun ivy--regex-fuzzy (str)
"Build a regex sequence from STR.
Insert .* between each char."
- (mapconcat #'string (string-to-list str) ".*"))
+ (if (string-match "\\`\\(\\^?\\)\\(.*?\\)\\(\\$?\\)\\'" str)
+ (concat (match-string 1 str)
+ (mapconcat #'string (string-to-list (match-string 2 str)) ".*")
+ (match-string 3 str))
+ str))
;;** Rest
(defun ivy--minibuffer-setup ()