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

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

[nongnu] elpa/evil-goggles 9dae90cef6 061/225: Define faces in a separat


From: ELPA Syncer
Subject: [nongnu] elpa/evil-goggles 9dae90cef6 061/225: Define faces in a separate file
Date: Wed, 12 Jan 2022 08:58:43 -0500 (EST)

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

    Define faces in a separate file
---
 evil-goggles-faces.el |  15 ++++
 evil-goggles.el       | 190 ++++++++++----------------------------------------
 test/make-compile.el  |   2 +-
 3 files changed, 52 insertions(+), 155 deletions(-)

diff --git a/evil-goggles-faces.el b/evil-goggles-faces.el
new file mode 100644
index 0000000000..3d0449c241
--- /dev/null
+++ b/evil-goggles-faces.el
@@ -0,0 +1,15 @@
+
+;; load diff-mode faces
+(require 'diff-mode)
+
+(defface evil-goggles-delete-face
+  '((t (:inherit diff-removed)))
+  "Face for delete action"
+  :group 'evil-goggles-faces)
+
+(defface evil-goggles-indent-face
+  '((t (:inherit region)))
+  "Face for delete action"
+  :group 'evil-goggles-faces)
+
+(provide 'evil-goggles-faces)
diff --git a/evil-goggles.el b/evil-goggles.el
index 65e8ee55c6..2a24dd220d 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -37,6 +37,7 @@
 ;;; Code:
 
 (require 'evil)
+(require 'evil-goggles-faces)
 
 (defcustom evil-goggles-duration 0.200
   "Time if floating seconds that the goggles overlay should last."
@@ -104,17 +105,17 @@ overlay must not be displayed.")
        ;; don't show overlay when the region has nothing but whitespace
        (not (null (string-match-p "[^ \t\n]" (buffer-substring-no-properties 
beg end))))))
 
-(defmacro evil-goggles--with-goggles (beg end adviced-fun &rest body)
+(defmacro evil-goggles--with-goggles (beg end overlay-face &rest body)
   "Show goggles overlay from BEG to END if the conditions are met.
 
-ADVICED-FUN is used to lookup which face should the overlay use.
+OVERLAY-FACE is the face to use for the overlay.
 The goggles overlay will be displayed briefly before BODY is executed.
 BODY will be executed but an overlay will not be allowed to be
 displayed while its running."
   (declare (indent defun) (debug t))
   `(if (evil-goggles--show-p ,beg ,end)
        (let* ((evil-goggles--on t))
-         (evil-goggles--show ,beg ,end (evil-goggles--face ,adviced-fun))
+         (evil-goggles--show ,beg ,end ,overlay-face)
          (progn ,@body))
      (progn ,@body)))
 
@@ -124,176 +125,57 @@ displayed while its running."
        (funcall-interactively ,fun ,@args)
      (funcall ,fun ,@args)))
 
-(defcustom evil-goggles-lighter
-  " EG"
-  ;; " (⌐■-■)"
-  "String used on the mode-line."
-  :group 'evil-goggles
-  :type 'string)
-
-;;;###autoload
-(define-minor-mode evil-goggles-mode
-  "evil-goggles global minor mode."
-  :lighter evil-goggles-lighter
-  :global t
-  (cond
-   (evil-goggles-mode
+;;; core ends here ;;;
 
-    ;; evil core functions
-    (evil-goggles--advice-add 'evil-delete          
'evil-goggles--evil-delete-advice)
-    (evil-goggles--advice-add 'evil-indent          
'evil-goggles--evil-indent-advice)
-    (evil-goggles--advice-add 'evil-yank            
'evil-goggles--evil-yank-advice)
-    (evil-goggles--advice-add 'evil-join            
'evil-goggles--evil-join-advice)
-    (evil-goggles--advice-add 'evil-join-whitespace 
'evil-goggles--evil-join-advice)
-    (evil-goggles--advice-add 'evil-paste-after     
'evil-goggles--evil-paste-after-advice)
-    (evil-goggles--advice-add 'evil-paste-before    
'evil-goggles--evil-paste-before-advice)
-    (evil-goggles--advice-add 'evil-ex-global       
'evil-goggles--evil-ex-global-advice)
-    (evil-goggles--advice-add 'evil-fill-and-move   
'evil-goggles--evil-fill-and-move-advice)
-
-    ;; undo/redo
-    ;; (evil-goggles--advice-add 'primitive-undo       
'evil-goggles--primitive-undo)
-
-    ;; evil non-core packages
-    (evil-goggles--advice-add 'evil-surround-region       
'evil-goggles--evil-surround-region-advice)
-    (evil-goggles--advice-add 'evil-commentary            
'evil-goggles--evil-commentary-advice)
-    (evil-goggles--advice-add 'evil-replace-with-register 
'evil-goggles--evil-replace-with-register-advice))
-   (t
-    (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 'evil-join            'evil-goggles--evil-join-advice)
-    (advice-remove 'evil-join-whitespace 'evil-goggles--evil-join-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)
-    (advice-remove 'evil-fill-and-move   
'evil-goggles--evil-fill-and-move-advice)
-
-    (advice-remove 'evil-surround-region       
'evil-goggles--evil-surround-region-advice)
-    (advice-remove 'evil-commentary            
'evil-goggles--evil-commentary-advice)
-    (advice-remove 'evil-replace-with-register 
'evil-goggles--evil-replace-with-register-advice))))
-
-(defun evil-goggles--advice-add (adviced-fun advice)
-  "Add advice around ADVICED-FUN with ADVICE.
-
-This function doesn't do anyting if FUN is in variable
-`evil-goggles-blacklist'"
-  (unless (memq adviced-fun evil-goggles-blacklist)
-    (advice-add adviced-fun :around advice)))
-
-;; core ends here; below are functions which use the core to display
-;; the visual hint
+(defcustom evil-goggles-enable-delete t
+  "If non-nil, enable delete support"
+  :type 'boolean
+  :group 'evil-goggles)
 
 (defun evil-goggles--evil-delete-advice (orig-fun beg end &optional type 
register yank-handler)
   "Around-advice for function `evil-delete`.
 
 ORIG-FUN is the original function.
 BEG END &OPTIONAL TYPE REGISTER YANK-HANDLER are the arguments of the original 
function."
-  (evil-goggles--with-goggles beg end 'evil-delete
+  (evil-goggles--with-goggles beg end 'evil-goggles-delete-face
     (evil-goggles--funcall-preserve-interactive orig-fun beg end type register 
yank-handler)))
 
+(defcustom evil-goggles-enable-indent t
+  "If non-nil, enable indent support"
+  :type 'boolean
+  :group 'evil-goggles)
+
 (defun evil-goggles--evil-indent-advice (orig-fun beg end)
   "Around-advice for function `evil-indent'.
 
 ORIG-FUN is the original function.
 BEG END are the arguments of the original function."
-  (evil-goggles--with-goggles beg end 'evil-indent
+  (evil-goggles--with-goggles beg end 'evil-goggles-indent-face
     (evil-goggles--funcall-preserve-interactive orig-fun beg end)))
 
-(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-goggles beg end 'evil-yank
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type register 
yank-handler)))
-
-(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-goggles beg end 'evil-join
-          (evil-goggles--funcall-preserve-interactive orig-fun beg end))
-      (evil-goggles--funcall-preserve-interactive orig-fun beg end))))
-
-(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-goggles beg end 'evil-surround-region
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type char 
force-new-line)))
+;;; mode defined below ;;;
 
-(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-goggles beg end 'evil-commentary
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end type)))
-
-(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-goggles beg end 'evil-replace-with-register
-    (evil-goggles--funcall-preserve-interactive orig-fun count beg end type 
register)))
-
-(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."
-  (let* ((evil-goggles--on t)) ;; set to `t' to prevent showing the overlay
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end pattern 
command invert)))
-
-(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 'evil-paste-after))
-    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 'evil-paste-before))
-    orig-fun-result))
-
-(defun evil-goggles--evil-paste-show (adviced-fun)
-  "Helper fun to show the goggles overlay on the last pasted text.
-
-ADVICED-FUN is used to lookup the face for the overlay.
-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--face 
adviced-fun)))))
-
-(defun evil-goggles--evil-fill-and-move-advice (orig-fun beg end)
-  "Around-advice for function `evil-fill-and-move'.
+(defcustom evil-goggles-lighter
+  " EG"
+  "String used on the mode-line."
+  :group 'evil-goggles
+  :type 'string)
 
-ORIG-FUN is the original function.
-BEG END are arguments of the original function."
-  (evil-goggles--with-goggles beg end 'evil-fill-and-move
-    (evil-goggles--funcall-preserve-interactive orig-fun beg end)))
+;;;###autoload
+(define-minor-mode evil-goggles-mode
+  "evil-goggles global minor mode."
+  :lighter evil-goggles-lighter
+  :global t
+  (cond
+   (evil-goggles-mode
 
+    ;; evil core functions
+    (when evil-goggles-enable-delete
+      (advice-add 'evil-delete :around 'evil-goggles--evil-delete-advice))
+    (when evil-goggles-enable-indent
+      (advice-add 'evil-indent :around 'evil-goggles--evil-indent-advice)))
+   (t
+    (advice-remove 'evil-delete 'evil-goggles--evil-delete-advice))))
 
 (provide 'evil-goggles)
 
diff --git a/test/make-compile.el b/test/make-compile.el
index ec336d17d0..5ef548e803 100644
--- a/test/make-compile.el
+++ b/test/make-compile.el
@@ -1,4 +1,4 @@
-(setq files '("evil-goggles.el"))
+(setq files '("evil-goggles.el" "evil-goggles-faces.el"))
 (setq byte-compile--use-old-handlers nil)
 (mapc #'byte-compile-file files)
 



reply via email to

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