[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching):
From: |
Oleh Krehel |
Subject: |
[elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f" |
Date: |
Tue, 08 Dec 2015 10:50:18 +0000 |
branch: master
commit 7cf75750e90f9bb5ad4c61c863330a5f395b80d2
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f"
* swiper.el (swiper-map): Bind `swiper-toggle-face-matching' to
"C-c C-f".
(swiper-invocation-face): New defvar.
(swiper--ivy): Set `swiper-invocation-face'.
(swiper-toggle-face-matching): Toggle `ivy-state-matcher' between
nil (the initial value) and 'swiper--face-matcher.
(swiper--face-matcher): New defun. In addition to filtering CANDIDATES
by having them match REGEXP, also ensure that every match has
`swiper-invocation-face'.
Example of usage:
1. Move point to a variable with e.g. `font-lock-keyword-face' and "C-s"
<input>.
2. Use "C-c C-f" to filter the candidates further by selecting only the
ones that have `font-lock-keyword-face'.
Note that "M-q" (`swiper-query-replace') is also affected by the filtering.
3. Use "C-c C-f" to toggle the filtering off.
Fixes #288
---
swiper.el | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/swiper.el b/swiper.el
index d1bf5de..2fe3ef7 100644
--- a/swiper.el
+++ b/swiper.el
@@ -93,6 +93,7 @@
(define-key map (kbd "C-l") 'swiper-recenter-top-bottom)
(define-key map (kbd "C-'") 'swiper-avy)
(define-key map (kbd "C-7") 'swiper-mc)
+ (define-key map (kbd "C-c C-f") 'swiper-toggle-face-matching)
map)
"Keymap for swiper.")
@@ -319,11 +320,16 @@ there have line numbers. In the buffer, `ivy--regex'
should be used."
(defvar swiper-history nil
"History for `swiper'.")
+(defvar swiper-invocation-face nil
+ "The face at the point of invocation of `swiper'.")
+
(defun swiper--ivy (&optional initial-input)
"`isearch' with an overview using `ivy'.
When non-nil, INITIAL-INPUT is the initial search pattern."
(interactive)
(swiper--init)
+ (setq swiper-invocation-face
+ (plist-get (text-properties-at (point)) 'face))
(let ((candidates (swiper--candidates))
(preselect (buffer-substring-no-properties
(line-beginning-position)
@@ -346,6 +352,33 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(when (null ivy-exit)
(goto-char swiper--opoint)))))
+(defun swiper-toggle-face-matching ()
+ "Toggle matching only the candidates with `swiper-invocation-face'."
+ (interactive)
+ (setf (ivy-state-matcher ivy-last)
+ (if (ivy-state-matcher ivy-last)
+ nil
+ #'swiper--face-matcher))
+ (setq ivy--old-re nil))
+
+(defun swiper--face-matcher (regexp candidates)
+ "Return REGEXP-matching CANDIDATES.
+Matched candidates should have `swiper-invocation-face'."
+ (cl-remove-if-not
+ (lambda (x)
+ (and
+ (string-match regexp x)
+ (let ((s (match-string 0 x))
+ (i 0))
+ (while (and (< i (length s))
+ (text-property-any
+ i (1+ i)
+ 'face swiper-invocation-face
+ s))
+ (cl-incf i))
+ (eq i (length s)))))
+ candidates))
+
(defun swiper--ensure-visible ()
"Remove overlays hiding point."
(let ((overlays (overlays-at (point)))
- [elpa] master e9ba89e 085/167: Make ivy work with enable-recursive-minibuffers, (continued)
- [elpa] master e9ba89e 085/167: Make ivy work with enable-recursive-minibuffers, Oleh Krehel, 2015/12/08
- [elpa] master 7a069be 088/167: ivy.el (ivy-occur-press): Work with counsel-rhythmbox, Oleh Krehel, 2015/12/08
- [elpa] master 32025e5 098/167: Add a better ivy-occur pulse to swiper and counsel-git-grep, Oleh Krehel, 2015/12/08
- [elpa] master b948987 095/167: Input "/sudo::" goes to current directory instead of root's home, Oleh Krehel, 2015/12/08
- [elpa] master 7317848 092/167: counsel.el (counsel-M-x): Add "definition" action, Oleh Krehel, 2015/12/08
- [elpa] master adf7fd3 097/167: swiper.el (swiper--add-overlays): Take extra WND arg, Oleh Krehel, 2015/12/08
- [elpa] master b91870e 094/167: Fix /ssh: and /sudo:: broken in 71695df, Oleh Krehel, 2015/12/08
- [elpa] master 6afce97 096/167: counsel.el (counsel-git-grep-query-replace): Should exit minibuffer, Oleh Krehel, 2015/12/08
- [elpa] master 6e9ab3d 111/167: swiper.el: Add support for evil-jumper/backward, Oleh Krehel, 2015/12/08
- [elpa] master 2a0a25d 117/167: counsel.el (counsel-locate): Add INTIAL-INPUT arg, Oleh Krehel, 2015/12/08
- [elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f",
Oleh Krehel <=
- [elpa] master 6b612cf 093/167: Rebind ivy-occur to "C-c C-o" and "C-o u", Oleh Krehel, 2015/12/08
- [elpa] master 4544c69 105/167: ivy.el (ivy-dispatching-done): Don't set action permanently, Oleh Krehel, 2015/12/08
- [elpa] master e037fb0 101/167: counsel.el (counsel-M-x): Show current-prefix-arg in the prompt, Oleh Krehel, 2015/12/08
- [elpa] master dcc747b 107/167: ivy.el (ivy-occur-mode-map): Bind "q" to quit-window, Oleh Krehel, 2015/12/08
- [elpa] master 57800f6 110/167: swiper.el (swiper-font-lock-ensure): Add eww-mode, Oleh Krehel, 2015/12/08
- [elpa] master f246178 113/167: ivy.el (ivy-prefix-sort): New defcustom, off by default for now, Oleh Krehel, 2015/12/08
- [elpa] master 660e293 106/167: Allow counsel-git-grep -> ivy-occur -> wgrep, Oleh Krehel, 2015/12/08
- [elpa] master 044307d 116/167: ivy.el (ivy--sort-files-by-date): Fix due to destructive cl-sort, Oleh Krehel, 2015/12/08
- [elpa] master 6666cf8 099/167: Fix directory validity check, Oleh Krehel, 2015/12/08
- [elpa] master d434071 120/167: swiper.el (swiper-all): New command to swiper all file buffers, Oleh Krehel, 2015/12/08