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

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

[elpa] 08/13: Implement #10: allow `-' to move before first selection


From: Leo Liu
Subject: [elpa] 08/13: Implement #10: allow `-' to move before first selection
Date: Sun, 13 Apr 2014 07:34:51 +0000

leoliu pushed a commit to branch master
in repository elpa.

commit 0ca3785a0f32a079424831a4f2f6fb915e286a07
Author: Leo Liu <address@hidden>
Date:   Sat Apr 12 16:58:42 2014 +0800

    Implement #10: allow `-' to move before first selection
---
 README.rst   |    1 +
 easy-kill.el |   45 +++++++++++++++++++++++++++------------------
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/README.rst b/README.rst
index 3d21e02..dec0a04 100644
--- a/README.rst
+++ b/README.rst
@@ -89,6 +89,7 @@ NEWS
 0.9.2
 +++++
 
+#. ``-`` can move pass the first selection.
 #. Mouse over the selection now shows description.
 #. Echo js2 node name.
 #. Append now uses sensible separator (customisable via
diff --git a/easy-kill.el b/easy-kill.el
index 74cbe11..924ea91 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -155,6 +155,11 @@ The value is the function's symbol if non-nil."
     (string (easy-kill-fboundp (intern-soft name)))
     (symbol (and (fboundp name) name))))
 
+(defun easy-kill-pair-to-list (pair)
+  (pcase pair
+    (`(,beg . ,end) (list beg end))
+    (_ (signal 'wrong-type-argument (list pair "Not a dot pair")))))
+
 (defun easy-kill-interprogram-cut (text)
   "Make non-empty TEXT available to other programs."
   (cl-check-type text string)
@@ -325,25 +330,29 @@ candidate property instead."
   (interactive)
   (easy-kill-thing nil '-))
 
-;; helper for `easy-kill-thing'.
+;; Helper for `easy-kill-thing'.
 (defun easy-kill-thing-forward (n)
-  (let ((step (if (cl-minusp n) -1 +1))
-        (thing (easy-kill-get thing))
-        (start (easy-kill-get start))
-        (end (easy-kill-get end)))
-    (when (and thing (/= n 0))
-      (let ((new-end (save-excursion
-                       (goto-char end)
-                       (with-demoted-errors
-                         (cl-dotimes (_ (abs n))
-                           (forward-thing thing step)
-                           (when (<= (point) start)
-                             (forward-thing thing 1)
-                             (cl-return))))
-                       (point))))
-        (when (/= end new-end)
-          (easy-kill-adjust-candidate thing nil new-end)
-          t)))))
+  (when (and (easy-kill-get thing) (/= n 0))
+    (let* ((step (if (cl-minusp n) -1 +1))
+           (thing (easy-kill-get thing))
+           (bounds1 (easy-kill-pair-to-list (bounds-of-thing-at-point thing)))
+           (start (easy-kill-get start))
+           (end (easy-kill-get end))
+           (front (or (car (cl-set-difference (list end start) bounds1))
+                      (pcase step
+                        (`-1 start)
+                        (`1 end))))
+           (new-front (save-excursion
+                        (goto-char front)
+                        (with-demoted-errors
+                          (cl-dotimes (_ (abs n))
+                            (forward-thing thing step)))
+                        (point))))
+      (pcase (and (/= front new-front)
+                  (sort (cons new-front bounds1) #'<))
+        (`(,start ,_ ,end)
+         (easy-kill-adjust-candidate thing start end)
+         t)))))
 
 (defun easy-kill-thing-handler (thing mode)
   "Get the handler for THING or nil if none is defined.



reply via email to

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