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

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

[nongnu] elpa/evil-goggles ef1cad8f3a 064/225: Re-add paste and fill-and


From: ELPA Syncer
Subject: [nongnu] elpa/evil-goggles ef1cad8f3a 064/225: Re-add paste and fill-and-move
Date: Wed, 12 Jan 2022 08:58:44 -0500 (EST)

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

    Re-add paste and fill-and-move
---
 evil-goggles-faces.el | 11 +++++++++-
 evil-goggles.el       | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/evil-goggles-faces.el b/evil-goggles-faces.el
index 0f4ae64d81..8c1eb8ad87 100644
--- a/evil-goggles-faces.el
+++ b/evil-goggles-faces.el
@@ -24,6 +24,16 @@
   "Face for join action"
   :group 'evil-goggles-faces)
 
+(defface evil-goggles-fill-and-move-face
+  '((t (:inherit region)))
+  "Face for fill and move (reformat) action"
+  :group 'evil-goggles-faces)
+
+(defface evil-goggles-paste-face
+  '((t (:inherit diff-added)))
+  "Face for paste action"
+  :group 'evil-goggles-faces)
+
 ;; non-core
 
 (defface evil-goggles-surround-face
@@ -31,7 +41,6 @@
   "Face for surround action"
   :group 'evil-goggles-faces)
 
-
 (defface evil-goggles-commentary-face
   '((t (:inherit region)))
   "Face for commentary action"
diff --git a/evil-goggles.el b/evil-goggles.el
index 65993d293d..f14bf1a316 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -192,6 +192,57 @@ BEG END are the arguments of the original function."
           (evil-goggles--funcall-preserve-interactive orig-fun beg end))
       (evil-goggles--funcall-preserve-interactive orig-fun beg end))))
 
+(defcustom evil-goggles-enable-fill-and-move t
+  "If non-nil, enable fill and move (reformat) support"
+  :type 'boolean
+  :group 'evil-goggles)
+
+(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-goggles beg end 'evil-goggles-fill-and-move-face
+    (evil-goggles--funcall-preserve-interactive orig-fun beg end)))
+
+(defcustom evil-goggles-enable-paste t
+  "If non-nil, enable paste support"
+  :type 'boolean
+  :group 'evil-goggles)
+
+(defun evil-goggles--evil-paste-after-advice (orig-fun count &optional 
register yank-handler)
+  "Around-advice for function `evil-paste-after'.
+
+ORIG-FUN is the original function.
+COUNT REGISTER YANK-HANDLER are the arguments of the original function."
+  (let ((was-in-normal-state (evil-normal-state-p))
+        (orig-fun-result (evil-goggles--funcall-preserve-interactive orig-fun 
count register yank-handler)))
+    (when was-in-normal-state
+      (evil-goggles--evil-paste-show))
+    orig-fun-result))
+
+(defun evil-goggles--evil-paste-before-advice (orig-fun count &optional 
register yank-handler)
+  "Around-advice for function `evil-paste-before'.
+
+ORIG-FUN is the original function.
+COUNT REGISTER YANK-HANDLER are the arguments of the original function."
+  (let ((was-in-normal-state (evil-normal-state-p))
+        (orig-fun-result (evil-goggles--funcall-preserve-interactive orig-fun 
count register yank-handler)))
+    (when was-in-normal-state
+      (evil-goggles--evil-paste-show))
+    orig-fun-result))
+
+(defun evil-goggles--evil-paste-show ()
+  "Helper fun to show the goggles overlay on the last pasted text.
+
+The overlay region is derermined by evil's variable `evil-last-paste'"
+  (unless (or evil-goggles--on (null evil-last-paste))
+    (let* ((beg (nth 3 evil-last-paste))
+           (end (nth 4 evil-last-paste))
+           (is-beg-at-eol (save-excursion (goto-char beg) (eolp)))
+           (beg-corrected (if is-beg-at-eol (1+ beg) beg) ))
+      (evil-goggles--show beg-corrected end 'evil-goggles-paste-face))))
+
 ;; ex global
 
 (defun evil-goggles--evil-ex-global-advice (orig-fun beg end pattern command 
&optional invert)
@@ -278,6 +329,13 @@ COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of 
the original function
       (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-after-advice)
+      (advice-add 'evil-paste-before :around 
'evil-goggles--evil-paste-before-advice))
+
     ;; make sure :global and :v don't show the goggles overlay
     (advice-add 'evil-ex-global :around 'evil-goggles--evil-ex-global-advice)
 
@@ -297,6 +355,9 @@ COUNT BEG &OPTIONAL END TYPE REGISTER are the arguments of 
the original function
     (advice-remove 'evil-yank 'evil-goggles--evil-yank-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-after-advice)
+    (advice-remove 'evil-paste-before 'evil-goggles--evil-paste-before-advice)
 
     (advice-remove 'evil-ex-global 'evil-goggles--evil-ex-global-advice)
 



reply via email to

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