[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 09da543 253/348: swiper.el: Ease the creation of swiper-in
From: |
Oleh Krehel |
Subject: |
[elpa] master 09da543 253/348: swiper.el: Ease the creation of swiper-in-region functions |
Date: |
Sat, 8 Apr 2017 11:04:09 -0400 (EDT) |
branch: master
commit 09da54380f590b86309d81c64138e9619767a57a
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el: Ease the creation of swiper-in-region functions
* swiper.el (swiper--point-min): New defvar.
(swiper--point-max): New defvar.
(swiper--init): Set the new vars.
(swiper--update-input-ivy): Use the new vars.
(swiper--action): Use the new var.
Example - swipe only in the current Org subtree:
(defun worf-occur ()
(interactive)
(let* ((bnd (worf--bounds-subtree))
(candidates
(save-restriction
(narrow-to-region (car bnd) (cdr bnd))
(swiper--init)
(swiper--candidates))))
(ivy-read "pattern: " candidates
:require-match t
:update-fn #'swiper--update-input-ivy
:action #'swiper--action
:unwind #'swiper--cleanup
:caller 'worf-occur)))
Here, `save-restriction' is used to select only the candidates in the
subtree. The actualy restriction is never shown, it's more seamless than
`org-narrow-to-subtree' followed by `swiper'.
---
swiper.el | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/swiper.el b/swiper.el
index 1e03445..b5ad76b 100644
--- a/swiper.el
+++ b/swiper.el
@@ -411,6 +411,8 @@ When REVERT is non-nil, regenerate the current *ivy-occur*
buffer."
(defvar swiper--current-line nil)
(defvar swiper--current-match-start nil)
+(defvar swiper--point-min nil)
+(defvar swiper--point-max nil)
(defun swiper--init ()
"Perform initialization common to both completion methods."
@@ -418,6 +420,8 @@ When REVERT is non-nil, regenerate the current *ivy-occur*
buffer."
(setq swiper--current-match-start nil)
(setq swiper--current-window-start nil)
(setq swiper--opoint (point))
+ (setq swiper--point-min (point-min))
+ (setq swiper--point-max (point-max))
(when (bound-and-true-p evil-mode)
(evil-set-jump)))
@@ -561,7 +565,7 @@ Matched candidates should have `swiper-invocation-face'."
(unless (if swiper--current-line
(eq swiper--current-line num)
(eq (line-number-at-pos) num))
- (goto-char (point-min))
+ (goto-char swiper--point-min)
(if swiper-use-visual-line
(line-move (1- num))
(forward-line (1- num))))
@@ -581,7 +585,10 @@ Matched candidates should have `swiper-invocation-face'."
(<= (point) (window-end (ivy-state-window ivy-last)
t)))
(recenter))
(setq swiper--current-window-start (window-start))))
- (swiper--add-overlays re)))))
+ (swiper--add-overlays
+ re
+ (max (window-start) swiper--point-min)
+ (min (window-end) swiper--point-max))))))
(defun swiper--add-overlays (re &optional beg end wnd)
"Add overlays for RE regexp in visible part of the current buffer.
@@ -658,7 +665,7 @@ WND, when specified is the window."
(unless (equal (current-buffer)
(ivy-state-buffer ivy-last))
(switch-to-buffer (ivy-state-buffer ivy-last)))
- (goto-char (point-min))
+ (goto-char swiper--point-min)
(funcall (if swiper-use-visual-line
#'line-move
#'forward-line)
- [elpa] master 7e02815 235/348: Fix counsel-rg to follow matching candidate, (continued)
- [elpa] master 7e02815 235/348: Fix counsel-rg to follow matching candidate, Oleh Krehel, 2017/04/08
- [elpa] master 530b7de 246/348: ivy.el: Use predicate when reading file names, Oleh Krehel, 2017/04/08
- [elpa] master 1c801a0 243/348: Ignore TAGS buffers in swiper-all, Oleh Krehel, 2017/04/08
- [elpa] master 6519ecc 248/348: ivy.el (ivy-call): Don't mess with default-directory, Oleh Krehel, 2017/04/08
- [elpa] master 721db4c 244/348: counsel.el (counsel-grep-post-action-hook): New hook for counsel-ag/grep/pt, Oleh Krehel, 2017/04/08
- [elpa] master 49acd4c 242/348: Remap scroll-up/down-command instead of assigning C-v/M-v so page up/down works, Oleh Krehel, 2017/04/08
- [elpa] master c322613 240/348: ivy.el (ivy--magic-file-slash): Fix pasting "/etc/", Oleh Krehel, 2017/04/08
- [elpa] master 1304925 239/348: ivy.el (ivy--directory-done): Fix broken "/ssh:", Oleh Krehel, 2017/04/08
- [elpa] master 359a6c8 241/348: Address multiple problems with counsel-rg, Oleh Krehel, 2017/04/08
- [elpa] master 2ed3da4 252/348: counsel.el: Fix byte-compile warning, Oleh Krehel, 2017/04/08
- [elpa] master 09da543 253/348: swiper.el: Ease the creation of swiper-in-region functions,
Oleh Krehel <=
- [elpa] master 3940f17 266/348: Fix typos, Oleh Krehel, 2017/04/08
- [elpa] master 25ac29f 079/348: ivy.el (ivy-completion-in-region): Avoid error for 0 candidates, Oleh Krehel, 2017/04/08
- [elpa] master 0572f16 123/348: swiper now respects ivy-re-builders-alist, Oleh Krehel, 2017/04/08
- [elpa] master d528f04 260/348: ivy.el (ivy--virtual-buffers): Don't modify recentfs or bookmarks, Oleh Krehel, 2017/04/08
- [elpa] master ed579dd 274/348: ivy.el: Fix ivy-highlight-functions-alist, Oleh Krehel, 2017/04/08
- [elpa] master 9151862 277/348: ivy.el (ivy--format-minibuffer-line): Fix for ivy-display-style nil, Oleh Krehel, 2017/04/08
- [elpa] master 6cf7feb 282/348: ivy.el: Allow toggling of sorting in ivy-read, Oleh Krehel, 2017/04/08
- [elpa] master dbcee94 288/348: counsel.el: support universal argument for counsel-unicode-char, Oleh Krehel, 2017/04/08
- [elpa] master 0507841 285/348: Use customizable list of directories when looking for linux apps., Oleh Krehel, 2017/04/08
- [elpa] master 7c73f71 293/348: Allow users to find libraries from counsel-load-library, Oleh Krehel, 2017/04/08