[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 20f11b7 159/272: New command ivy-occur-revert-buffer bound
From: |
Oleh Krehel |
Subject: |
[elpa] master 20f11b7 159/272: New command ivy-occur-revert-buffer bound to "g" |
Date: |
Mon, 25 Apr 2016 10:13:23 +0000 |
branch: master
commit 20f11b7af72a4e09f5abffa189ac1398ac2a5429
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
New command ivy-occur-revert-buffer bound to "g"
* ivy.el (ivy-occur-mode-map): Move `ivy-occur-press' from "g" to "f".
Bind "g" to `ivy-occur-revert-buffer'.
(ivy-occur-revert-buffer): New command. Does what e.g. `revert-buffer'
does for *Help* buffers.
* swiper.el (swiper-faces): Add :group and :type.
(swiper-occur): Try to avoid calling `ivy-occur-grep-mode' as it will
kill all local variables.
(swiper--action): Update so that `ivy-occur-toggle-calling' works properly.
---
ivy.el | 30 +++++++++++++++++++++++++++++-
swiper.el | 19 +++++++++++--------
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/ivy.el b/ivy.el
index 60c20a6..cd9a7b5 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2695,7 +2695,8 @@ buffer would modify `ivy-last'.")
(define-key map (kbd "k") 'ivy-occur-previous-line)
(define-key map (kbd "h") 'backward-char)
(define-key map (kbd "l") 'forward-char)
- (define-key map (kbd "g") 'ivy-occur-press)
+ (define-key map (kbd "f") 'ivy-occur-press)
+ (define-key map (kbd "g") 'ivy-occur-revert-buffer)
(define-key map (kbd "a") 'ivy-occur-read-action)
(define-key map (kbd "o") 'ivy-occur-dispatch)
(define-key map (kbd "c") 'ivy-occur-toggle-calling)
@@ -2703,6 +2704,33 @@ 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)
diff --git a/swiper.el b/swiper.el
index be73d6f..bdf3819 100644
--- a/swiper.el
+++ b/swiper.el
@@ -69,7 +69,9 @@
swiper-match-face-2
swiper-match-face-3
swiper-match-face-4)
- "List of `swiper' faces for group matches.")
+ "List of `swiper' faces for group matches."
+ :group 'ivy-faces
+ :type 'list)
(defcustom swiper-min-highlight 2
"Only highlight matches for regexps at least this long."
@@ -316,12 +318,11 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(defun swiper-occur ()
"Generate a custom occur buffer for `swiper'."
- (ivy-occur-grep-mode)
- (font-lock-mode -1)
(let* ((fname (propertize
(with-ivy-window
(file-name-nondirectory
- (buffer-file-name)))
+ (buffer-file-name
+ (ivy-state-buffer ivy-last))))
'face
'compilation-info))
(cands (mapcar
@@ -334,6 +335,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
'face 'compilation-line-number)
(substring s 1)))
ivy--old-cands)))
+ (unless (eq major-mode 'ivy-occur-grep-mode)
+ (ivy-occur-grep-mode)
+ (font-lock-mode -1))
(insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
default-directory))
(insert (format "%d candidates:\n" (length cands)))
@@ -559,10 +563,9 @@ WND, when specified is the window."
(defun swiper--action (x)
"Goto line X."
- (let ((ln (1- (read (if (memq this-command '(ivy-occur-press))
- (when (string-match ":\\([0-9]+\\):.*\\'" x)
- (match-string-no-properties 1 x))
- (get-text-property 0 'display x)))))
+ (let ((ln (1- (read (or (get-text-property 0 'display x)
+ (and (string-match ":\\([0-9]+\\):.*\\'" x)
+ (match-string-no-properties 1 x))))))
(re (ivy--regex ivy-text)))
(if (null x)
(user-error "No candidates")
- [elpa] master 4235ffc 092/272: colir.el (colir-blend-face-background): Improve, (continued)
- [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
- [elpa] master 2a1ef54 148/272: ivy-dispatching-done should not permanently modify default action index, Oleh Krehel, 2016/04/25
- [elpa] master 5eaf787 078/272: doc/ivy.org: Improve the Texinfo/HTML export structure, Oleh Krehel, 2016/04/25
- [elpa] master b7c40d3 152/272: ivy.el (ivy-resume): Add a guard against null :action, Oleh Krehel, 2016/04/25
- [elpa] master 2ab9c54 197/272: ivy.el (ivy--switch-buffer-matcher): Fix, Oleh Krehel, 2016/04/25
- [elpa] master db00518 270/272: Bump version to 0.8.0, Oleh Krehel, 2016/04/25
- [elpa] master 96828c2 100/272: ivy.el (ivy-read): Identify extra-actions by caller as well, Oleh Krehel, 2016/04/25
- [elpa] master d425392 178/272: Correctly expand the file name at point, Oleh Krehel, 2016/04/25
- [elpa] master 8201f36 224/272: ivy.el (ivy-occur-revert-buffer): Improve for counsel-git-grep, Oleh Krehel, 2016/04/25
- [elpa] master 20f11b7 159/272: New command ivy-occur-revert-buffer bound to "g",
Oleh Krehel <=
- [elpa] master d8da9c4 188/272: counsel.el (counsel-mode): Allow use of describe-prefix-bindings, Oleh Krehel, 2016/04/25
- [elpa] master ab795d0 265/272: Don't highlight that match in the file name part, Oleh Krehel, 2016/04/25
- [elpa] master 255457a 177/272: Fixed counsel-list-processes-action-switch to use correct buffer., Oleh Krehel, 2016/04/25
- [elpa] master 48b5638 129/272: ivy.el (ivy-next-history-element): Don't add symbol bounds for file names, Oleh Krehel, 2016/04/25
- [elpa] master 41dfae6 194/272: ivy.el (ivy--format-function-generic): Fix doc, Oleh Krehel, 2016/04/25
- [elpa] master f0de338 198/272: ivy.el (ivy--directory-done): Fix when ivy-text is a dir, Oleh Krehel, 2016/04/25
- [elpa] master 67224c0 171/272: counsel.el (counsel-prompt-function): New defcustom, Oleh Krehel, 2016/04/25
- [elpa] master 0c5f68c 183/272: counsel.el (counsel-pt): Add, Oleh Krehel, 2016/04/25
- [elpa] master 692002d 184/272: counsel.el (counsel-pt): Remove unused args, Oleh Krehel, 2016/04/25
- [elpa] master 0bad922 083/272: Provide the :caller in most calls to ivy-read, Oleh Krehel, 2016/04/25