[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ee27e27 161/272: ivy.el (ivy-occur-revert-buffer): Move co
From: |
Oleh Krehel |
Subject: |
[elpa] master ee27e27 161/272: ivy.el (ivy-occur-revert-buffer): Move code to swiper-occur |
Date: |
Mon, 25 Apr 2016 10:13:23 +0000 |
branch: master
commit ee27e27a156f9d0c9c2e328f27d6fcce042cfe09
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-occur-revert-buffer): Move code to swiper-occur
* ivy.el (ivy-occur-revert-buffer): Shouldn't know what's going on with
`swiper'.
* swiper.el (swiper-occur): Now takes an optional arg. Also moves the
point to the first cand.
TODO: The recovery of `ivy-text' is still hacky.
---
ivy.el | 47 ++++++++++++++++++++---------------------------
swiper.el | 21 +++++++++++++++------
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/ivy.el b/ivy.el
index 96eeeb0..5a19227 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2704,33 +2704,6 @@ buffer would modify `ivy-last'.")
map)
"Keymap for Ivy Occur mode.")
-(defun ivy-occur-revert-buffer ()
- "Refresh the buffer making it up-to date with the collection.
-
-Currently only works for `swiper'. In that specific case, the
-*ivy-occur* buffer becomes nearly useless as the orignal buffer
-is updated, since the line numbers no longer match.
-
-Calling this function is as if you called `ivy-occur' on the
-updated original buffer."
- (interactive)
- (let ((caller (ivy-state-caller ivy-occur-last))
- (text (progn (string-match "\"\\(.*\\)\"" (buffer-name))
- (match-string 1 (buffer-name))))
- (ivy-last ivy-occur-last))
- (when (eq caller 'swiper)
- (let ((buffer (ivy-state-buffer ivy-occur-last)))
- (unless (buffer-live-p buffer)
- (error "buffer was killed"))
- (with-current-buffer buffer
- (setq ivy--old-re nil)
- (setq ivy--old-cands (ivy--filter text (swiper--candidates))))
- (let ((inhibit-read-only t))
- (erase-buffer)
- (swiper-occur)
- (goto-char (point-min))
- (forward-line 4))))))
-
(defun ivy-occur-toggle-calling ()
"Toggle `ivy-calling'."
(interactive)
@@ -2829,6 +2802,26 @@ There is no limit on the number of *ivy-occur* buffers."
(ivy-exit-with-action
`(lambda (_) (pop-to-buffer ,buffer))))))
+(defun ivy-occur-revert-buffer ()
+ "Refresh the buffer making it up-to date with the collection.
+
+Currently only works for `swiper'. In that specific case, the
+*ivy-occur* buffer becomes nearly useless as the orignal buffer
+is updated, since the line numbers no longer match.
+
+Calling this function is as if you called `ivy-occur' on the
+updated original buffer."
+ (interactive)
+ (let ((caller (ivy-state-caller ivy-occur-last))
+ (ivy-last ivy-occur-last))
+ (when (eq caller 'swiper)
+ (let ((buffer (ivy-state-buffer ivy-occur-last)))
+ (unless (buffer-live-p buffer)
+ (error "buffer was killed"))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (funcall (plist-get ivy--occurs-list caller) t))))))
+
(declare-function wgrep-change-to-wgrep-mode "ext:wgrep")
(defun ivy-wgrep-change-to-wgrep-mode ()
diff --git a/swiper.el b/swiper.el
index bdf3819..a2c3255 100644
--- a/swiper.el
+++ b/swiper.el
@@ -316,13 +316,13 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(declare-function string-trim-right "subr-x")
-(defun swiper-occur ()
+(defun swiper-occur (&optional revert)
"Generate a custom occur buffer for `swiper'."
- (let* ((fname (propertize
+ (let* ((buffer (ivy-state-buffer ivy-last))
+ (fname (propertize
(with-ivy-window
(file-name-nondirectory
- (buffer-file-name
- (ivy-state-buffer ivy-last))))
+ (buffer-file-name buffer)))
'face
'compilation-info))
(cands (mapcar
@@ -334,7 +334,14 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(get-text-property 0 'display s))
'face 'compilation-line-number)
(substring s 1)))
- ivy--old-cands)))
+ (if (null revert)
+ ivy--old-cands
+ (setq ivy--old-re nil)
+ (ivy--filter
+ (progn (string-match "\"\\(.*\\)\"" (buffer-name))
+ (match-string 1 (buffer-name)))
+ (with-current-buffer buffer
+ (swiper--candidates)))))))
(unless (eq major-mode 'ivy-occur-grep-mode)
(ivy-occur-grep-mode)
(font-lock-mode -1))
@@ -344,7 +351,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(ivy--occur-insert-lines
(mapcar
(lambda (cand) (concat "./" cand))
- cands))))
+ cands))
+ (goto-char (point-min))
+ (forward-line 4)))
(ivy-set-occur 'swiper 'swiper-occur)
- [elpa] master b2d2b82 209/272: counsel.el (counsel-grep-action): Improve cleanup, (continued)
- [elpa] master b2d2b82 209/272: counsel.el (counsel-grep-action): Improve cleanup, Oleh Krehel, 2016/04/25
- [elpa] master 8c4f595 233/272: Fix remapping commit c9b6e0, Oleh Krehel, 2016/04/25
- [elpa] master 6fae6e0 259/272: counsel.el (counsel-grep-or-swiper): Use swiper when narrowed, Oleh Krehel, 2016/04/25
- [elpa] master 1b4e819 218/272: ivy.el (ivy-next-history-element): Simplify, Oleh Krehel, 2016/04/25
- [elpa] master b5a9dc5 255/272: ivy.el (ivy--reset-state): file-directory-p needs a string, Oleh Krehel, 2016/04/25
- [elpa] master 6fc36b5 210/272: option to add newline after ivy-read prompt, Oleh Krehel, 2016/04/25
- [elpa] master 9899547 235/272: ivy.el (ivy-action): New face, Oleh Krehel, 2016/04/25
- [elpa] master 63b96a1 250/272: Fix counsel-grep-last-line bug, Oleh Krehel, 2016/04/25
- [elpa] master a891df3 264/272: swiper.el (swiper--multi-candidates): Add check, Oleh Krehel, 2016/04/25
- [elpa] master 5ce2623 223/272: counsel.el (counsel-git): Add "j" action, Oleh Krehel, 2016/04/25
- [elpa] master ee27e27 161/272: ivy.el (ivy-occur-revert-buffer): Move code to swiper-occur,
Oleh Krehel <=
- [elpa] master 3dcb07d 237/272: Allow to customize the action hint formatter, Oleh Krehel, 2016/04/25
- [elpa] master 39a458e 272/272: Merge commit 'db005182ad0fd05c07e8e5c085abe6c750e6c578' from ivy, Oleh Krehel, 2016/04/25