evil-goggles
evil-goggles copied to clipboard
goggles for custom evil-operators
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.
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
...
)
Yes something like:
(evil-define-operator my/evil-operator-org-capture (beg end)
"Evil operator for org-capture."
:visual-hint t
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.
That's bad news. Can you think of another way to make visual-hint for custom evil-operators possible?
Could you paste the whole custom operator code?
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))
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.
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.
Probably it can be done with emacs' after-change-functions / before-change-functions
. Suggestions, proof-of-concepts and PRs are welcome.
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)
;; ------------------------------------------------------------------