casouri / vundo

Visualize the undo tree.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some issue from evil-mode

liuyinz opened this issue · comments

I'm a user of evil-mode. So I prefer to call Vundo when I use evil-undo-system. This is my code below:

(defun evil-undo-advice(fn &rest _)
  "Hybrid evil and vundo."
  (if (not (fboundp 'vundo))
      (funcall fn 1)
    (vundo)
    (if (eq fn 'evil-redo)
        (vundo-forward 1)
      (vundo-backward 1))))

(advice-add 'evil-undo :around #'evil-undo-advice)
(advice-add 'evil-redo :around #'evil-undo-advice)

The problem is orig-function arguments fn , (if (eq fn 'evil-redo) always return nil , even I call evil-redo , it still execute vundo-backward , I know it's not Vundo's problem, but how should I fix it ?

Maybe fn isn't a symbol but a function object, I would try

(if (eq fn (symbol-function 'evil-redo))
    ...)

Nope. I try again. Still failed.

I see, fn is a closure object. I'm afraid you can't really tell which function fn is.

However, you could look at this-command (a variable). It might not be bullet-proof though.

I don't understand closure, but I guess I could write advice twice for each command, it's just redundent.

However, you could look at this-command (a variable). It might not be bullet-proof though.

Yes, this-command is the answer !

  (defun evil-undo-advice (fn &rest _)
    "Hybrid evil and vundo."
    (if (not (fboundp 'vundo))
        (funcall fn 1)
      (vundo)
      (if (eq this-command 'evil-redo)
          (vundo-forward 1)
        (vundo-backward 1))))

  (advice-add 'evil-undo :around #'evil-undo-advice)
  (advice-add 'evil-redo :around #'evil-undo-advice)

Thanks so much!
I guess some evil-fans would need it and love it.