[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.
- [nongnu] elpa/evil-goggles 4388040c0c 034/225: Check early for non-nil `evil-last-paste', (continued)
- [nongnu] elpa/evil-goggles 4388040c0c 034/225: Check early for non-nil `evil-last-paste', ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles bebcecadef 053/225: .gitignore *.elc, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 9dae90cef6 061/225: Define faces in a separate file, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles e95fb4d6b9 058/225: Partially revert README, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles ca75849806 065/225: Add support for evil-shift-left and evil-shift-right, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles c2c9aedaff 075/225: No lonely parentheses in README, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles c1df77a548 079/225: Add "checkdoc" make target, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 2117f62dff 087/225: Alternative implementation for undo/redo, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 6ab09a09c7 093/225: Don't use `caadr`, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles d274e1572c 096/225: Make Travis run all of evil's tests under (evil-goggles-mode), ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 513ba2eb3e 094/225: Polish u/redo implementation to handle u/redo after "o"/"O",
ELPA Syncer <=
- [nongnu] elpa/evil-goggles cbcad38344 021/225: Cleanup code, add some doc strings, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 3dc8417950 040/225: Add evil-fill-and-move "=", ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles bc4a117f6c 059/225: Rename evil-goggles-face to evil-goggles-default-face, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 02a8072435 011/225: Use evil faces for delete and yank, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles a4958cf377 012/225: Add evil-commentary and evil-replace-with-register, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles dc4ce17b65 013/225: Add license header, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 8d6fc41234 023/225: Doc strings, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 743fd1d96d 027/225: Indent tweak, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 805e20dcde 022/225: Don't show overlay when :global or :vglobal is executed, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles ac3b272cdb 031/225: Reduce byte compiler errors, ELPA Syncer, 2022/01/12