This variable is set by `ivy-read' and used by `ivy--set-candidates'.")
+(defcustom ivy-use-ignore-default t
+ "The default policy for user-configured candidate filtering."
+ :type '(choice
+ (const :tag "Ignore ignored always" always)
+ (const :tag "Ignore ignored when others exist" t)
+ (const :tag "Don't ignore" nil)))
+
(defvar ivy-use-ignore t
- "Store policy for user-configured candidate filtering.")
+ "Store policy for user-configured candidate filtering.
+This may be changed dynamically by `ivy-toggle-ignore'.
+Use `ivy-use-ignore-default' for a permanent configuration.")
(defvar ivy--default nil
"Default initial input.")
"Exit the minibuffer with the selected candidate."
(interactive)
(delete-minibuffer-contents)
- (cond ((> ivy--length 0)
+ (cond ((or (> ivy--length 0)
+ ;; the action from `ivy-dispatching-done' may not need a
+ ;; candidate at all
+ (eq this-command 'ivy-dispatching-done))
(ivy--done ivy--current))
((memq (ivy-state-collection ivy-last)
'(read-file-name-internal internal-complete-buffer))
(defun ivy-toggle-ignore ()
"Toggle user-configured candidate filtering."
(interactive)
- (setq ivy-use-ignore (null ivy-use-ignore))
+ (setq ivy-use-ignore
+ (if ivy-use-ignore
+ nil
+ (or ivy-use-ignore-default t)))
;; invalidate cache
(setq ivy--old-cands nil))
(setq ivy--full-length nil)
(setq ivy-text "")
(setq ivy-calling nil)
- (setq ivy-use-ignore t)
+ (setq ivy-use-ignore ivy-use-ignore-default)
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
:test #'equal)))
(setq coll (all-completions "" collection predicate))))
((eq collection 'read-file-name-internal)
- (setq ivy--directory default-directory)
+ (if (and initial-input (file-directory-p initial-input))
+ (progn
+ (setq ivy--directory initial-input)
+ (setq initial-input nil))
+ (setq ivy--directory default-directory))
(require 'dired)
(when preselect
(let ((preselect-directory (file-name-directory preselect)))
match-len)
(while (and (string-match " +" str start1)
(< start1 len))
- (setq match-len (- (match-end 0) (match-beginning 0)))
- (if (= match-len 1)
+ (if (and (> (match-beginning 0) 2)
+ (string= "[^" (substring
+ str
+ (- (match-beginning 0) 2)
+ (match-beginning 0))))
(progn
- (when start0
- (setq start1 start0)
- (setq start0 nil))
- (push (substring str start1 (match-beginning 0)) res)
- (setq start1 (match-end 0)))
- (setq str (replace-match
- (make-string (1- match-len) ?\ )
- nil nil str))
- (setq start0 (or start0 start1))
- (setq start1 (1- (match-end 0)))))
+ (setq start1 (match-end 0))
+ (setq start0 0))
+ (setq match-len (- (match-end 0) (match-beginning 0)))
+ (if (= match-len 1)
+ (progn
+ (when start0
+ (setq start1 start0)
+ (setq start0 nil))
+ (push (substring str start1 (match-beginning 0)) res)
+ (setq start1 (match-end 0)))
+ (setq str (replace-match
+ (make-string (1- match-len) ?\ )
+ nil nil str))
+ (setq start0 (or start0 start1))
+ (setq start1 (1- (match-end 0))))))
(if start0
(push (substring str start0) res)
(setq s (substring str start1))
(cl-sort (copy-sequence collection) sort-fn)
collection)))))
+(defun ivy--magic-file-slash ()
+ (cond ((member ivy-text ivy--all-candidates)
+ (ivy--cd (expand-file-name ivy-text ivy--directory)))
+ ((string-match "//\\'" ivy-text)
+ (if (and default-directory
+ (string-match "\\`[[:alpha:]]:/" default-directory))
+ (ivy--cd (match-string 0 default-directory))
+ (ivy--cd "/")))
+ ((string-match "[[:alpha:]]:/\\'" ivy-text)
+ (let ((drive-root (match-string 0 ivy-text)))
+ (when (file-exists-p drive-root)
+ (ivy--cd drive-root))))
+ ((and (or (> ivy--index 0)
+ (= ivy--length 1)
+ (not (string= ivy-text "/")))
+ (let ((default-directory ivy--directory))
+ (and
+ (not (equal ivy--current ""))
+ (file-directory-p ivy--current)
+ (file-exists-p ivy--current))))
+ (ivy--cd (expand-file-name ivy--current ivy--directory)))))
+
(defun ivy--exhibit ()
"Insert Ivy completions display.
Should be run via minibuffer `post-command-hook'."
(ivy--format ivy--all-candidates))))
(cond (ivy--directory
(if (string-match "/\\'" ivy-text)
- (if (member ivy-text ivy--all-candidates)
- (ivy--cd (expand-file-name ivy-text ivy--directory))
- (when (string-match "//\\'" ivy-text)
- (if (and default-directory
- (string-match "\\`[[:alpha:]]:/" default-directory))
- (ivy--cd (match-string 0 default-directory))
- (ivy--cd "/")))
- (when (string-match "[[:alpha:]]:/$" ivy-text)
- (let ((drive-root (match-string 0 ivy-text)))
- (when (file-exists-p drive-root)
- (ivy--cd drive-root)))))
+ (ivy--magic-file-slash)
(if (string-match "\\`~\\'" ivy-text)
(ivy--cd (expand-file-name "~/")))))
((eq (ivy-state-collection ivy-last) 'internal-complete-buffer)
(not (eq ivy--regex-function 'ivy--regex-fuzzy)))
(unless ivy--old-re
(setq ivy--old-re (funcall ivy--regex-function ivy-text)))
- (while (and (string-match ivy--old-re str start)
- (> (- (match-end 0) (match-beginning 0)) 0))
- (setq start (match-end 0))
- (let ((i 0))
- (while (<= i ivy--subexps)
- (let ((face
- (cond ((zerop ivy--subexps)
- (cadr ivy-minibuffer-faces))
- ((zerop i)
- (car ivy-minibuffer-faces))
- (t
- (nth (1+ (mod (+ i 2) (1- (length ivy-minibuffer-faces))))
- ivy-minibuffer-faces)))))
- (ivy-add-face-text-property
- (match-beginning i) (match-end i)
- face str))
- (cl-incf i))))))
+ (ignore-errors
+ (while (and (string-match ivy--old-re str start)
+ (> (- (match-end 0) (match-beginning 0)) 0))
+ (setq start (match-end 0))
+ (let ((i 0))
+ (while (<= i ivy--subexps)
+ (let ((face
+ (cond ((zerop ivy--subexps)
+ (cadr ivy-minibuffer-faces))
+ ((zerop i)
+ (car ivy-minibuffer-faces))
+ (t
+ (nth (1+ (mod (+ i 2) (1- (length ivy-minibuffer-faces))))
+ ivy-minibuffer-faces)))))
+ (ivy-add-face-text-property
+ (match-beginning i) (match-end i)
+ face str))
+ (cl-incf i)))))))
str))
(ivy-set-display-transformer
((file-exists-p name)
(find-file name)))))
((eq (car view) 'buffer)
- (switch-to-buffer (cadr view)))))
+ (switch-to-buffer (cadr view)))
+ ((eq (car view) 'sexp)
+ (eval (cadr view)))))
(defun ivy--switch-buffer-action (buffer)
"Switch to BUFFER.
(string-match-p f-or-r buf)))
ivy-ignore-buffers))
res)
- res))))
+ (and (eq ivy-use-ignore t)
+ res)))))
(ivy-set-display-transformer
'ivy-switch-buffer 'ivy-switch-buffer-transformer)
(declare-function swiper--cleanup "swiper")
(declare-function swiper--add-overlays "swiper")
(defvar ivy-occur-timer nil)
+(defvar counsel-grep-last-line)
(defun ivy-occur-press ()
"Execute action for the current candidate."
(action (ivy--get-action ivy-last))
(ivy-exit 'done))
(with-ivy-window
+ (setq counsel-grep-last-line nil)
(funcall action
(if (and (consp coll)
(consp (car coll)))