emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ivy-hydra 6a576cb 293/395: ivy-avy.el: Extract


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra 6a576cb 293/395: ivy-avy.el: Extract
Date: Thu, 25 Feb 2021 08:32:23 -0500 (EST)

branch: externals/ivy-hydra
commit 6a576cba564ab8860142f9ec343b13ec89cc2440
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    ivy-avy.el: Extract
---
 ivy-avy.el  | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ivy-test.el |   2 +-
 ivy.el      |  87 ---------------------------------------------------
 3 files changed, 102 insertions(+), 88 deletions(-)

diff --git a/ivy-avy.el b/ivy-avy.el
new file mode 100644
index 0000000..8939da5
--- /dev/null
+++ b/ivy-avy.el
@@ -0,0 +1,101 @@
+;;; ivy-avy.el --- Avy integration for Ivy -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020  Free Software Foundation, Inc.
+
+;; Author: Oleh Krehel <ohwoeowho@gmail.com>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ivy)
+(require 'avy)
+
+(defcustom ivy-avy-style 'pre
+  "The `avy-style' setting for `ivy-avy'."
+  :type '(choice
+          (const :tag "Pre" pre)
+          (const :tag "At" at)
+          (const :tag "At Full" at-full)
+          (const :tag "Post" post)
+          (const :tag "De Bruijn" de-bruijn)
+          (const :tag "Words" words))
+  :group 'ivy)
+
+(defun ivy--avy-candidates ()
+  (let (candidates)
+    (save-excursion
+      (save-restriction
+        (narrow-to-region
+         (window-start)
+         (window-end))
+        (goto-char (point-min))
+        (forward-line)
+        (while (< (point) (point-max))
+          (push
+           (cons (point)
+                 (selected-window))
+           candidates)
+          (forward-line))))
+    (nreverse candidates)))
+
+(defun ivy--avy-action (pt)
+  (when (number-or-marker-p pt)
+    (let ((bnd (ivy--minibuffer-index-bounds
+                ivy--index ivy--length ivy-height)))
+      (ivy--done
+       (substring-no-properties
+        (nth (+ (car bnd) (- (line-number-at-pos pt) 2)) ivy--old-cands))))))
+
+(defun ivy--avy-handler-function (char)
+  (let (cmd)
+    (cond ((memq char '(?\C-\[ ?\C-g))
+           ;; exit silently
+           (throw 'done 'abort))
+          ((memq (setq cmd (lookup-key ivy-minibuffer-map (vector char)))
+                 '(ivy-scroll-up-command
+                   ivy-scroll-down-command))
+           (funcall cmd)
+           (ivy--exhibit)
+           (throw 'done 'exit))
+          ;; ignore wrong key
+          (t
+           (throw 'done 'restart)))))
+
+(defun ivy-avy ()
+  "Jump to one of the current ivy candidates."
+  (interactive)
+  (if (= (minibuffer-depth) 0)
+      (user-error
+       "This command is intended to be called from within `ivy-read'")
+    (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))
+           (avy-action #'identity)
+           (avy-handler-function #'ivy--avy-handler-function)
+           res)
+      (while (eq (setq res (avy-process (ivy--avy-candidates))) t))
+      (when res
+        (ivy--avy-action res)))))
+
+(put 'ivy-avy 'no-counsel-M-x t)
+(define-key ivy-minibuffer-map (kbd "C-'") 'ivy-avy)
+(add-to-list 'avy-styles-alist `(ivy-avy . ,ivy-avy-style))
+
+(provide 'ivy-avy)
diff --git a/ivy-test.el b/ivy-test.el
index 3d1a5cb..88243cf 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1529,7 +1529,7 @@ a buffer visiting a file."
             '("one" "two"))))
 
 (ert-deftest ivy-avy ()
-  (when (require 'avy nil t)
+  (when (require 'ivy-avy nil t)
     (let ((enable-recursive-minibuffers t)
           (read-numbers '(ivy-read "test: " (mapcar #'number-to-string 
(number-sequence 1 100)))))
       (should (string= (ivy-with read-numbers "C-' a") "1"))
diff --git a/ivy.el b/ivy.el
index 8587a79..05bed29 100644
--- a/ivy.el
+++ b/ivy.el
@@ -457,7 +457,6 @@ action functions.")
     (define-key map [remap kill-whole-line] 'ivy-kill-whole-line)
     (define-key map (kbd "S-SPC") 'ivy-restrict-to-matches)
     (define-key map [remap kill-ring-save] 'ivy-kill-ring-save)
-    (define-key map (kbd "C-'") 'ivy-avy)
     (define-key map (kbd "C-M-a") 'ivy-read-action)
     (define-key map (kbd "C-c C-o") 'ivy-occur)
     (define-key map (kbd "C-c C-a") 'ivy-toggle-ignore)
@@ -1808,15 +1807,6 @@ minibuffer."
   (cl-rotatef ivy--regex-function ivy--regexp-quote)
   (setq ivy-regex (funcall ivy--regex-function ivy-text)))
 
-(defvar avy-all-windows)
-(defvar avy-action)
-(defvar avy-keys)
-(defvar avy-keys-alist)
-(defvar avy-style)
-(defvar avy-styles-alist)
-(declare-function avy-process "ext:avy")
-(declare-function avy--style-fn "ext:avy")
-
 (defcustom ivy-format-functions-alist
   '((t . ivy-format-function-default))
   "An alist of functions that transform the list of candidates into a string.
@@ -1830,83 +1820,6 @@ This string is inserted into the minibuffer."
            (const :tag "Full line" ivy-format-function-line)
            (function :tag "Custom function"))))
 
-(defcustom ivy-avy-style 'pre
-  "The `avy-style' setting for `ivy-avy'."
-  :type '(choice
-          (const :tag "Pre" pre)
-          (const :tag "At" at)
-          (const :tag "At Full" at-full)
-          (const :tag "Post" post)
-          (const :tag "De Bruijn" de-bruijn)
-          (const :tag "Words" words)))
-
-(with-eval-after-load 'avy
-  (add-to-list 'avy-styles-alist `(ivy-avy . ,ivy-avy-style)))
-
-(defun ivy--avy-candidates ()
-  (let (candidates)
-    (save-excursion
-      (save-restriction
-        (narrow-to-region
-         (window-start)
-         (window-end))
-        (goto-char (point-min))
-        (forward-line)
-        (while (< (point) (point-max))
-          (push
-           (cons (point)
-                 (selected-window))
-           candidates)
-          (forward-line))))
-    (nreverse candidates)))
-
-(defun ivy--avy-action (pt)
-  (when (number-or-marker-p pt)
-    (let ((bnd (ivy--minibuffer-index-bounds
-                ivy--index ivy--length ivy-height)))
-      (ivy--done
-       (substring-no-properties
-        (nth (+ (car bnd) (- (line-number-at-pos pt) 2)) ivy--old-cands))))))
-
-(defun ivy--avy-handler-function (char)
-  (let (cmd)
-    (cond ((memq char '(?\C-\[ ?\C-g))
-           ;; exit silently
-           (throw 'done 'abort))
-          ((memq (setq cmd (lookup-key ivy-minibuffer-map (vector char)))
-                 '(ivy-scroll-up-command
-                   ivy-scroll-down-command))
-           (funcall cmd)
-           (ivy--exhibit)
-           (throw 'done 'exit))
-          ;; ignore wrong key
-          (t
-           (throw 'done 'restart)))))
-
-(defvar avy-handler-function)
-
-(defun ivy-avy ()
-  "Jump to one of the current ivy candidates."
-  (interactive)
-  (cond ((not (require 'avy nil 'noerror))
-         (error "Package avy isn't installed"))
-        ((= (minibuffer-depth) 0)
-         (user-error
-          "This command is intended to be called from within `ivy-read'"))
-        (t
-         (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))
-                (avy-action #'identity)
-                (avy-handler-function #'ivy--avy-handler-function)
-                res)
-           (while (eq (setq res (avy-process (ivy--avy-candidates))) t))
-           (when res
-             (ivy--avy-action res))))))
-(put 'ivy-avy 'no-counsel-M-x t)
-
 (defun ivy-sort-file-function-default (x y)
   "Compare two files X and Y.
 Prioritize directories."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]