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

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

[elpa] externals/easy-kill 5b4ae1e 13/14: Introduce easy-kill-cycle-igno


From: Stefan Monnier
Subject: [elpa] externals/easy-kill 5b4ae1e 13/14: Introduce easy-kill-cycle-ignored to opt out of cycling
Date: Mon, 15 Mar 2021 22:20:17 -0400 (EDT)

branch: externals/easy-kill
commit 5b4ae1e33e0307a42df0440cc10004d812a6b70a
Author: Leo Liu <sdl.web@gmail.com>
Commit: Leo Liu <sdl.web@gmail.com>

    Introduce easy-kill-cycle-ignored to opt out of cycling
---
 easy-kill.el | 25 +++++++++++++++++++------
 test.el      | 21 +++++++++++++++++++++
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/easy-kill.el b/easy-kill.el
index 1ec03fd..455c58e 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -91,6 +91,11 @@ deprecated."
                        (choice string (const :tag "None" nil))))
   :group 'killing)
 
+(defcustom easy-kill-cycle-ignored nil
+  "A list of things that `easy-kill-cycle' should ignore."
+  :type '(repeat symbol)
+  :group 'killing)
+
 (defcustom easy-kill-unhighlight-key nil
   "Key sequence if non-nil to unhighlight the kill candidate."
   :type '(choice (const :tag "None" nil) key-sequence)
@@ -389,21 +394,28 @@ candidate property instead."
   (easy-kill-thing nil '+))
 
 (defun easy-kill-cycle (&optional thing)
-  "Cycle through things in `easy-kill-alist'."
+  "Cycle through things in `easy-kill-alist'.
+A thing is opted out of cycling if in `easy-kill-cycle-ignored'."
   (interactive)
-  (let ((next (easy-kill-cycle-next (or thing (easy-kill-get thing)))))
+  (let ((next (easy-kill-cycle-next (or thing (easy-kill-get thing))
+                                    (length easy-kill-cycle-ignored))))
     (easy-kill-thing next)
     (if (eq next (easy-kill-get thing))
         (easy-kill-echo "%s" next)
       ;; NEXT not killable continue cycle.
       (easy-kill-cycle next))))
 
-(defun easy-kill-cycle-next (thing)
+(defun easy-kill-cycle-next (thing depth)
   (cl-flet ((thing-name (thing)
               (if (symbolp (cdr thing)) (cdr thing) (cl-second thing))))
-    (cl-loop for (head . tail) on easy-kill-alist
-             when (eq thing (thing-name head))
-             return (thing-name (car (or tail easy-kill-alist))))))
+    (let ((next (thing-name
+                 (car (or (cl-loop for (head . tail) on easy-kill-alist
+                                   when (eq thing (thing-name head))
+                                   return tail)
+                          easy-kill-alist)))))
+      (cond ((not (memq next easy-kill-cycle-ignored)) next)
+            ((> depth 0) (easy-kill-cycle-next next (1- depth)))
+            (t (user-error "Nothing to cycle"))))))
 
 (defun easy-kill-digit-argument (n)
   "Expand selection by N number of things.
@@ -608,6 +620,7 @@ Temporally activate additional key bindings as follows:
   @       => append selection to previous kill;
   ?       => help;
   C-w     => kill selection;
+  SPC     => cycle through things in `easy-kill-alist';
   C-SPC   => turn selection into an active region;
   C-g     => abort;
   others  => save selection and exit."
diff --git a/test.el b/test.el
index 599920a..5dc5392 100644
--- a/test.el
+++ b/test.el
@@ -443,4 +443,25 @@ some of the ways to customize it;
       (should (= (mark t) (easy-kill-get start)))
       (should (= (point) (easy-kill-get end))))))
 
+(ert-deftest test-easy-kill-cycle ()
+  (let ((easy-kill-alist '((?w word) (?s sexp))))
+   (with-temp-buffer
+     (insert "a@example.com")
+     (call-interactively 'easy-kill)
+     (should (eq 'email (easy-kill-get thing)))
+
+     (call-interactively 'easy-kill-cycle)
+     (should (eq 'word (easy-kill-get thing)))
+     (call-interactively 'easy-kill-cycle)
+     (should (eq 'sexp (easy-kill-get thing)))
+     (call-interactively 'easy-kill-cycle)
+     (should (eq 'word (easy-kill-get thing)))
+
+     (let ((easy-kill-cycle-ignored '(sexp)))
+       (call-interactively 'easy-kill-cycle))
+     (should (eq 'word (easy-kill-get thing)))
+
+     (let ((easy-kill-cycle-ignored '(word sexp)))
+       (should-error (call-interactively 'easy-kill-cycle))))))
+
 ;;; test.el ends here



reply via email to

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