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

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

[nongnu] elpa/evil-goggles 79a2f620bf 190/225: Implement yank, delete, i


From: ELPA Syncer
Subject: [nongnu] elpa/evil-goggles 79a2f620bf 190/225: Implement yank, delete, indent & change with a :before advice
Date: Wed, 12 Jan 2022 08:59:07 -0500 (EST)

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

    Implement yank, delete, indent & change with a :before advice
---
 evil-goggles.el | 564 ++++++++------------------------------------------------
 1 file changed, 79 insertions(+), 485 deletions(-)

diff --git a/evil-goggles.el b/evil-goggles.el
index 5c228250a0..cffc7224a3 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -137,14 +137,6 @@ background of 'evil-goggles-default-face, then 'region."
       (overlay-put ov (pop properties) (pop properties)))
     ov))
 
-(defvar evil-goggles--on nil
-  "When non-nil, the goggles overlay must not be displayed.
-
-Used to prevent displaying multiple overlays for the same command.  For
-example, when the user executes `evil-delete', the overlay should be
-displayed, but when `evil-delete' calls internally `evil-yank', the
-overlay must not be re-displayed.")
-
 (defvar evil-goggles--force-block nil
   "When non-nil, force the hint about to be shown to be a block.")
 
@@ -243,7 +235,7 @@ This function returns a list - either ('blink face) or 
('pulse bg)."
 If hint is visible, check it's ok to display it from BEG to END.  If
 it's not, do BODY1, else BODY2."
   (declare (indent 3) (debug t)) ;; TODO indent like `if'
-  `(if (and (not evil-goggles--on) (evil-goggles--show-p ,beg ,end) 
(called-interactively-p 'any))
+  `(if (and (evil-goggles--show-p ,beg ,end) (called-interactively-p 'any))
        (let ((evil-goggles--on t))
          ,@body2)
      ,body1))
@@ -251,8 +243,7 @@ it's not, do BODY1, else BODY2."
 (defmacro evil-goggles--with-disabled-hint (&rest body)
   "Do BODY with hints disabled."
   (declare (indent 0) (debug t))
-  `(let ((evil-goggles--on t))
-     ,@body))
+  `(,@body))
 
 (defmacro evil-goggles--with-blocking-hint (beg end face &rest body)
   "Show hint from BEG to END with face FACE, hide it, then do BODY.
@@ -324,12 +315,6 @@ so this package can work with Emacs 24"
   (cl-letf (((symbol-function 'called-interactively-p) (lambda (_) t)))
     (apply f args)))
 
-(defmacro evil-goggles--funcall-preserve-interactive (fun &rest args)
-  "Call FUN with ARGS with `funcall' or `funcall-interactively'."
-  `(if (called-interactively-p 'any)
-       (evil-goggles--funcall-interactively ,fun ,@args)
-     (funcall ,fun ,@args)))
-
 (defmacro evil-goggles--define-switch-and-face (switch-name switch-doc 
face-name face-doc &optional off-by-default)
   "Helper macro defining an on/off var, a face, and duration var.
 
@@ -391,56 +376,72 @@ OFF-BY-DEFAULT if non-nil will set the switch to `nil'"
    '(evil-goggles-undo-redo-remove-face ((t (:inherit magit-diff-removed))))
    '(evil-goggles-undo-redo-add-face    ((t (:inherit magit-diff-added))))))
 
+;;; generic blocking advice
+
+(defun evil-goggles--get-face (command)
+  (or
+   (plist-get (alist-get command evil-goggles--faces) :face)
+   'evil-goggles-default-face))
+
+(defun evil-goggles--show-blocking-hint (beg end face)
+  "Show blocking hint from BEG to END with face FACE."
+  (let ((dur (or evil-goggles-blocking-duration evil-goggles-duration)))
+    (if (or (eq evil-this-type 'block) evil-goggles--force-block)
+        (evil-goggles--show-block-overlay beg end face dur)
+      (evil-goggles--show-overlay beg end face dur))))
+
+(defun evil-goggles--generic-blocking-advice (beg end &rest _)
+  (when (and (called-interactively-p 'interactive)
+             (evil-goggles--show-p beg end))
+    (evil-goggles--show-blocking-hint beg end (evil-goggles--get-face 
this-command))))
+
+;;; generic async advice
+
+(defvar evil-goggles--timer nil)
+(defvar evil-goggles--async-ov nil)
+
+(defun evil-goggles--vanish (&rest _)
+  "Remove the async overlay and cancel the timer."
+  (when (timerp evil-goggles--timer)
+    (cancel-timer evil-goggles--timer)
+    (setq evil-goggles--timer nil))
+  (when evil-goggles--async-ov
+    (delete-overlay evil-goggles--async-ov)
+    (setq evil-goggles--async-ov nil)))
+
+(defun evil-goggles--generic-async-advice (beg end &rest _)
+  (when (and (called-interactively-p 'interactive)
+             (evil-goggles--show-p beg end))
+    (let ((ov (evil-goggles--make-overlay beg end 'insert-behind-hooks 
'(evil-goggles--overlay-insert-behind-hook)))
+          (dur (or evil-goggles-async-duration evil-goggles-duration))
+          (face (evil-goggles--get-face this-command)))
+      (unwind-protect
+          ;; show the overlay
+          (evil-goggles--show-or-pulse-overlay ov 'evil-goggles-default-face 
dur)
+        ;; remove the overlay with a timer
+        (setq
+         evil-goggles--async-ov ov
+         evil-goggles--timer (run-at-time dur
+                                          nil
+                                          #'evil-goggles--vanish))))))
+
 ;;; delete
 
 (evil-goggles--define-switch-and-face
     evil-goggles-enable-delete "If non-nil, enable delete support"
     evil-goggles-delete-face "Face for delete action")
 
-(defun evil-goggles--evil-delete-advice (orig-fun beg end &optional type 
register yank-handler)
-  "Around-advice for function `evil-delete`.
+;;; yank
 
-ORIG-FUN is the original function.
-BEG END &OPTIONAL TYPE REGISTER YANK-HANDLER are the arguments of the original 
function."
-  (evil-goggles--with-blocking-hint beg end 'evil-goggles-delete-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type register 
yank-handler)))
+(evil-goggles--define-switch-and-face
+    evil-goggles-enable-yank "If non-nil, enable yank support"
+    evil-goggles-yank-face "Face for yank action")
 
 ;;; change
 
 (evil-goggles--define-switch-and-face
     evil-goggles-enable-change "If non-nil, enable change support"
-    evil-goggles-change-face "Face for change action"
-    :off-by-default)
-
-(defun evil-goggles--evil-change-advice (orig-fun beg end &optional type 
register yank-handler delete-func)
-  "Around-advice for function `evil-change`.
-
-ORIG-FUN is the original function.
-BEG END TYPE REGISTER YANK-HANDLER DELETE-FUNC are the arguments of the 
original function."
-  (evil-goggles--with-blocking-hint beg end 'evil-goggles-change-face
-    (funcall orig-fun beg end type register yank-handler delete-func)))
-
-(defun evil-goggles--evil-change-line-advice (orig-fun beg end &optional type 
register yank-handler)
-  "Around-advice for function `evil-change-line`.
-
-ORIG-FUN is the original function.
-BEG END TYPE REGISTER YANK-HANDLER are the arguments of the original function."
-  (evil-goggles--with-blocking-hint beg end 'evil-goggles-change-face
-    (funcall orig-fun beg end type register yank-handler)))
-
-;;; substitute
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-substitute "If non-nil, enable substitute support"
-    evil-goggles-substitute-face "Face for substitute action")
-
-(defun evil-goggles--evil-change-whole-line-advice (orig-fun beg end &optional 
type register yank-handler)
-  "Around-advice for function `evil-change-whole-line`.
-
-ORIG-FUN is the original function.
-BEG END TYPE REGISTER YANK-HANDLER are the arguments of the original function."
-  (evil-goggles--with-blocking-hint beg end 'evil-goggles-substitute-face
-    (funcall orig-fun beg end type register yank-handler)))
+    evil-goggles-change-face "Face for change action")
 
 ;;; indent
 
@@ -448,347 +449,15 @@ BEG END TYPE REGISTER YANK-HANDLER are the arguments of 
the original function."
     evil-goggles-enable-indent "If non-nil, enable indent support"
     evil-goggles-indent-face "Face for indent action")
 
-(defun evil-goggles--evil-indent-advice (orig-fun beg end)
-  "Around-advice for function `evil-indent'.
+;;; assosiation list with faces
 
-ORIG-FUN is the original function.
-BEG END are the arguments of the original function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-indent-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end)))
+(defvar evil-goggles--faces
+  '((evil-delete :face evil-goggles-delete-face)
+    (evil-yank   :face evil-goggles-yank-face)
+    (evil-indent :face evil-goggles-indent-face)
+    (evil-change :face evil-goggles-change-face)))
 
-;;; yank
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-yank "If non-nil, enable yank support"
-    evil-goggles-yank-face "Face for yank action")
-
-(defun evil-goggles--evil-yank-advice (orig-fun beg end &optional type 
register yank-handler)
-  "Around-advice for function `evil-yank'.
-
-ORIG-FUN is the original function.
-BEG END &OPTIONAL TYPE REGISTER YANK-HANDLER are the arguments of the original 
function."
-  (evil-goggles--with-async-hint 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 t
-  "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 t
-  "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)
-
-(defface evil-goggles-undo-redo-change-face
-  '((t
-     (:inherit evil-goggles-default-face)))
-  "Face for undo/redo change action" :group 'evil-goggles-faces)
-
-(defun evil-goggles--undo-tree-undo-advice (orig-fun &optional arg)
-  "Advice for function `undo-tree-undo` and function `undo-tree-redo`.
-
-ORIG-FUN is the original function.
-ARG is the arguments of the original function."
-  (unwind-protect
-      (progn
-        (advice-add 'primitive-undo :around 
'evil-goggles--primitive-undo-advice)
-        (funcall orig-fun arg))
-    (advice-remove 'primitive-undo 'evil-goggles--primitive-undo-advice)))
-
-(defun evil-goggles--primitive-undo-advice (orig-fun n list)
-  "Advice for function `primitive-undo`.
-
-ORIG-FUN is the original function.
-N and LIST are the arguments of the original function."
-  (let ((undo-item (evil-goggles--get-undo-item list)))
-    ;; show hint on the text which will be removed before undo/redo removes it
-    (pcase undo-item
-      (`(text-added ,beg ,end)
-       (evil-goggles--show-hint beg end 'evil-goggles-undo-redo-remove-face 
nil t)))
-
-    ;; call the undo/redo function
-    (funcall orig-fun n list)
-
-    ;; show hint on the text which will be added after undo/redo addes it
-    (pcase undo-item
-      (`(text-removed ,beg ,end)
-       (evil-goggles--show-hint beg end 'evil-goggles-undo-redo-add-face))
-      (`(text-changed ,beg ,end)
-       (evil-goggles--show-hint beg end 
'evil-goggles-undo-redo-change-face)))))
-
-(defun evil-goggles--get-undo-item (list)
-  "Process LIST.
-
-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)"
-  (let* ((processed-list
-          (evil-goggles--combine-undo-list (cl-remove-if #'null (mapcar 
#'evil-goggles--undo-elt 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)
-  "Combine elements in INPUT list.
-
-Each element is expected to be either '(text-added BEG END) or
-'(text-removed BEG END)."
-  (let* ((last (car input))
-         (result (list last)))
-    (dolist (this (cdr input) (nreverse result))
-      (cond ((and (eq (car last) (car this)) ;; both are either text-added or 
text-removed
-                  (eq (nth 1 last) (nth 1 this)))
-             ;; combine 2 overlapping elements
-             (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))))
-             ;; combine 2 connecting text-added/text-deleted elements
-             (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)))))
-            ((and
-              (eq (car last) 'text-added)
-              (eq (car this) 'text-removed)
-              (eq (nth 1 last) (nth 1 this)))
-             ;; combine overlapping text-added with text-removed which start 
at the same point
-             (setcar result (list
-                             'text-changed
-                             (nth 1 last)
-                             (if (< (nth 2 last) (nth 2 this))
-                                 (max (nth 2 last) (nth 2 this))
-                               (min (nth 2 last) (nth 2 this))))))
-            (t (push this result)))
-      (setq last (car result)))))
-
-(defun evil-goggles--undo-elt (undo-elt)
-  "Process UNDO-ELT.
-
-Return a list: either ('text-added beg end) or ('text-removed beg end)"
-  (pcase undo-elt
-    ;; (BEG . END) means text added
-    (`(,(and beg (pred integerp)) . ,(and end (pred integerp)))
-     `(text-added ,beg ,end))
-    ;; (TEXT . POSITION) means text inserted
-    (`(,(and text (pred stringp)) . ,(and pos (pred integerp)))
-     (list 'text-removed pos (+ pos (length text))))
-    ;; All others return nil
-    (_ nil)))
-
-;;; join
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-join "If non-nil, enable join support"
-    evil-goggles-join-face "Face for join action")
-
-(defun evil-goggles--evil-join-advice (orig-fun beg end)
-  "Around-advice for function `evil-join'.
-
-ORIG-FUN is the original function.
-BEG END are the arguments of the original function."
-  (let* ((beg-line (line-number-at-pos beg))
-         (end-line (line-number-at-pos end))
-         (line-count (- end-line beg-line)))
-    (if (> line-count 1) ;; don't show goggles for single lines ("J"/"gJ" 
without count)
-        (evil-goggles--with-blocking-hint beg end 'evil-goggles-join-face
-          (evil-goggles--funcall-preserve-interactive orig-fun beg end))
-      (evil-goggles--funcall-preserve-interactive orig-fun beg end))))
-
-;;; reformat (fill and move)
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-fill-and-move "If non-nil, enable fill and move 
(reformat) support"
-    evil-goggles-fill-and-move-face "Face for fill and move (reformat) action")
-
-(defun evil-goggles--evil-fill-and-move-advice (orig-fun beg end)
-  "Around-advice for function `evil-fill-and-move'.
-
-ORIG-FUN is the original function.
-BEG END are arguments of the original function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-fill-and-move-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end)))
-
-;;; paste before and after
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-paste "If non-nil, enable paste support"
-    evil-goggles-paste-face "Face for paste action")
-
-(defun evil-goggles--evil-paste-advice (orig-fun count &optional register 
yank-handler)
-  "Around-advice for functions `evil-paste-after' and `evil-paste-before'.
-
-ORIG-FUN is the original function.
-COUNT REGISTER YANK-HANDLER are the arguments of the original function."
-  (prog1
-      (evil-goggles--funcall-preserve-interactive orig-fun count register 
yank-handler)
-    (when (evil-normal-state-p)
-      (let* ((beg (save-excursion (evil-goto-mark ?\[) (if (eolp) (1+ (point)) 
(point))))
-             (end (save-excursion (evil-goto-mark ?\]) (if (eolp) (1+ (point)) 
(point))))
-             (use-block-hint (evil-goggles--evil-paste-block-p register 
yank-handler)))
-        (evil-goggles--show-hint beg end 'evil-goggles-paste-face 
use-block-hint)))))
-
-(defun evil-goggles--evil-paste-block-p (register yank-handler)
-  "Return t if the paste was a vertical block.
-
-Argument REGISTER is the evil register.
-Argument YANK-HANDLER is the yank hanler."
-  (let* ((text (if register
-                   (evil-get-register register)
-                 (current-kill 0)))
-         (yh (or yank-handler
-                 (when (stringp text)
-                   (car-safe (get-text-property
-                              0 'yank-handler text))))))
-    (eq yh 'evil-yank-block-handler)))
-
-;;; shift left & right
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-shift "If non-nil, enable shift left/right support"
-    evil-goggles-shift-face "Face for paste action")
-
-(defun evil-goggles--evil-shift-advice (orig-fun beg end &optional count 
preserve-empty)
-  "Around-advice for function `evil-shift-left` and `evil-shift-right`.
-
-ORIG-FUN is the original function.
-BEG END &OPTIONAL COUNT PRESERVE-EMPTY are the arguments of the original 
function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-shift-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end count 
preserve-empty)))
-
-;;; set mark
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-set-marker "If non-nil, enable set mark support"
-    evil-goggles-set-marker-face "Face for set mark action")
-
-(defun evil-goggles--evil-set-marker-advice (orig-fun char &optional pos 
advance)
-  "Around-advice for function `evil-set-marker`.
-
-ORIG-FUN is the original function.
-CHAR POS ADVANCE are the arguments of the original function."
-  ;; call orig-fun
-  (evil-goggles--funcall-preserve-interactive orig-fun char pos advance)
-  ;; maybe show the goggles overlay
-  (when (<= ?a char ?z)
-    (let ((beg (line-beginning-position))
-          (end (1+ (line-end-position)))
-          (evil-goggles--hint-on-empty-lines t))
-      (evil-goggles--with-async-hint beg end 'evil-goggles-set-marker-face))))
-
-;;; record macro
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-record-macro "If non-nil, enable record macro support"
-    evil-goggles-record-macro-face "Face for record macro action")
-
-(defun evil-goggles--evil-record-macro-advice (orig-fun register)
-  "Around-advice for function `evil-record-macro'.
-
-ORIG-FUN is the original function.
-REGISTER is the argument of the original function."
-  (let ((beg (line-beginning-position))
-        (end (1+ (line-end-position)))
-        (was-defining-kbd-macro defining-kbd-macro)
-        (evil-goggles--hint-on-empty-lines t))
-
-    ;; show hint before starting to record a macro
-    (unless was-defining-kbd-macro
-      (evil-goggles--show-hint beg end 'evil-goggles-record-macro-face))
-
-    (evil-goggles--funcall-preserve-interactive orig-fun register)
-
-    ;; show hint when done defining the macro
-    (when was-defining-kbd-macro
-      (evil-goggles--show-hint beg end 'evil-goggles-record-macro-face))))
-
-
-;;; ex global
-
-(defun evil-goggles--evil-ex-global-advice (orig-fun beg end pattern command 
&optional invert)
-  "Around-advice for function `evil-ex-global'.
-
-ORIG-FUN is the original function.
-BEG END PATTERN COMMAND &OPTIONAL INVERT are the arguments of the original 
function."
-  (evil-goggles--with-disabled-hint
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end pattern 
command invert)))
-
-;;; surround
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-surround "If non-nil, enable surround support"
-    evil-goggles-surround-face "Face for surround action")
-
-(defun evil-goggles--evil-surround-region-advice (orig-fun beg end &optional 
type char force-new-line)
-  "Around-advice for function `evil-surround-region'.
-
-ORIG-FUN is the original function.
-BEG END &OPTIONAL TYPE CHAR FORCE-NEW-LINE are the arguments of the original 
function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-surround-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type char 
force-new-line)))
-
-;;; commentary
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-commentary "If non-nil, enable commentary support"
-    evil-goggles-commentary-face "Face for commentary action")
-
-(defun evil-goggles--evil-commentary-advice (orig-fun beg end &optional type)
-  "Around-advice for function `evil-commentary'.
-
-ORIG-FUN is the original function.
-BEG END &OPTIONAL TYPE are the arguments of the original function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-commentary-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type)))
-
-;;; nerd-commenter
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-nerd-commenter "If non-nil, enable nerd-commenter 
support"
-    evil-goggles-nerd-commenter-face "Face for nerd-commenter action")
-
-(defun evil-goggles--evil-nerd-commenter-advice (orig-fun beg end &optional 
type)
-  "Around-advice for function `evilnc-comment-operator'.
-
-ORIG-FUN is the original function.
-BEG END &OPTIONAL TYPE are the arguments of the original function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-nerd-commenter-face
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type)))
-
-;;; replace with register
-
-(evil-goggles--define-switch-and-face
-    evil-goggles-enable-replace-with-register "If non-nil, enable replace with 
register support"
-    evil-goggles-replace-with-register-face "Face for replace with register 
action")
-
-(defun evil-goggles--evil-replace-with-register-advice (orig-fun count beg 
&optional end type register)
-  "Around-advice for function `evil-replace-with-register'.
-
-ORIG-FUN is the original function.
-COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of the original 
function."
-  (evil-goggles--with-async-hint beg end 'evil-goggles-nerd-commenter-face
-    (evil-goggles--funcall-preserve-interactive orig-fun count beg end type 
register)))
-
-;;; mode defined below ;;;
+;;; minor mode defined below ;;;
 
 (defcustom evil-goggles-lighter
   " EG"
@@ -802,97 +471,22 @@ COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments 
of the original function
   :lighter evil-goggles-lighter
   :global t
   :require 'evil-goggles
-  (cond
-   (evil-goggles-mode
-
-    ;; evil core functions
-
-    (when evil-goggles-enable-delete
-      (advice-add 'evil-delete :around 'evil-goggles--evil-delete-advice))
-
-    ;; `c' and `C' normal state keys
-    (when evil-goggles-enable-change
-      (advice-add 'evil-change :around 'evil-goggles--evil-change-advice)
-      (advice-add 'evil-change-line :around 
'evil-goggles--evil-change-line-advice))
-
-    ;; `s' and `S' normal state keys
-    (when evil-goggles-enable-substitute
-      (advice-add 'evil-change-whole-line :around 
'evil-goggles--evil-change-whole-line-advice))
-
-    (when evil-goggles-enable-indent
-      (advice-add 'evil-indent :around 'evil-goggles--evil-indent-advice))
-
-    (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-advice))
-    (when evil-goggles-enable-redo
-      (advice-add 'undo-tree-redo :around 
'evil-goggles--undo-tree-undo-advice))
-
-    (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))
-
-    (when evil-goggles-enable-fill-and-move
-      (advice-add 'evil-fill-and-move :around 
'evil-goggles--evil-fill-and-move-advice))
-
-    (when evil-goggles-enable-paste
-      (advice-add 'evil-paste-after :around 'evil-goggles--evil-paste-advice)
-      (advice-add 'evil-paste-before :around 'evil-goggles--evil-paste-advice))
-
-    (when evil-goggles-enable-shift
-      (advice-add 'evil-shift-left :around 'evil-goggles--evil-shift-advice)
-      (advice-add 'evil-shift-right :around 'evil-goggles--evil-shift-advice))
-
-    (when evil-goggles-enable-set-marker
-      (advice-add 'evil-set-marker :around 
'evil-goggles--evil-set-marker-advice))
-
-    (when evil-goggles-enable-record-macro
-      (advice-add 'evil-record-macro :around 
'evil-goggles--evil-record-macro-advice))
-
-    ;; make sure :global and :v don't show the goggles overlay
-    (advice-add 'evil-ex-global :around 'evil-goggles--evil-ex-global-advice)
-
-    ;; evil non-core functions
-
-    (when evil-goggles-enable-surround
-      (advice-add 'evil-surround-region :around 
'evil-goggles--evil-surround-region-advice))
-
-    (when evil-goggles-enable-commentary
-      (advice-add 'evil-commentary :around 
'evil-goggles--evil-commentary-advice))
-
-    (when evil-goggles-enable-nerd-commenter
-      (advice-add 'evilnc-comment-operator :around 
'evil-goggles--evil-nerd-commenter-advice))
-
-    (when evil-goggles-enable-replace-with-register
-      (advice-add 'evil-replace-with-register :around 
'evil-goggles--evil-replace-with-register-advice)))
-   (t
-    (advice-remove 'evil-delete 'evil-goggles--evil-delete-advice)
-    (advice-remove 'evil-change 'evil-goggles--evil-change-advice)
-    (advice-remove 'evil-change-line 'evil-goggles--evil-change-line-advice)
-    (advice-remove 'evil-change-whole-line 
'evil-goggles--evil-change-whole-line-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-advice)
-    (advice-remove 'undo-tree-redo 'evil-goggles--undo-tree-undo-advice)
-    (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)
-    (advice-remove 'evil-paste-after 'evil-goggles--evil-paste-advice)
-    (advice-remove 'evil-paste-before 'evil-goggles--evil-paste-advice)
-    (advice-remove 'evil-shift-left 'evil-goggles--evil-shift-advice)
-    (advice-remove 'evil-shift-right 'evil-goggles--evil-shift-advice)
-    (advice-remove 'evil-set-marker 'evil-goggles--evil-set-marker-advice)
-    (advice-remove 'evil-record-macro 'evil-goggles--evil-record-macro-advice)
-
-    (advice-remove 'evil-ex-global 'evil-goggles--evil-ex-global-advice)
-
-    ;; evil non-core functions
-    (advice-remove 'evil-surround-region 
'evil-goggles--evil-surround-region-advice)
-    (advice-remove 'evil-commentary 'evil-goggles--evil-commentary-advice)
-    (advice-remove 'evilnc-comment-operator 
'evil-goggles--evil-nerd-commenter-advice)
-    (advice-remove 'evil-replace-with-register 
'evil-goggles--evil-replace-with-register-advice))))
+  (if evil-goggles-mode
+      (progn
+        (add-hook 'pre-command-hook #'evil-goggles--vanish)
+        (when evil-goggles-enable-delete
+          (advice-add 'evil-delete :before 
'evil-goggles--generic-blocking-advice))
+        (when evil-goggles-enable-yank
+          (advice-add 'evil-yank :before 
'evil-goggles--generic-blocking-advice))
+        (when evil-goggles-enable-change
+          (advice-add 'evil-change :before 
'evil-goggles--generic-blocking-advice))
+        (when evil-goggles-enable-indent
+          (advice-add 'evil-indent :before 
'evil-goggles--generic-async-advice)))
+    (remove-hook 'pre-command-hook #'evil-goggles--vanish)
+    (advice-remove 'evil-delete 'evil-goggles--generic-blocking-advice)
+    (advice-remove 'evil-yak    'evil-goggles--generic-blocking-advice)
+    (advice-remove 'evil-change 'evil-goggles--generic-blocking-advice)
+    (advice-remove 'evil-indent 'evil-goggles--generic-async-advice)))
 
 (provide 'evil-goggles)
 



reply via email to

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