Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avy、swiper、counselについて最近の仕様変更に伴うPR #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions avy-migemo-e.g.counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ This function will be used for `counsel-unquote-regex-parens-migemo'."
"Replace the backslash of \\\\| with empty string in STR.
after `counsel-unquote-regex-parens'."
(replace-regexp-in-string "\\(\\\\\\)|" ""
(counsel-unquote-regex-parens str) nil nil 1))
(counsel--elisp-to-pcre str) nil nil 1))
(byte-compile 'counsel-unquote-regex-parens-migemo-default)

(defun counsel-unquote-regex-parens-migemo (str)
Expand Down Expand Up @@ -144,7 +144,7 @@ after `counsel-unquote-regex-parens'."
"The same as `counsel-ag-function' except for using migemo."
(when (null extra-pt-args)
(setq extra-pt-args ""))
(or (counsel-more-chars)
(or (ivy-more-chars)
(let ((default-directory (ivy-state-directory ivy-last))
(regex (counsel-unquote-regex-parens-migemo ; Adapt for migemo
(setq ivy--old-re
Expand Down Expand Up @@ -236,7 +236,7 @@ after `counsel-unquote-regex-parens'."

(defun counsel-grep-function-migemo (string)
"The same as `counsel-grep-function' except for using migemo."
(or (counsel-more-chars)
(or (ivy-more-chars)
(let ((regex (counsel-unquote-regex-parens-migemo ; Adapt for migemo
(setq ivy--old-re
(ivy--regex-migemo string))))
Expand Down
30 changes: 15 additions & 15 deletions avy-migemo-e.g.swiper.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If nil, `swiper-min-highlight' will be used."
:type '(choice integer
(const :tag "Use `swiper-min-highlight'." nil)))

(defun swiper--add-overlays-migemo-visible-regions (beg end)
(defun swiper--make-overlays-migemo-visible-regions (beg end)
"Return visible regions between BEG and END."
(let ((pt beg)
npt
Expand All @@ -48,10 +48,10 @@ If nil, `swiper-min-highlight' will be used."
(unless (invisible-p pt) (push (cons pt npt) regions))
(setq pt npt))
(nreverse regions)))
(byte-compile 'swiper--add-overlays-migemo-visible-regions)
(byte-compile 'swiper--make-overlays-migemo-visible-regions)

(defun swiper--add-overlays-migemo-ignore-order (re-seq &optional beg end wnd)
"Add overlays at lines matched by RE-SEQ from BEG to END on WND.
(defun swiper--make-overlays-migemo-ignore-order (re-seq &optional beg end wnd)
"Make overlays at lines matched by RE-SEQ from BEG to END on WND.
RE-SEQ is a list of \(regex . boolean)."
(setq wnd (or wnd (ivy-state-window ivy-last)))
(cl-macrolet ((lbeg-pos () '(if visual-line-mode
Expand Down Expand Up @@ -86,24 +86,24 @@ RE-SEQ is a list of \(regex . boolean)."
(setq lbeg (max (lbeg-pos) beg))
(setq lend (min (lend-pos) end))))
(cl-loop
for (lbeg . lend) in (swiper--add-overlays-migemo-visible-regions lbeg lend) do
for (lbeg . lend) in (swiper--make-overlays-migemo-visible-regions lbeg lend) do
(cl-loop
with i-face = 1
for (re . match-p) in re-seq do
(goto-char lbeg)
(while (and match-p
(re-search-forward re lend t))
(swiper--add-overlay
(swiper--make-overlay
(match-beginning 0) (match-end 0)
(nth (1+ (mod (+ i-face 2) (1- (length swiper-faces))))
swiper-faces)
wnd i-face))
(when match-p (cl-incf i-face)))))
(goto-char lend)))))))
(byte-compile 'swiper--add-overlays-migemo-ignore-order)
(byte-compile 'swiper--make-overlays-migemo-ignore-order)

(defun swiper--add-overlays-migemo (re &optional beg end wnd)
"The same as `swiper--add-overlays' except adapting it for migemo's regexp."
(defun swiper--make-overlays-migemo (re &optional beg end wnd)
"The same as `swiper--make-overlays' except adapting it for migemo's regexp."
(setq wnd (or wnd (ivy-state-window ivy-last)))
(let ((ov (if visual-line-mode
(make-overlay
Expand All @@ -130,11 +130,11 @@ RE-SEQ is a list of \(regex . boolean)."
(>= (length ivy-text) swiper-migemo-min-highlight)
(>= (length re) swiper-min-highlight))
(if (eq ivy--regex-function 'ivy--regex-ignore-order)
(swiper--add-overlays-migemo-ignore-order
(swiper--make-overlays-migemo-ignore-order
(ivy--regex-ignore-order ivy-text) beg end wnd)
(save-excursion
(cl-loop
for (beg . end) in (swiper--add-overlays-migemo-visible-regions beg end) do
for (beg . end) in (swiper--make-overlays-migemo-visible-regions beg end) do
(goto-char beg)
;; RE can become an invalid regexp
(while (and (ignore-errors (re-search-forward re end t))
Expand All @@ -150,7 +150,7 @@ RE-SEQ is a list of \(regex . boolean)."
(let ((mb (match-beginning 0))
(me (match-end 0)))
(unless (> (- me mb) 2017)
(swiper--add-overlay mb me
(swiper--make-overlay mb me
(if (zerop ivy--subexps)
(cadr swiper-faces)
(car swiper-faces))
Expand All @@ -170,14 +170,14 @@ RE-SEQ is a list of \(regex . boolean)."
(setq c-mbeg (or c-mbeg mbeg))
(unless (and (match-beginning (1+ i))
(= mend (match-beginning (1+ i))))
(swiper--add-overlay
(swiper--make-overlay
mbeg (setq l-mend mend)
(nth (1+ (mod (+ i-face 2) (1- (length swiper-faces))))
swiper-faces)
wnd i-face)
(setq c-mbeg nil)
(cl-incf i-face)))))))))))
(byte-compile 'swiper--add-overlays-migemo)
(byte-compile 'swiper--make-overlays-migemo)

(defvar search-default-mode)
(defun swiper--re-builder-migemo-around (fn &rest args)
Expand All @@ -187,7 +187,7 @@ RE-SEQ is a list of \(regex . boolean)."
(byte-compile 'swiper--re-builder-migemo-around)

;; For using with avy-migemo-mode
(avy-migemo-add-names 'swiper--add-overlays-migemo
(avy-migemo-add-names 'swiper--make-overlays-migemo
'(swiper--re-builder
:around swiper--re-builder-migemo-around))

Expand Down
35 changes: 17 additions & 18 deletions avy-migemo.el
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,12 @@ BEG / LEN is an integer."
(interactive (list (read-char "char: " t)
current-prefix-arg))
(avy-with avy-goto-char
(avy--generic-jump
(avy-jump
(if (= 13 char)
"\n"
;; Adapt for migemo
(avy-migemo-regex-quote-concat (string char)))
arg
avy-style)))
:window-flip arg)))

;;;###autoload
(defun avy-migemo-goto-char-2 (char1 char2 &optional arg beg end)
Expand All @@ -576,32 +575,32 @@ BEG / LEN is an integer."
(read-char "char 2: " t)
current-prefix-arg
nil nil))
(when (eq char1 ?)
(when (eq char1 ?
)
(setq char1 ?\n))
(when (eq char2 ?)
(when (eq char2 ?
)
(setq char2 ?\n))
(avy-with avy-goto-char-2
(avy--generic-jump
(avy-jump
;; Adapt for migemo
(if (eq char1 ?\n)
(concat (string char1) (avy-migemo-regex-quote-concat (string char2)))
(avy-migemo-regex-quote-concat (string char1 char2)))
arg
avy-style
beg end)))
:window-flip arg
:beg beg :end end)))

;;;###autoload
(defun avy-migemo-goto-char-in-line (char)
"The same as `avy-goto-char-in-line' except for the candidates via migemo."
(interactive (list (read-char "char: " t)))
(avy-with avy-goto-char
(avy--generic-jump
(avy-jump
;; Adapt for migemo
(avy-migemo-regex-quote-concat (string char))
avy-all-windows
avy-style
(line-beginning-position)
(line-end-position))))
:window-flip avy-all-windows
:beg (line-beginning-position)
:end (line-end-position))))

(defun avy-migemo--read-candidates (&optional re-builder group)
"The same as `avy--read-candidates' except for the candidates via migemo.
Expand Down Expand Up @@ -679,7 +678,7 @@ If GROUP is no-nil, the group will be highlighted. Default value is 0."
(not avy-all-windows)
avy-all-windows)))
(avy-with avy-goto-char-timer
(avy--process
(avy-process
;; Adapt for migemo
(avy-migemo--read-candidates)
(avy--style-fn avy-style)))))
Expand Down Expand Up @@ -719,7 +718,7 @@ If GROUP is no-nil, the group will be highlighted. Default value is 0."
(concat
"\\b"
(avy-migemo-regex-concat str))))))
(avy--generic-jump regex arg avy-style beg end))))
(avy-jump regex :window-flip arg :beg beg :end end))))

(defcustom avy-migemo-use-isearch-search-fun nil
"If non-nil, `avy-migemo-isearch' uses `isearch-search-fun'."
Expand Down Expand Up @@ -771,7 +770,7 @@ If GROUP is no-nil, the group will be highlighted. Default value is 0."
(avy-with avy-isearch
(let ((avy-background nil))
;; Adapt for migemo
(avy--process (if avy-migemo-use-isearch-search-fun
(avy-process (if avy-migemo-use-isearch-search-fun
(avy-migemo--isearch-candidates isearch-string)
(avy--regex-candidates
(avy-migemo-regex-concat isearch-string)))
Expand All @@ -789,7 +788,7 @@ If GROUP is no-nil, the group will be highlighted. Default value is 0."
(not avy-all-windows)
avy-all-windows)))
(avy-with avy-goto-char-timer
(avy--process
(avy-process
;; Addapt for migemo
(avy-migemo--read-candidates
(lambda (input)
Expand Down