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

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

[elpa] externals/mct 0cce0e6e7a 1/2: Improve code and docs of mct+avy in


From: ELPA Syncer
Subject: [elpa] externals/mct 0cce0e6e7a 1/2: Improve code and docs of mct+avy integration
Date: Fri, 11 Feb 2022 01:57:38 -0500 (EST)

branch: externals/mct
commit 0cce0e6e7ad684fbd171abf772b351fe42f8475f
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Improve code and docs of mct+avy integration
---
 README.org | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 52 insertions(+), 13 deletions(-)

diff --git a/README.org b/README.org
index c6de10b540..64fa8f19c1 100644
--- a/README.org
+++ b/README.org
@@ -1146,10 +1146,11 @@ not be part of =mct.el=.  Use this in your init file 
instead:
 (advice-add #'completing-read-multiple :filter-args #'my-crm-indicator)
 #+end_src
 
-** Select completion with Avy
+** Select completion candidate with Avy
 :PROPERTIES:
 :CUSTOM_ID: h:18a2a223-8544-4294-b847-012c99003de4
 :END:
+#+cindex: Quick selection with Avy
 
 The =avy= package by Oleh Krehel can be used to quickly select a candidate
 from a visible =*Completions*= buffer.  In the following example, we
@@ -1165,18 +1166,18 @@ activate it with the =C-.= key.
 (defun my-avy-completions-select ()
   "Choose completion and exit using Avy."
   (interactive)
-  (when (mct--get-completion-window)
-    (mct--switch-to-completions)
-    (avy-with avy-completion
-      (let ((avy-action 'my-avy--choose))
-        (avy-process
-         (save-excursion
-           (let (completions)
-             (goto-char (mct--first-completion-point))
-             (while (not (eobp))
-               (push (point) completions)
-               (next-completion 1))
-             (nreverse completions))))))))
+  (when-let ((window (mct--get-completion-window)))
+    (with-selected-window window
+      (avy-with avy-completion
+        (let ((avy-action 'prot/mct-avy--choose))
+          (avy-process
+           (save-excursion
+             (let (completions)
+               (goto-char (mct--first-completion-point))
+               (while (not (eobp))
+                 (push (point) completions)
+                 (next-completion 1))
+               (nreverse completions)))))))))
 
 (dolist (map (list mct-minibuffer-local-completion-map
                    mct-minibuffer-completion-list-map
@@ -1185,6 +1186,44 @@ activate it with the =C-.= key.
   (define-key map (kbd "C-.") #'my-avy-completions-select))
 #+end_src
 
+If you are declaring =mct= before =avsy= in your init file, then the above
+can be wrapped in ~with-eval-after-load~, like this:
+
+#+begin_src emacs-lisp
+(require 'mct)
+
+;; more mct code here
+
+(with-eval-after-load 'avy
+  ;; Adapted from Omar AntolĂ­n Camarena's `avy-embark-collect.el'.
+  (defun my-avy--choose (pt)
+    "Choose completion at PT."
+    (goto-char pt)
+    (mct-choose-completion-exit))
+
+  (defun my-avy-completions-select ()
+    "Choose completion and exit using Avy."
+    (interactive)
+    (when-let ((window (mct--get-completion-window)))
+      (with-selected-window window
+        (avy-with avy-completion
+          (let ((avy-action 'prot/mct-avy--choose))
+            (avy-process
+             (save-excursion
+               (let (completions)
+                 (goto-char (mct--first-completion-point))
+                 (while (not (eobp))
+                   (push (point) completions)
+                   (next-completion 1))
+                 (nreverse completions)))))))))
+
+  (dolist (map (list mct-minibuffer-local-completion-map
+                     mct-minibuffer-completion-list-map
+                     mct-region-completion-list-map
+                     mct-region-buffer-map))
+    (define-key map (kbd "C-.") #'my-avy-completions-select)))
+#+end_src
+
 ** Ido-style navigation through directories
 :PROPERTIES:
 :CUSTOM_ID: h:9a6746dd-0be9-4e29-ac40-0af9612d05a2



reply via email to

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