evil-goggles icon indicating copy to clipboard operation
evil-goggles copied to clipboard

goggles for custom evil-operators

Open Dickby opened this issue 7 years ago • 10 comments

Hi, it would be a nice to be able to turn on goggles for custom evil-operators. This could be possible by adding an evil-command-property.

Dickby avatar May 26 '17 23:05 Dickby

What do you mean by custom evil operators? Operators you define yourself?

Are you requesting something like :visual-hint, e.g.:

(evil-define-command my-custom-command (count)
  :visual-hint t
  ...
)

edkolev avatar May 27 '17 06:05 edkolev

Yes something like:

(evil-define-operator my/evil-operator-org-capture (beg end)
  "Evil operator for org-capture."
  :visual-hint t

Dickby avatar May 27 '17 09:05 Dickby

I don't think this could be achieved because evil-define-operator is part of evil's core. As of now, evil's goal is to mimic vim's behaviour, I don't think evil-goggles could soon (if ever) become a part of evil.

evil-goggles could provide other means of registering custom operators. Maybe some API which can register custom operators.

edkolev avatar May 29 '17 06:05 edkolev

That's bad news. Can you think of another way to make visual-hint for custom evil-operators possible?

Dickby avatar May 29 '17 12:05 Dickby

Could you paste the whole custom operator code?

edkolev avatar May 30 '17 05:05 edkolev

I got lots of custom evil-operators in my config file, one of it is this:

(evil-define-operator my/evil-operator-org-capture (beg end)
  "Evil operator for org-capture."
  (interactive "<r>")
  (require 'org)
  (unless (region-active-p)
    (goto-char beg)
    (set-mark-command nil)
    (goto-char end))
  (org-capture))

Dickby avatar May 30 '17 10:05 Dickby

just thinking out loud: it seems evil uses evil-operator-range to collect the range, perhaps that opens possibilities?

an evil-goggles api like this (just an idea) would perhaps become possible?

(evil-goggles-add #'my-custom-evil-operator 'partial-face-name 'before)

the before/after choice would be nice to have; see #7.

wbolster avatar May 30 '17 13:05 wbolster

Wouldn't it be possible to make it truly generic, by monitoring what is "a single change" (that can be undone in one step) and highlight that? I.e. without the need to maintain an operation list, add custom operators to that list etc.

VanLaser avatar Jun 02 '17 11:06 VanLaser

Probably it can be done with emacs' after-change-functions / before-change-functions. Suggestions, proof-of-concepts and PRs are welcome.

edkolev avatar Jun 02 '17 12:06 edkolev

Probably it can be done with emacs' after-change-functions / before-change-functions. Suggestions, proof-of-concepts and PRs are welcome.

Ok, here's a small proof-of-concept: :)

;; ------------------------------------------------------------------
;; * note, this doesn't work with copying
;; (one could follow the kill-ring perhaps?)
;; * visual state change also doesn't quite work
;; (but there you *can* see what you're doing anyway
;; ------------------------------------------------------------------
(defun evil-gg--highlight-changes (beg end &optional len)
  "Local hook run before and after the buffer is changed."
  (when (and (not (minibufferp))
	     (evil-normal-state-p)
	     (< (1+ beg) end)) ; that (1+ beg) *is* needed (just try with `beg' instead)
    (let ((cmd (symbol-name this-command)))
      (when (or (string-prefix-p "evil-" cmd)
		(string-prefix-p "undo-" cmd))
	(let ((ov (make-overlay beg end)))
	  (if len ;or, use command name to build a face name and use that, if it exists
	      (overlay-put ov 'face '(:background "green"))
	    (overlay-put ov 'face '(:background "red")))
	  (redisplay t)
	  (message "%s" this-command) ;debug	
	  (sleep-for 0.150)
	  (delete-overlay ov))))))

(add-hook 'before-change-functions #'evil-gg--highlight-changes nil t)
(add-hook 'after-change-functions #'evil-gg--highlight-changes nil t)
;; ------------------------------------------------------------------

;; to disable
(remove-hook 'after-change-functions #'evil-gg--highlight--changes t)
(remove-hook 'before-change-functions #'evil-gg--highlight--changes t)
;; ------------------------------------------------------------------

VanLaser avatar Aug 20 '17 15:08 VanLaser