Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

goggles for custom evil-operators #10

Open
Dickby opened this Issue May 26, 2017 · 10 comments

Comments

Projects
None yet
4 participants
Contributor

Dickby commented May 26, 2017

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.

Owner

edkolev commented May 27, 2017

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
  ...
)
Contributor

Dickby commented May 27, 2017

Yes something like:

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

edkolev commented May 29, 2017

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.

Contributor

Dickby commented May 29, 2017

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

Owner

edkolev commented May 30, 2017

Could you paste the whole custom operator code?

Contributor

Dickby commented May 30, 2017

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))
Contributor

wbolster commented May 30, 2017

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.

VanLaser commented Jun 2, 2017

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.

Owner

edkolev commented Jun 2, 2017

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

VanLaser commented Aug 20, 2017 edited

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)
;; ------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment