[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1485e58 076/272: Add ignore pattern toggling
From: |
Oleh Krehel |
Subject: |
[elpa] master 1485e58 076/272: Add ignore pattern toggling |
Date: |
Mon, 25 Apr 2016 10:13:17 +0000 |
branch: master
commit 1485e58fd2313e0a019e97191f4332fcebf2ae62
Author: Stephen Whipple <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add ignore pattern toggling
* ivy.el (ivy-minibuffer-map): Bind "C-c C-a" to `ivy-toggle-ignore'.
(ivy-use-ignore): New defvar.
(ivy-toggle-ignore): New command to toggle ignore
patterns (user-configured filtering). If the ignore patterns are enabled
and there are zero candidates after ignoring, display the ones that
match the current text. This feature currently works for
`ivy-switch-buffer' and `counsel-find-file'.
(ivy--buffer-list): Simplify.
(ivy--switch-buffer-matcher): New defun.
(ivy-switch-buffer): Use `ivy--switch-buffer-matcher'.
* counsel.el (counsel--find-file-matcher): Use `ivy-use-ignore'.
Fixes #369
---
counsel.el | 12 +++++++-----
ivy.el | 59 +++++++++++++++++++++++++++++++++++++++++------------------
2 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/counsel.el b/counsel.el
index 2a6a264..25ebf98 100644
--- a/counsel.el
+++ b/counsel.el
@@ -542,13 +542,15 @@ Possible value: \"\\(?:\\`[#.]\\)\\|\\(?:[#~]\\'\\)\"."
"Return REGEXP-matching CANDIDATES.
Skip some dotfiles unless `ivy-text' requires them."
(let ((res (ivy--re-filter regexp candidates)))
- (if (or (null counsel-find-file-ignore-regexp)
+ (if (or (null ivy-use-ignore)
+ (null counsel-find-file-ignore-regexp)
(string-match counsel-find-file-ignore-regexp ivy-text))
res
- (cl-remove-if
- (lambda (x)
- (string-match counsel-find-file-ignore-regexp x))
- res))))
+ (or (cl-remove-if
+ (lambda (x)
+ (string-match counsel-find-file-ignore-regexp x))
+ res)
+ res))))
(defun counsel-git-grep-matcher (regexp candidates)
(or (and (equal regexp ivy--old-re)
diff --git a/ivy.el b/ivy.el
index 4a17bbf..b95ce33 100644
--- a/ivy.el
+++ b/ivy.el
@@ -236,6 +236,7 @@ Example:
(define-key map (kbd "C-'") 'ivy-avy)
(define-key map (kbd "C-M-a") 'ivy-read-action)
(define-key map (kbd "C-c C-o") 'ivy-occur)
+ (define-key map (kbd "C-c C-a") 'ivy-toggle-ignore)
(define-key map (kbd "C-h m") 'ivy-help)
map)
"Keymap used in the minibuffer.")
@@ -318,6 +319,9 @@ sources. These values will subsequently be filtered on
`ivy-text'.
This variable is set by `ivy-read' and used by `ivy--set-candidates'.")
+(defvar ivy-use-ignore t
+ "Store policy for user-configured candidate filtering.")
+
(defvar ivy--default nil
"Default initial input.")
@@ -734,6 +738,13 @@ If the input is empty, select the previous history element
instead."
(when (setq ivy-calling (not ivy-calling))
(ivy-call)))
+(defun ivy-toggle-ignore ()
+ "Toggle user-configured candidate filtering."
+ (interactive)
+ (setq ivy-use-ignore (null ivy-use-ignore))
+ ;; invalidate cache
+ (setq ivy--old-cands nil))
+
(defun ivy--get-action (state)
"Get the action function from STATE."
(let ((action (ivy-state-action state)))
@@ -1285,6 +1296,7 @@ This is useful for recursive `ivy-read'."
(setq ivy--full-length nil)
(setq ivy-text "")
(setq ivy-calling nil)
+ (setq ivy-use-ignore t)
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
@@ -2383,24 +2395,18 @@ CANDS is a list of strings."
(defun ivy--buffer-list (str &optional virtual)
"Return the buffers that match STR.
When VIRTUAL is non-nil, add virtual buffers."
- (cl-remove-if
- (lambda (buf)
- (cl-find-if
- (lambda (regexp)
- (string-match regexp buf))
- ivy-ignore-buffers))
- (delete-dups
- (append
- (mapcar
- (lambda (x)
- (if (with-current-buffer x
- (file-remote-p
- (abbreviate-file-name default-directory)))
- (propertize x 'face 'ivy-remote)
- x))
- (all-completions str 'internal-complete-buffer))
- (and virtual
- (ivy--virtual-buffers))))))
+ (delete-dups
+ (append
+ (mapcar
+ (lambda (x)
+ (if (with-current-buffer x
+ (file-remote-p
+ (abbreviate-file-name default-directory)))
+ (propertize x 'face 'ivy-remote)
+ x))
+ (all-completions str 'internal-complete-buffer))
+ (and virtual
+ (ivy--virtual-buffers)))))
(defun ivy--switch-buffer-action (buffer)
"Switch to BUFFER.
@@ -2449,6 +2455,22 @@ BUFFER may be a string or nil."
ivy--rename-buffer-action
"rename")))
+(defun ivy--switch-buffer-matcher (regexp candidates)
+ "Return REGEXP-matching CANDIDATES.
+Skip buffers that match `ivy-ignore-buffers'."
+ (let ((res (ivy--re-filter regexp candidates)))
+ (if (or (null ivy-use-ignore)
+ (null ivy-ignore-buffers))
+ res
+ (or (cl-remove-if
+ (lambda (buf)
+ (cl-find-if
+ (lambda (regexp)
+ (string-match regexp buf))
+ ivy-ignore-buffers))
+ res)
+ res))))
+
;;;###autoload
(defun ivy-switch-buffer ()
"Switch to another buffer."
@@ -2457,6 +2479,7 @@ BUFFER may be a string or nil."
(call-interactively 'switch-to-buffer)
(let ((this-command 'ivy-switch-buffer))
(ivy-read "Switch to buffer: " 'internal-complete-buffer
+ :matcher #'ivy--switch-buffer-matcher
:preselect (buffer-name (other-buffer (current-buffer)))
:action #'ivy--switch-buffer-action
:keymap ivy-switch-buffer-map))))
- [elpa] master 80825a6 082/272: ivy.el: Fixup face docs, (continued)
- [elpa] master 80825a6 082/272: ivy.el: Fixup face docs, Oleh Krehel, 2016/04/25
- [elpa] master 44856a3 219/272: ivy.el (ivy-read): Revert abf880f, Oleh Krehel, 2016/04/25
- [elpa] master 0afb000 077/272: Fix default-directory for ivy-occur + counsel-git-grep, Oleh Krehel, 2016/04/25
- [elpa] master a6cd189 192/272: counsel.el (counsel-linux-apps-list): Skip spaces around =, Oleh Krehel, 2016/04/25
- [elpa] master e8f516e 182/272: counsel.el (counsel-ag): Add transformer, Oleh Krehel, 2016/04/25
- [elpa] master 6a8da39 206/272: counsel.el (counsel-grep-action): Reveal outlines, Oleh Krehel, 2016/04/25
- [elpa] master 2bd092d 222/272: ivy.el (ivy--minibuffer-setup): Ensure inhibit-field-text-motion is nil, Oleh Krehel, 2016/04/25
- [elpa] master 2ac1d2d 256/272: ivy.el (ivy-occur-press): Set counsel-grep-last-line to nil, Oleh Krehel, 2016/04/25
- [elpa] master 4ebf0b4 215/272: ivy.el: Add `counsel-find-file' transformer., Oleh Krehel, 2016/04/25
- [elpa] master 615dd90 241/272: counsel.el (counsel-grep-action): Work better from ivy-occur, Oleh Krehel, 2016/04/25
- [elpa] master 1485e58 076/272: Add ignore pattern toggling,
Oleh Krehel <=
- [elpa] master 8dfff3e 200/272: ivy.el (ivy-next-history-element): Improve, Oleh Krehel, 2016/04/25
- [elpa] master 3177419 216/272: ivy.el (ivy-sort-functions-alist): Update :type, Oleh Krehel, 2016/04/25
- [elpa] master abf880f 214/272: ivy.el (ivy-read): Make "M-o" not modify the action, Oleh Krehel, 2016/04/25
- [elpa] master 3f4f080 226/272: counsel-ag now works with ivy-occur-revert-buffer, Oleh Krehel, 2016/04/25
- [elpa] master f31ab12 066/272: swiper.el (swiper--ivy): Return point, Oleh Krehel, 2016/04/25
- [elpa] master 6777cf8 220/272: counsel.el (counsel-unquote-regex-parens): Improve, Oleh Krehel, 2016/04/25
- [elpa] master ddc1d9f 114/272: Move all faces to ivy-faces group, Oleh Krehel, 2016/04/25
- [elpa] master e92d282 195/272: Make ivy-ignore-buffers similar to ido-ignore-buffers., Oleh Krehel, 2016/04/25
- [elpa] master 4235ffc 092/272: colir.el (colir-blend-face-background): Improve, Oleh Krehel, 2016/04/25
- [elpa] master 9aee83a 105/272: ivy.el (ivy-completion-in-region): Bind completion-ignore-case, Oleh Krehel, 2016/04/25