update packages
This commit is contained in:
132
lisp/swiper.el
132
lisp/swiper.el
@@ -1,13 +1,13 @@
|
||||
;;; swiper.el --- Isearch with an overview. Oh, man! -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2015-2020 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2015-2021 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Oleh Krehel <ohwoeowho@gmail.com>
|
||||
;; URL: https://github.com/abo-abo/swiper
|
||||
;; Package-Version: 20201208.1419
|
||||
;; Package-Commit: 71c59aecf669142ebe264fac8ff7b440c0c71712
|
||||
;; Version: 0.13.0
|
||||
;; Package-Requires: ((emacs "24.5") (ivy "0.13.0"))
|
||||
;; Package-Version: 20210919.1221
|
||||
;; Package-Commit: c97ea72285f2428ed61b519269274d27f2b695f9
|
||||
;; Version: 0.13.4
|
||||
;; Package-Requires: ((emacs "24.5") (ivy "0.13.4"))
|
||||
;; Keywords: matching
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
@@ -334,19 +334,28 @@ If the input is empty, select the previous history element instead."
|
||||
(avy-push-mark))
|
||||
(avy--done))))
|
||||
|
||||
(defun swiper--avy-index (pos)
|
||||
"Return `ivy--index' for `avy' candidate at minibuffer POS."
|
||||
;; Position in original buffer.
|
||||
(let ((opos (get-text-property pos 'point)))
|
||||
(or
|
||||
;; Find `swiper-isearch' index based on buffer position.
|
||||
(and opos (cl-position opos ivy--all-candidates))
|
||||
;; Find `swiper' index based on line number.
|
||||
(let ((nlines (count-lines (point-min) (point-max))))
|
||||
(+ (car (ivy--minibuffer-index-bounds
|
||||
ivy--index ivy--length ivy-height))
|
||||
(line-number-at-pos pos)
|
||||
(if (or (= nlines (1+ ivy-height))
|
||||
(< ivy--length ivy-height))
|
||||
0
|
||||
(- ivy-height nlines))
|
||||
-2)))))
|
||||
|
||||
(defun swiper--avy-goto (candidate)
|
||||
(cond ((let ((win (cdr-safe candidate)))
|
||||
(and win (window-minibuffer-p win)))
|
||||
(let ((nlines (count-lines (point-min) (point-max))))
|
||||
(ivy-set-index
|
||||
(+ (car (ivy--minibuffer-index-bounds
|
||||
ivy--index ivy--length ivy-height))
|
||||
(line-number-at-pos (car candidate))
|
||||
(if (or (= nlines (1+ ivy-height))
|
||||
(< ivy--length ivy-height))
|
||||
0
|
||||
(- ivy-height nlines))
|
||||
-2)))
|
||||
(setq ivy--index (swiper--avy-index (car candidate)))
|
||||
(ivy--exhibit)
|
||||
(ivy-done)
|
||||
(ivy-call))
|
||||
@@ -357,16 +366,19 @@ If the input is empty, select the previous history element instead."
|
||||
|
||||
;;;###autoload
|
||||
(defun swiper-avy ()
|
||||
"Jump to one of the current swiper candidates."
|
||||
"Jump to one of the current swiper candidates with `avy'."
|
||||
(interactive)
|
||||
(unless (require 'avy nil 'noerror)
|
||||
(error "Package avy isn't installed"))
|
||||
(user-error "Package avy isn't installed"))
|
||||
(cl-case (length ivy-text)
|
||||
(0
|
||||
(user-error "Need at least one char of input"))
|
||||
(1
|
||||
(let ((swiper-min-highlight 1))
|
||||
(swiper--update-input-ivy))))
|
||||
;; FIXME: `swiper--update-input-ivy' expects string candidates,
|
||||
;; but `swiper-isearch' now uses buffer positions.
|
||||
(when (stringp (ivy-state-current ivy-last))
|
||||
(let ((swiper-min-highlight 1))
|
||||
(swiper--update-input-ivy)))))
|
||||
(swiper--avy-goto (swiper--avy-candidate)))
|
||||
|
||||
(declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")
|
||||
@@ -1143,11 +1155,11 @@ WND, when specified is the window."
|
||||
(defun swiper-from-isearch ()
|
||||
"Invoke `swiper' from isearch."
|
||||
(interactive)
|
||||
(let ((query (if isearch-regexp
|
||||
isearch-string
|
||||
(regexp-quote isearch-string))))
|
||||
(isearch-exit)
|
||||
(swiper query)))
|
||||
(swiper (prog1 (if isearch-regexp
|
||||
isearch-string
|
||||
(regexp-quote isearch-string))
|
||||
(let ((search-nonincremental-instead nil))
|
||||
(isearch-exit)))))
|
||||
|
||||
(defvar swiper-multi-buffers nil
|
||||
"Store the current list of buffers.")
|
||||
@@ -1400,24 +1412,20 @@ See `ivy-format-functions-alist' for further information."
|
||||
(nreverse cands)))))
|
||||
|
||||
(defun swiper--isearch-next-item (re cands)
|
||||
(if swiper--isearch-backward
|
||||
(or
|
||||
(cl-position-if
|
||||
(lambda (x)
|
||||
(and
|
||||
(< x swiper--isearch-start-point)
|
||||
(eq 0 (string-match-p
|
||||
re
|
||||
(buffer-substring-no-properties
|
||||
x swiper--isearch-start-point)))))
|
||||
cands
|
||||
:from-end t)
|
||||
0)
|
||||
(or
|
||||
(cl-position-if
|
||||
(lambda (x) (> x swiper--isearch-start-point))
|
||||
cands)
|
||||
0)))
|
||||
(or (if swiper--isearch-backward
|
||||
(save-excursion
|
||||
;; Match RE starting at each position in CANDS.
|
||||
(setq re (concat "\\=\\(?:" re "\\)"))
|
||||
(cl-position-if
|
||||
(lambda (x)
|
||||
(when (< x swiper--isearch-start-point)
|
||||
(goto-char x)
|
||||
;; Note: Not quite the same as `looking-at' + `match-end'.
|
||||
(re-search-forward re swiper--isearch-start-point t)))
|
||||
cands
|
||||
:from-end t))
|
||||
(cl-position swiper--isearch-start-point cands :test #'<))
|
||||
0))
|
||||
|
||||
(defun swiper--isearch-filter-ignore-order (re-full cands)
|
||||
(let (filtered-cands)
|
||||
@@ -1475,11 +1483,15 @@ that we search only for one character."
|
||||
(dolist (re (swiper--positive-regexps))
|
||||
(swiper--add-overlays re))))
|
||||
|
||||
(defun swiper--isearch-candidate-pos (cand)
|
||||
"Return the buffer position of `swiper-isearch' CAND, or nil."
|
||||
(cond ((integer-or-marker-p cand) cand)
|
||||
((and (stringp cand) (> (length cand) 0))
|
||||
(get-text-property 0 'point cand))))
|
||||
|
||||
(defun swiper-isearch-action (x)
|
||||
"Move to X for `swiper-isearch'."
|
||||
(if (or (numberp x)
|
||||
(and (> (length x) 0)
|
||||
(setq x (get-text-property 0 'point x))))
|
||||
(if (setq x (swiper--isearch-candidate-pos x))
|
||||
(with-ivy-window
|
||||
(goto-char x)
|
||||
(when (and (or (eq this-command 'ivy-previous-line-or-history)
|
||||
@@ -1489,7 +1501,11 @@ that we search only for one character."
|
||||
(goto-char (match-beginning 0)))
|
||||
(funcall isearch-filter-predicate (point) (1+ (point)))
|
||||
(swiper--maybe-recenter)
|
||||
(if (eq ivy-exit 'done)
|
||||
(if (or (eq ivy-exit 'done)
|
||||
;; FIXME: With the default action 'M-o o', `ivy-exit' remains
|
||||
;; nil for some reason, so check `this-command' instead to
|
||||
;; tell whether we're "done".
|
||||
(eq this-command #'ivy-dispatching-done))
|
||||
(progn
|
||||
(swiper--push-mark)
|
||||
(swiper--remember-search-history (ivy--regex ivy-text)))
|
||||
@@ -1506,7 +1522,20 @@ that we search only for one character."
|
||||
(line-beginning-position) (line-end-position)))
|
||||
(goto-char swiper--opoint))
|
||||
|
||||
(ivy-add-actions 'swiper-isearch '(("w" swiper-action-copy "copy")))
|
||||
(defun swiper-isearch-action-copy (cand)
|
||||
"Save `swiper-isearch' candidate CAND to `kill-ring'.
|
||||
Return to original position."
|
||||
(unwind-protect
|
||||
(progn
|
||||
(unless (and (setq cand (swiper--isearch-candidate-pos cand))
|
||||
;; FIXME: Better way of getting current candidate?
|
||||
(goto-char cand)
|
||||
(looking-back (ivy-re-to-str ivy-regex) (point-min)))
|
||||
(error "Could not copy `swiper-isearch' candidate: %S" cand))
|
||||
(kill-new (match-string 0)))
|
||||
(goto-char swiper--opoint)))
|
||||
|
||||
(ivy-add-actions 'swiper-isearch '(("w" swiper-isearch-action-copy "copy")))
|
||||
(ivy-add-actions 'swiper '(("w" swiper-action-copy "copy")))
|
||||
|
||||
(defun swiper-isearch-thing-at-point ()
|
||||
@@ -1538,10 +1567,19 @@ When not running `swiper-isearch' already, start it."
|
||||
(setq thing (ivy-thing-at-point))))
|
||||
(swiper-isearch thing))))
|
||||
|
||||
(defun swiper-isearch-C-r (&optional arg)
|
||||
"Move cursor vertically up ARG candidates.
|
||||
When the input is empty, browse the search history instead."
|
||||
(interactive "p")
|
||||
(if (string= ivy-text "")
|
||||
(ivy-reverse-i-search)
|
||||
(ivy-previous-line arg)))
|
||||
|
||||
(defvar swiper-isearch-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(set-keymap-parent map swiper-map)
|
||||
(define-key map (kbd "M-n") 'swiper-isearch-thing-at-point)
|
||||
(define-key map (kbd "C-r") 'swiper-isearch-C-r)
|
||||
map)
|
||||
"Keymap for `swiper-isearch'.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user