[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-goggles 0c713e7462 086/225: Add experimental support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-goggles 0c713e7462 086/225: Add experimental support for undo/redo, off by default |
Date: |
Wed, 12 Jan 2022 08:58:55 -0500 (EST) |
branch: elpa/evil-goggles
commit 0c713e7462f88ae30cabd020a082abef9aa4bd46
Author: Evgeni Kolev <evgenysw@gmail.com>
Commit: Evgeni Kolev <evgenysw@gmail.com>
Add experimental support for undo/redo, off by default
---
evil-goggles.el | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 63 insertions(+), 2 deletions(-)
diff --git a/evil-goggles.el b/evil-goggles.el
index 3e2e068a22..e12fa5b9d0 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -163,7 +163,9 @@ FACE-DOC is the docstring for FACE-NAME."
(custom-set-faces
'(evil-goggles-delete-face ((t (:inherit 'diff-removed))))
'(evil-goggles-paste-face ((t (:inherit 'diff-added))))
- '(evil-goggles-yank-face ((t (:inherit 'diff-changed))))))
+ '(evil-goggles-yank-face ((t (:inherit 'diff-changed))))
+ '(evil-goggles-undo-redo-remove-face ((t (:inherit 'diff-removed))))
+ '(evil-goggles-undo-redo-add-face ((t (:inherit 'diff-added))))))
;; delete
@@ -207,6 +209,54 @@ BEG END &OPTIONAL TYPE REGISTER YANK-HANDLER are the
arguments of the original f
(evil-goggles--with-goggles beg end 'evil-goggles-yank-face
(evil-goggles--funcall-preserve-interactive orig-fun beg end type register
yank-handler)))
+;; undo & redo
+
+(defcustom evil-goggles-enable-undo nil ;; experimental, disabled by default
+ "If non-nil, enable undo support.
+This variable must be set before `evil-goggles-mode' is enabled"
+ :type 'boolean :group 'evil-goggles)
+
+(defcustom evil-goggles-enable-redo nil ;; experimental, disabled by default
+ "If non-nil, enable redo support
+This variable must be set before `evil-goggles-mode' is enabled"
+ :type 'boolean :group 'evil-goggles)
+
+(defface evil-goggles-undo-redo-add-face
+ '((t
+ (:inherit evil-goggles-default-face)))
+ "Face for undo/redo add action" :group 'evil-goggles-faces)
+
+(defface evil-goggles-undo-redo-remove-face
+ '((t
+ (:inherit evil-goggles-default-face)))
+ "Face for undo/redo remove action" :group 'evil-goggles-faces)
+
+(defun evil-goggles--undo-tree-undo--undo-tree-redo (orig-fun &optional arg)
+ "Advice for function `undo-tree-undo` and function `undo-tree-redo`."
+ (unwind-protect
+ (progn
+ (add-hook 'before-change-functions #'evil-goggles--before-change)
+ (add-hook 'after-change-functions #'evil-goggles--after-change)
+ (evil-goggles--funcall-preserve-interactive orig-fun arg))
+ (remove-hook 'before-change-functions #'evil-goggles--before-change)
+ (remove-hook 'after-change-functions #'evil-goggles--after-change)))
+
+(defun evil-goggles--before-change (beg end)
+ ;; (message "evil-goggles--after-change: from %s to %s" beg end)
+ ;; if beg and end are different, text will be removed
+ (let ((text-will-be-removed (not (eq beg end))))
+ (when (and text-will-be-removed
+ (evil-goggles--show-p beg end))
+ (evil-goggles--show beg end 'evil-goggles-undo-redo-remove-face))))
+
+(defun evil-goggles--after-change (beg end _length)
+ ;; (message "evil-goggles--after-change: from %s to %s, len %s after change
undo" beg end _length)
+ ;; if beg and end are different, text will be added
+ (let ((text-was-added (not (eq beg end))))
+ (when (and text-was-added
+ (evil-goggles--show-p beg end))
+ (evil-goggles--show beg end 'evil-goggles-undo-redo-add-face))))
+
;; join
(evil-goggles--define-switch-and-face
@@ -388,7 +438,11 @@ BEG END &OPTIONAL TYPE are the arguments of the original
function."
ORIG-FUN is the original function.
COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of the original
function."
(evil-goggles--with-goggles beg end 'evil-goggles-replace-with-register-face
- (evil-goggles--funcall-preserve-interactive orig-fun count beg end type
register)))
+ (evil-goggles--funcall-preserve-interactive orig-fun count beg end type
register))
+
+ ;; good good
+
+ (evil-goggles--show beg (point) 'diff-added))
;;; mode defined below ;;;
@@ -417,6 +471,11 @@ COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of
the original function
(when evil-goggles-enable-yank
(advice-add 'evil-yank :around 'evil-goggles--evil-yank-advice))
+ (when evil-goggles-enable-undo
+ (advice-add 'undo-tree-undo :around
'evil-goggles--undo-tree-undo--undo-tree-redo))
+ (when evil-goggles-enable-redo
+ (advice-add 'undo-tree-redo :around
'evil-goggles--undo-tree-undo--undo-tree-redo))
+
(when evil-goggles-enable-join
(advice-add 'evil-join :around 'evil-goggles--evil-join-advice)
(advice-add 'evil-join-whitespace :around
'evil-goggles--evil-join-advice))
@@ -452,6 +511,8 @@ COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of
the original function
(advice-remove 'evil-delete 'evil-goggles--evil-delete-advice)
(advice-remove 'evil-indent 'evil-goggles--evil-indent-advice)
(advice-remove 'evil-yank 'evil-goggles--evil-yank-advice)
+ (advice-remove 'undo-tree-undo
'evil-goggles--undo-tree-undo--undo-tree-redo)
+ (advice-remove 'undo-tree-redo
'evil-goggles--undo-tree-undo--undo-tree-redo)
(advice-remove 'evil-join 'evil-goggles--evil-join-advice)
(advice-remove 'evil-join-whitespace 'evil-goggles--evil-join-advice)
(advice-remove 'evil-fill-and-move
'evil-goggles--evil-fill-and-move-advice)
- [nongnu] elpa/evil-goggles 9882706667 030/225: Preserve the return value of evil-paste-*, (continued)
- [nongnu] elpa/evil-goggles 9882706667 030/225: Preserve the return value of evil-paste-*, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 253613ce66 039/225: Fix check of evil-last-paste, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 788c73d505 041/225: Make lighter configurable, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 97498ef1ba 050/225: Clarify package should be on Melpa, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles bf6f836609 056/225: Update README.md, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 10512f5b3b 054/225: Check evil-mode is on with bound-and-true-p, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles ae77a5c6f0 067/225: Replace the boilerplate in evil-goggles-faces.el with a macro, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 0f6254f548 070/225: Update README.md, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 902270eea8 084/225: Show a vertical visual hint for vertical text objects., ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 879114abea 085/225: Don't show the overlay when evil-mc is displaying multiple fake cursors, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 0c713e7462 086/225: Add experimental support for undo/redo, off by default,
ELPA Syncer <=
- [nongnu] elpa/evil-goggles fec8dfd7b5 088/225: Simplify undo/redo checks, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles fd85719817 089/225: Improve doc strings, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 0585f4d657 097/225: Try to avoid Travis seg-faults by running emacs in batch mode, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 142e0a9f2b 105/225: Remove unused option, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles ee7fafb858 107/225: Remove debugs, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 5404dcfaf8 106/225: Don't quote inherited faces so face-background works, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 13fd7e348c 110/225: Disable pulsing by default, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 49c1318098 113/225: Update README, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 6bf281c788 117/225: Simplify macro, ELPA Syncer, 2022/01/12
- [nongnu] elpa/evil-goggles 9f4a9dec5a 122/225: Fix comment, ELPA Syncer, 2022/01/12