(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))
(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)))))))
(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)
(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 ()
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)
(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))))
"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
(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 ()
"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.
(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))
(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))))
(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."