|
4 | 4 |
|
5 | 5 | ;; Author: Oleh Krehel < [email protected]> |
6 | 6 | ;; URL: https://github.com/abo-abo/swiper |
7 | | -;; Version: 0.13.4 |
| 7 | +;; Version: 0.13.5 |
8 | 8 | ;; Package-Requires: ((emacs "24.5")) |
9 | 9 | ;; Keywords: matching |
10 | 10 |
|
@@ -303,8 +303,8 @@ action functions.") |
303 | 303 | (require 'delsel) |
304 | 304 | (defun ivy-define-key (keymap key def) |
305 | 305 | "Forward to (`define-key' KEYMAP KEY DEF). |
306 | | -Remove DEF from `counsel-M-x' list." |
307 | | - (put def 'no-counsel-M-x t) |
| 306 | +Remove DEF (a function symbol) from `counsel-M-x' completion." |
| 307 | + (function-put def 'no-counsel-M-x t) |
308 | 308 | (define-key keymap key def)) |
309 | 309 |
|
310 | 310 | (defvar ivy-minibuffer-map |
@@ -353,6 +353,7 @@ Remove DEF from `counsel-M-x' list." |
353 | 353 | (ivy-define-key map [remap kill-whole-line] 'ivy-kill-whole-line) |
354 | 354 | (ivy-define-key map (kbd "S-SPC") 'ivy-restrict-to-matches) |
355 | 355 | (ivy-define-key map [remap kill-ring-save] 'ivy-kill-ring-save) |
| 356 | + (ivy-define-key map (kbd "C-'") 'ivy-avy) |
356 | 357 | (ivy-define-key map (kbd "C-M-a") 'ivy-read-action) |
357 | 358 | (ivy-define-key map (kbd "C-c C-o") 'ivy-occur) |
358 | 359 | (ivy-define-key map (kbd "C-c C-a") 'ivy-toggle-ignore) |
@@ -1710,6 +1711,84 @@ This string is inserted into the minibuffer." |
1710 | 1711 | ivy-format-function-arrow-line) |
1711 | 1712 | (function :tag "Custom function")))) |
1712 | 1713 |
|
| 1714 | +(defcustom ivy-avy-style 'pre |
| 1715 | + "The `avy-style' setting for `ivy-avy'." |
| 1716 | + :type '(choice |
| 1717 | + (const :tag "Pre" pre) |
| 1718 | + (const :tag "At" at) |
| 1719 | + (const :tag "At Full" at-full) |
| 1720 | + (const :tag "Post" post) |
| 1721 | + (const :tag "De Bruijn" de-bruijn) |
| 1722 | + (const :tag "Words" words) |
| 1723 | + (const :tag "Default" nil))) |
| 1724 | + |
| 1725 | +(defun ivy--avy-candidates () |
| 1726 | + "List of candidates for `ivy-avy'." |
| 1727 | + (let (candidates) |
| 1728 | + (save-excursion |
| 1729 | + (save-restriction |
| 1730 | + (narrow-to-region (window-start) (window-end)) |
| 1731 | + (goto-char (point-min)) |
| 1732 | + (forward-line) |
| 1733 | + (while (< (point) (point-max)) |
| 1734 | + (push (cons (point) (selected-window)) |
| 1735 | + candidates) |
| 1736 | + (forward-line)))) |
| 1737 | + (nreverse candidates))) |
| 1738 | + |
| 1739 | +(defun ivy--avy-action (pt) |
| 1740 | + "Select the candidate represented by PT." |
| 1741 | + (when (number-or-marker-p pt) |
| 1742 | + (let ((bnd (ivy--minibuffer-index-bounds |
| 1743 | + ivy--index ivy--length ivy-height))) |
| 1744 | + (ivy--done |
| 1745 | + (substring-no-properties |
| 1746 | + (nth (+ (car bnd) (- (line-number-at-pos pt) 2)) ivy--old-cands)))))) |
| 1747 | + |
| 1748 | +(defun ivy--avy-handler-function (char) |
| 1749 | + "Handle CHAR that's not on `avy-keys'." |
| 1750 | + (cond ((memql char '(?\C-\[ ?\C-g)) |
| 1751 | + ;; Exit silently. |
| 1752 | + (throw 'done 'abort)) |
| 1753 | + ((let ((cmd (lookup-key ivy-minibuffer-map (vector char)))) |
| 1754 | + (when (memq cmd '(ivy-scroll-up-command |
| 1755 | + ivy-scroll-down-command)) |
| 1756 | + (funcall cmd) |
| 1757 | + (ivy--exhibit) |
| 1758 | + (throw 'done 'exit)))) |
| 1759 | + ;; Ignore wrong key. |
| 1760 | + ((throw 'done 'restart)))) |
| 1761 | + |
| 1762 | +(defun ivy-avy () |
| 1763 | + "Jump to one of the current `ivy' candidates with `avy'." |
| 1764 | + (interactive) |
| 1765 | + (unless (require 'avy nil t) |
| 1766 | + (user-error "Package `avy' is not installed")) |
| 1767 | + (when (zerop (minibuffer-depth)) |
| 1768 | + (user-error |
| 1769 | + "Command `ivy-avy' is intended to be called from within `ivy-read'")) |
| 1770 | + (defvar avy-action) |
| 1771 | + (defvar avy-all-windows) |
| 1772 | + (defvar avy-handler-function) |
| 1773 | + (defvar avy-keys) |
| 1774 | + (defvar avy-keys-alist) |
| 1775 | + (defvar avy-style) |
| 1776 | + (defvar avy-styles-alist) |
| 1777 | + (declare-function avy-process "avy" |
| 1778 | + (candidates &optional overlay-fn cleanup-fn)) |
| 1779 | + (let ((avy-all-windows nil) |
| 1780 | + (avy-keys (or (cdr (assq #'ivy-avy avy-keys-alist)) |
| 1781 | + avy-keys)) |
| 1782 | + (avy-style (or ivy-avy-style |
| 1783 | + (cdr (assq #'ivy-avy avy-styles-alist)) |
| 1784 | + avy-style)) |
| 1785 | + (avy-action #'identity) |
| 1786 | + (avy-handler-function #'ivy--avy-handler-function) |
| 1787 | + res) |
| 1788 | + (while (eq (setq res (avy-process (ivy--avy-candidates))) t)) |
| 1789 | + (when res |
| 1790 | + (ivy--avy-action res)))) |
| 1791 | + |
1713 | 1792 | (defun ivy-sort-file-function-default (x y) |
1714 | 1793 | "Compare two files X and Y. |
1715 | 1794 | Prioritize directories." |
|
0 commit comments