[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 476fc5d 58/63: Add with-ivy-window macro
From: |
Oleh Krehel |
Subject: |
[elpa] master 476fc5d 58/63: Add with-ivy-window macro |
Date: |
Fri, 21 Aug 2015 12:08:48 +0000 |
branch: master
commit 476fc5d647f392c82631b66538dbbf0fe9f2d939
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add with-ivy-window macro
* ivy.el (with-ivy-window): New macro.
(ivy-yank-word): Update.
* swiper.el (swiper--window): Remove defvar.
(swiper-query-replace):
(swiper-avy):
(swiper-recenter-top-bottom):
(swiper--init):
(swiper--update-input-ivy):
(swiper--add-overlays): Update.
* counsel.el (counsel-git-grep-recenter):
(counsel-git-grep-action):
(counsel-M-x): Update.
(org-agenda-set-tags): Add a declare.
---
counsel.el | 8 ++--
ivy.el | 9 +++++-
swiper.el | 96 ++++++++++++++++++++++++++++-------------------------------
3 files changed, 58 insertions(+), 55 deletions(-)
diff --git a/counsel.el b/counsel.el
index f771ab7..6aefbb0 100644
--- a/counsel.el
+++ b/counsel.el
@@ -301,13 +301,13 @@
(defun counsel-git-grep-recenter ()
(interactive)
- (with-selected-window (ivy-state-window ivy-last)
+ (with-ivy-window
(counsel-git-grep-action ivy--current)
(recenter-top-bottom)))
(defun counsel-git-grep-action (x)
(when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
- (with-selected-window (ivy-state-window ivy-last)
+ (with-ivy-window
(let ((file-name (match-string-no-properties 1 x))
(line-number (match-string-no-properties 2 x)))
(find-file (expand-file-name file-name counsel--git-grep-dir))
@@ -315,7 +315,6 @@
(forward-line (1- (string-to-number line-number)))
(re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
(unless (eq ivy-exit 'done)
- (setq swiper--window (selected-window))
(swiper--cleanup)
(swiper--add-overlays (ivy--regex ivy-text)))))))
@@ -652,7 +651,7 @@ Optional INITIAL-INPUT is the initial input in the
minibuffer."
(lambda (cands)
(funcall
store
- (with-selected-window (ivy-state-window ivy-last)
+ (with-ivy-window
(mapcar #'counsel--M-x-transformer cands)))))
(cands obarray)
(pred 'commandp)
@@ -817,6 +816,7 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
(declare-function org-get-buffer-tags "org")
(declare-function org-global-tags-completion-table "org")
(declare-function org-agenda-files "org")
+(declare-function org-agenda-set-tags "org-agenda")
;;;###autoload
(defun counsel-org-tag ()
diff --git a/ivy.el b/ivy.el
index 10f1d6c..55005de 100644
--- a/ivy.el
+++ b/ivy.el
@@ -237,6 +237,13 @@ When non-nil, it should contain one %d.")
,@body))
(minibuffer-keyboard-quit)))
+(defmacro with-ivy-window (&rest body)
+ "Execute BODY in the window from which `ivy-read' was called."
+ (declare (indent 0)
+ (debug t))
+ `(with-selected-window (ivy-state-window ivy-last)
+ ,@body))
+
(defun ivy--done (text)
"Insert TEXT and exit minibuffer."
(if (and ivy--directory
@@ -1599,7 +1606,7 @@ BUFFER may be a string or nil."
"Pull next word from buffer into search string."
(interactive)
(let (amend)
- (with-selected-window (ivy-state-window ivy-last)
+ (with-ivy-window
(let ((pt (point))
(le (line-end-position)))
(forward-word 1)
diff --git a/swiper.el b/swiper.el
index e7bd574..1032f04 100644
--- a/swiper.el
+++ b/swiper.el
@@ -83,9 +83,6 @@
map)
"Keymap for swiper.")
-(defvar swiper--window nil
- "Store the current window.")
-
(defun swiper-query-replace ()
"Start `query-replace' with string to replace from last search string."
(interactive)
@@ -96,7 +93,7 @@
(to (query-replace-read-to from "Query replace" t)))
(delete-minibuffer-contents)
(ivy-set-action (lambda (_)
- (with-selected-window swiper--window
+ (with-ivy-window
(move-beginning-of-line 1)
(perform-replace from to
t t nil))))
@@ -115,7 +112,7 @@
"Jump to one of the current swiper candidates."
(interactive)
(unless (string= ivy-text "")
- (with-selected-window (ivy-state-window ivy-last)
+ (with-ivy-window
(let* ((avy-all-windows nil)
(candidates
(avy--regex-candidates
@@ -127,9 +124,9 @@
(avy-action-goto candidate))))))
(defun swiper-recenter-top-bottom (&optional arg)
- "Call (`recenter-top-bottom' ARG) in `swiper--window'."
+ "Call (`recenter-top-bottom' ARG)."
(interactive "P")
- (with-selected-window swiper--window
+ (with-ivy-window
(recenter-top-bottom arg)))
(defun swiper-font-lock-ensure ()
@@ -201,8 +198,7 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
"Perform initialization common to both completion methods."
(setq swiper--opoint (point))
(setq swiper--len 0)
- (setq swiper--anchor (line-number-at-pos))
- (setq swiper--window (selected-window)))
+ (setq swiper--anchor (line-number-at-pos)))
(defun swiper--re-builder (str)
"Transform STR into a swiper regex.
@@ -282,13 +278,13 @@ Please remove it and update the \"swiper\" package."))
(defun swiper--update-input-ivy ()
"Called when `ivy' input is updated."
- (swiper--cleanup)
- (let* ((re (ivy--regex ivy-text))
- (str ivy--current)
- (num (if (string-match "^[0-9]+" str)
- (string-to-number (match-string 0 str))
- 0)))
- (with-selected-window swiper--window
+ (with-ivy-window
+ (swiper--cleanup)
+ (let* ((re (ivy--regex ivy-text))
+ (str ivy--current)
+ (num (if (string-match "^[0-9]+" str)
+ (string-to-number (match-string 0 str))
+ 0)))
(goto-char (point-min))
(when (cl-plusp num)
(goto-char (point-min))
@@ -301,7 +297,7 @@ Please remove it and update the \"swiper\" package."))
(isearch-range-invisible (line-beginning-position)
(line-end-position))
(unless (and (>= (point) (window-start))
- (<= (point) (window-end swiper--window t)))
+ (<= (point) (window-end (ivy-state-window ivy-last) t)))
(recenter)))
(swiper--add-overlays re))))
@@ -312,39 +308,39 @@ BEG and END, when specified, are the point bounds."
(line-beginning-position)
(1+ (line-end-position)))))
(overlay-put ov 'face 'swiper-line-face)
- (overlay-put ov 'window swiper--window)
- (push ov swiper--overlays))
- (let* ((wh (window-height))
- (beg (or beg (save-excursion
- (forward-line (- wh))
- (point))))
- (end (or end (save-excursion
- (forward-line wh)
- (point)))))
- (when (>= (length re) swiper-min-highlight)
- (save-excursion
- (goto-char beg)
- ;; RE can become an invalid regexp
- (while (and (ignore-errors (re-search-forward re end t))
- (> (- (match-end 0) (match-beginning 0)) 0))
- (let ((i 0))
- (while (<= i ivy--subexps)
- (when (match-beginning i)
- (let ((overlay (make-overlay (match-beginning i)
- (match-end i)))
- (face
- (cond ((zerop ivy--subexps)
- (cadr swiper-faces))
- ((zerop i)
- (car swiper-faces))
- (t
- (nth (1+ (mod (+ i 2) (1- (length
swiper-faces))))
- swiper-faces)))))
- (push overlay swiper--overlays)
- (overlay-put overlay 'face face)
- (overlay-put overlay 'window swiper--window)
- (overlay-put overlay 'priority i)))
- (cl-incf i))))))))
+ (overlay-put ov 'window (ivy-state-window ivy-last))
+ (push ov swiper--overlays)
+ (let* ((wh (window-height))
+ (beg (or beg (save-excursion
+ (forward-line (- wh))
+ (point))))
+ (end (or end (save-excursion
+ (forward-line wh)
+ (point)))))
+ (when (>= (length re) swiper-min-highlight)
+ (save-excursion
+ (goto-char beg)
+ ;; RE can become an invalid regexp
+ (while (and (ignore-errors (re-search-forward re end t))
+ (> (- (match-end 0) (match-beginning 0)) 0))
+ (let ((i 0))
+ (while (<= i ivy--subexps)
+ (when (match-beginning i)
+ (let ((overlay (make-overlay (match-beginning i)
+ (match-end i)))
+ (face
+ (cond ((zerop ivy--subexps)
+ (cadr swiper-faces))
+ ((zerop i)
+ (car swiper-faces))
+ (t
+ (nth (1+ (mod (+ i 2) (1- (length
swiper-faces))))
+ swiper-faces)))))
+ (push overlay swiper--overlays)
+ (overlay-put overlay 'face face)
+ (overlay-put overlay 'window (ivy-state-window ivy-last))
+ (overlay-put overlay 'priority i)))
+ (cl-incf i)))))))))
(defun swiper--action (x input)
"Goto line X and search for INPUT."
- [elpa] master 5b61577 49/63: Use recoll -t instead of recollq, (continued)
- [elpa] master 5b61577 49/63: Use recoll -t instead of recollq, Oleh Krehel, 2015/08/21
- [elpa] master 8d82b98 51/63: swiper.el (swiper-from-isearch): New command, Oleh Krehel, 2015/08/21
- [elpa] master dba4e47 50/63: counsel.el (org-bound-and-true-p): Update declare, Oleh Krehel, 2015/08/21
- [elpa] master 1f0c79b 52/63: counsel.el (org-setting-tags): Declare dynamic var, Oleh Krehel, 2015/08/21
- [elpa] master 40c17b4 54/63: Add a few more Org declarations, Oleh Krehel, 2015/08/21
- [elpa] master 13d0c50 56/63: counsel.el (counsel-org-tag-agenda): New command, Oleh Krehel, 2015/08/21
- [elpa] master b8b951b 59/63: Allow ivy-count-format to be set as nil, Oleh Krehel, 2015/08/21
- [elpa] master a33af29 55/63: counsel.el (org-bound-and-true-p): Use bound-and-true-p, Oleh Krehel, 2015/08/21
- [elpa] master 6b57efe 57/63: Bind "C-M-j" to ivy-immediate-done, Oleh Krehel, 2015/08/21
- [elpa] master be989fe 60/63: Preselect perfect matches with a leading ^, Oleh Krehel, 2015/08/21
- [elpa] master 476fc5d 58/63: Add with-ivy-window macro,
Oleh Krehel <=
- [elpa] master 4443a8b 53/63: counsel.el (org-last-tags-completion-table): Declare, Oleh Krehel, 2015/08/21
- [elpa] master 098bec0 61/63: counsel.el (counsel-find-file): Fix window focus issue, Oleh Krehel, 2015/08/21
- [elpa] master 09f86fc 62/63: doc/Changelog.org: Add, Oleh Krehel, 2015/08/21
- [elpa] master f5dac47 63/63: Merge commit '09f86fca437f1b2e168093824e9d4ee0aea5130a' from swiper, Oleh Krehel, 2015/08/21