[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-posframe 9982c6d 052/195: Merge pull request #17 fr
From: |
Feng Shu |
Subject: |
[elpa] externals/ivy-posframe 9982c6d 052/195: Merge pull request #17 from noctuid/ivy-avy |
Date: |
Sat, 3 Oct 2020 07:11:43 -0400 (EDT) |
branch: externals/ivy-posframe
commit 9982c6d62b9e474f56c6a4a1b86e0050e6f6174d
Merge: 3d98dbd b217e00
Author: tumashu <tumashu@163.com>
Commit: GitHub <noreply@github.com>
Merge pull request #17 from noctuid/ivy-avy
Implement ivy-posframe-avy
---
ivy-posframe.el | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 142 insertions(+), 4 deletions(-)
diff --git a/ivy-posframe.el b/ivy-posframe.el
index ce7c97f..0a323d1 100644
--- a/ivy-posframe.el
+++ b/ivy-posframe.el
@@ -287,10 +287,145 @@ selection, non-nil otherwise."
(setcar actions (1+ action-idx))
(ivy-set-action actions)))))))
+(defun ivy-posframe--avy-action (pt)
+ "Finish ivy session with the candidate at PT."
+ (with-current-buffer ivy-posframe-buffer
+ (ivy--done
+ (substring-no-properties
+ (nth (- (line-number-at-pos pt) 2) ivy--old-cands)))))
+
+(defun ivy-posframe--window ()
+ "Return the posframe window displaying `ivy-posframe-buffer'."
+ (frame-selected-window
+ (buffer-local-value 'posframe--frame
+ (get-buffer ivy-posframe-buffer))))
+
+(defvar avy-all-windows)
+(defvar avy-keys)
+(defvar avy-keys-alist)
+(defvar avy-style)
+(defvar avy-styles-alist)
+(defvar avy-action)
+(declare-function avy--process "avy")
+(declare-function avy--style-fn "avy")
(defun ivy-posframe-avy ()
"Jump to one of the current ivy candidates."
(interactive)
- (message "ivy-posframe: ivy-avy is not supported at the moment."))
+ (unless (require 'avy nil 'noerror)
+ (error "Package avy isn't installed"))
+ (unless (boundp 'avy-pre-action)
+ (error "A newer version of avy is required for this command"))
+ (let* ((avy-all-windows nil)
+ (avy-keys (or (cdr (assq 'ivy-avy avy-keys-alist))
+ avy-keys))
+ (avy-style (or (cdr (assq 'ivy-avy
+ avy-styles-alist))
+ avy-style))
+ ;; prevent default pre action, which calls
+ ;; `select-frame-set-input-focus', deselecting the minibuffer and
+ ;; causing `ivy-posframe-cleanup' to run prematurely
+ (avy-pre-action #'ignore)
+ (window (ivy-posframe--window))
+ candidates)
+ (with-current-buffer ivy-posframe-buffer
+ (save-excursion
+ (save-restriction
+ (narrow-to-region
+ (window-start window)
+ (window-end window))
+ (goto-char (point-min))
+ (forward-line)
+ (while (< (point) (point-max))
+ (push (cons (point) window) candidates)
+ (forward-line)))))
+ (setq avy-action #'ivy-posframe--avy-action)
+ (avy--process
+ (nreverse candidates)
+ (avy--style-fn avy-style))))
+
+(declare-function avy--make-backgrounds "avy")
+(declare-function avy-window-list "avy")
+(declare-function avy-read-de-bruijn "avy")
+(declare-function avy-read "avy")
+(declare-function avy-tree "avy")
+(declare-function avy--overlay-post "avy")
+(declare-function avy--remove-leading-chars "avy")
+(declare-function avy-push-mark "avy")
+(declare-function avy--done "avy")
+(defun ivy-posframe--swiper-avy-candidate ()
+ (let* ((avy-all-windows nil)
+ ;; We'll have overlapping overlays, so we sort all the
+ ;; overlays in the visible region by their start, and then
+ ;; throw out non-Swiper overlays or overlapping Swiper
+ ;; overlays.
+ (visible-overlays (cl-sort (with-ivy-window
+ (overlays-in (window-start)
+ (window-end)))
+ #'< :key #'overlay-start))
+ (min-overlay-start 0)
+ (overlays-for-avy (cl-remove-if-not
+ (lambda (ov)
+ (when (and (>= (overlay-start ov)
+ min-overlay-start)
+ (memq (overlay-get ov 'face)
+ swiper-faces))
+ (setq min-overlay-start (overlay-start ov))))
+ visible-overlays))
+ (offset (if (eq (ivy-state-caller ivy-last) 'swiper) 1 0))
+ (window (ivy-posframe--window))
+ (candidates (nconc
+ (mapcar (lambda (ov)
+ (cons (overlay-start ov)
+ (overlay-get ov 'window)))
+ overlays-for-avy)
+ (with-current-buffer ivy-posframe-buffer
+ (save-excursion
+ (save-restriction
+ (narrow-to-region (window-start window)
+ (window-end window))
+ (goto-char (point-min))
+ (forward-line)
+ (let (cands)
+ (while (not (eobp))
+ (push (cons (+ (point) offset) window)
+ cands)
+ (forward-line))
+ cands)))))))
+ (unwind-protect
+ (prog2
+ (avy--make-backgrounds
+ (append (avy-window-list)
+ (list (ivy-state-window ivy-last))))
+ (if (eq avy-style 'de-bruijn)
+ (avy-read-de-bruijn candidates avy-keys)
+ (avy-read (avy-tree candidates avy-keys)
+ #'avy--overlay-post
+ #'avy--remove-leading-chars))
+ (avy-push-mark))
+ (avy--done))))
+
+(declare-function avy-action-goto "avy")
+(declare-function avy-candidate-beg "avy")
+(defun ivy-posframe-swiper-avy ()
+ "Jump to one of the current swiper candidates."
+ (interactive)
+ (unless (require 'avy nil 'noerror)
+ (error "Package avy isn't installed"))
+ (unless (string= ivy-text "")
+ (let ((candidate (ivy-posframe--swiper-avy-candidate)))
+ (if (eq (cdr candidate) (ivy-posframe--window))
+ (let ((cand-text (with-current-buffer ivy-posframe-buffer
+ (save-excursion
+ (goto-char (car candidate))
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))))
+ (ivy-set-index (cl-position cand-text ivy--old-cands :test
#'string=))
+ (ivy--exhibit)
+ (ivy-done)
+ (ivy-call))
+ (ivy-quit-and-run
+ (avy-action-goto (avy-candidate-beg candidate)))))))
(defun ivy-posframe--minibuffer-setup (orig-func)
"Advice function of `ivy--minibuffer-setup'."
@@ -309,9 +444,12 @@ selection, non-nil otherwise."
(interactive)
(require 'ivy)
(ivy-posframe-setup)
- (define-key ivy-minibuffer-map (kbd "C-M-a") 'ivy-posframe-read-action)
- (define-key ivy-minibuffer-map (kbd "M-o") 'ivy-posframe-dispatching-done)
- (define-key ivy-minibuffer-map (kbd "C-'") 'ivy-posframe-avy)
+ (define-key ivy-minibuffer-map
+ [remap ivy-read-action] 'ivy-posframe-read-action)
+ (define-key ivy-minibuffer-map
+ [remap ivy-dispatching-done] 'ivy-posframe-dispatching-done)
+ (define-key ivy-minibuffer-map [remap ivy-avy] 'ivy-posframe-avy)
+ (define-key ivy-minibuffer-map [remap swiper-avy] 'ivy-posframe-swiper-avy)
(advice-add 'ivy--minibuffer-setup :around #'ivy-posframe--minibuffer-setup)
(message "ivy-posframe is enabled, disabling it need to reboot emacs."))
- [elpa] externals/ivy-posframe 8f62984 033/195: Add ivy-posframe-read-action and ivy-posframe-dispatching-done, (continued)
- [elpa] externals/ivy-posframe 8f62984 033/195: Add ivy-posframe-read-action and ivy-posframe-dispatching-done, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 26e3a64 034/195: ivy-posframe: add ivy-posframe-avy, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 0989e42 039/195: Show cursor's position, fix #9, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe b37e713 041/195: Merge pull request #10 from drrlvn/patch-1, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 15d9a9e 043/195: Revert "Set ivy-posframe-cursor as mulitcursor", Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe b92aaa1 046/195: Merge pull request #13 from samrayleung/feature-add-variable, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 8be3311 047/195: ivy-posframe do not support mouse click, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 3d98dbd 048/195: Add ivy-posframe-hide-minibuffer feature, fix #12, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7544bb6 049/195: Implement ivy-posframe-avy, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe b217e00 051/195: Use remaps for all keybindings, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 9982c6d 052/195: Merge pull request #17 from noctuid/ivy-avy,
Feng Shu <=
- [elpa] externals/ivy-posframe 187d14b 053/195: ivy-posframe.el (ivy-posframe--display): Simplify, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7ea96ce 055/195: Merge pull request #19 from abo-abo/master, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 52c8209 057/195: Merge pull request #20 from tumashu/revert-19-master, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 19f1382 059/195: update README, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 05432ef 063/195: fallback width = frame-width * 0.618, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7787514 064/195: ivy-posframe-hide-minibuffer default is t, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 0fdb1b6 066/195: Update snapshots, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 96c2e83 067/195: Update README, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe 7bfd14f 068/195: Add ivy-posframe-border face and use it, Feng Shu, 2020/10/03
- [elpa] externals/ivy-posframe ba42fec 019/195: Fix warn, Feng Shu, 2020/10/03