casouri / vundo

Visualize the undo tree.
443 stars 22 forks source link

some issue from evil-mode #6

Closed liuyinz closed 3 years ago

liuyinz commented 3 years ago

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 ?

casouri commented 3 years ago

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

(if (eq fn (symbol-function 'evil-redo))
    ...)
liuyinz commented 3 years ago

Nope. I try again. Still failed.

casouri commented 3 years ago

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

casouri commented 3 years ago

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

liuyinz commented 3 years ago

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

liuyinz commented 3 years ago

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)
liuyinz commented 3 years ago

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