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

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

[nongnu] elpa/evil-goggles 513ba2eb3e 094/225: Polish u/redo implementat


From: ELPA Syncer
Subject: [nongnu] elpa/evil-goggles 513ba2eb3e 094/225: Polish u/redo implementation to handle u/redo after "o"/"O"
Date: Wed, 12 Jan 2022 08:58:59 -0500 (EST)

branch: elpa/evil-goggles
commit 513ba2eb3ed7f579b9babeff0d2d0e0b0a37c69f
Author: Evgeni Kolev <evgenysw@gmail.com>
Commit: Evgeni Kolev <evgenysw@gmail.com>

    Polish u/redo implementation to handle u/redo after "o"/"O"
---
 evil-goggles.el | 69 ++++++++++++++++++++++++++-------------------------------
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/evil-goggles.el b/evil-goggles.el
index 697b57b8e6..9462db5277 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -271,45 +271,38 @@ N and LIST are the arguments of the original function."
 The LIST is the input variable to function primitive-undo.
 
 This function tries to return a single list, either:
-('text-added beg end), or:
-('text-removed beg end)"
+ ('text-added beg end), or:
+ ('text-removed beg end)"
   (let* ((processed-list
-          (cl-remove-if #'null (mapcar #'evil-goggles--undo-elt list))))
-    (message "processed-list %s" processed-list)
-    (cond
-     ;; if there's only item in the list, return it
-     ((eq 1 (length processed-list))
-      (car processed-list))
-
-     ;; check if first and second region are connected:
-     ;; if we have: ((text-added 2 6) (text-added 1 2))
-     ;; then return: ((text-added 1 6))
-     ;;
-     ;; or, if we have: ((text-removed 1 2) (text-removed 2 6))
-     ;; then return: ((text-removed 1 6))
-     ;;
-     ;; TODO this could be more generic, it could work for any number of items 
in processed-list
-     ;; for example, this should be handled as well:
-     ;;    ((text-added 43 46) (text-added 22 43) (text-added 1 22))
-     ;; should become:
-     ;;    ((text-added 1 46))
-
-     ;; TODO how can this be handled, reprodcued with Otext<esc>u:
-     ;;    ((text-added 1 5) (text-added 1 2))
-     ((and (eq 2 (length processed-list))
-           (eq (car (car (cdr processed-list))) (caar processed-list)))
-      (let (
-            (change-type (car (car (cdr processed-list))))
-            (start-of-first-region  (nth 1 (nth 0 processed-list)))
-            (end-of-first-region    (nth 2 (nth 0 processed-list)))
-            (start-of-second-region (nth 1 (nth 1 processed-list)))
-            (end-of-second-region   (nth 2 (nth 1 processed-list))))
-        (message "here1 %s %s" start-of-first-region end-of-second-region)
-        (cond
-         ((eq start-of-first-region end-of-second-region)
-          `(,change-type ,start-of-second-region ,end-of-first-region))
-         ((eq end-of-first-region start-of-second-region)
-          `(,change-type ,start-of-first-region ,end-of-second-region))))))))
+          (evil-goggles--combine-undo-list (cl-remove-if #'null (mapcar 
#'evil-goggles--undo-elt list)))))
+    ;; (message "processed-list %s, list %s" processed-list list)
+    ;; (message "combined undo-list %s" processed-list)
+    ;; if there's only item in the list, return it; otherwise - nil
+    (when (eq 1 (length processed-list))
+      (car processed-list))))
+
+(defun evil-goggles--combine-undo-list (input)
+  ;; (message "input undo-list ::: %s" input)
+  (let* ((last (car input))
+         (result (list last)))
+    (dolist (this (cdr input) (nreverse result))
+      (cond ((and (eq (car last) 'text-added)
+                  (eq (car last) (car this))
+                  (eq (nth 1 last) (nth 1 this)))
+             (setcar result (list
+                             (car this)
+                             (nth 1 this)
+                             (+ (nth 2 last) (abs (- (nth 1 this) (nth 2 
this)))))))
+            ((and (eq (car last) (car this))
+                  (or
+                   (eq (nth 1 last) (nth 2 this))
+                   (eq (nth 2 last) (nth 1 this))))
+             (setcar result (list
+                             (car this)
+                             (min (nth 1 this) (nth 2 this) (nth 1 last) (nth 
2 last))
+                             (max (nth 1 this) (nth 2 this) (nth 1 last) (nth 
2 last)))))
+            (t (push this result)))
+      (setq last (car result)))))
 
 (defun evil-goggles--undo-elt (undo-elt)
   "Process UNDO-ELT.



reply via email to

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