Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special hook vundo-after-undo-functions #74

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

protesilaos
Copy link
Contributor

The idea is to allow users to call functions that act on the vundo--orig-buffer.

The idea is to allow users to call functions that act on the
vundo--orig-buffer.
@protesilaos
Copy link
Contributor Author

I am using this special hook to produce a diff of the underlying file. Here is how I am doing it right now:

(defvar prot/vundo-diff-buffer-window nil
  "Window object of `prot/vundo-diff-buffer'.")

(defun prot/vundo-quit-diff-window ()
  "Quit `prot/vundo-diff-buffer-window' if it is live.
Assign this function to the `vundo-post-exit-hook'."
  (when (and prot/vundo-diff-buffer-window
             (window-live-p prot/vundo-diff-buffer-window))
    (quit-window nil prot/vundo-diff-buffer-window)
    (setq prot/vundo-diff-buffer-window nil)))

(defun prot/vundo-diff-buffer (buffer)
  "Diff BUFFER with its underlying file, if possible.
Assign this to `vundo-after-undo-functions'.  BUFFER is provided
by that special hook."
  (when (buffer-file-name buffer)
    (with-current-buffer (window-buffer (diff-buffer-with-file buffer))
      (setq prot/vundo-diff-buffer-window (get-buffer-window)))))

(add-hook 'vundo-after-undo-functions #'prot/vundo-diff-buffer)
(add-hook 'vundo-post-exit-hook #'prot/vundo-quit-diff-window)

protesilaos added a commit to protesilaos/dotfiles that referenced this pull request Jun 13, 2023
I am waiting for upstream to respond to my pull request:
<casouri/vundo#74>.
@gitrj95
Copy link

gitrj95 commented Jun 13, 2023

hi guys :). wonder if we can select two points in vundo and construct a diff between them?

@casouri
Copy link
Owner

casouri commented Jun 14, 2023

Cool. I think this is fine. I'd call hooks hook though. Is there any particular reason to call it functions?

@protesilaos
Copy link
Contributor Author

Thank you @casouri!

Is there any particular reason to call it functions?

Quote from (info "(elisp) Hooks")

If the hook variable’s name does not end with ‘-hook’, that indicates
it is probably an “abnormal hook”. These differ from normal hooks in
two ways: they can be called with one or more arguments, and their
return values can be used in some way. The hook’s documentation says
how the functions are called and how their return values are used. Any
functions added to an abnormal hook must follow the hook’s calling
convention. By convention, abnormal hook names end in ‘-functions’.

@casouri casouri merged commit ecc0e2c into casouri:master Jun 14, 2023
@casouri
Copy link
Owner

casouri commented Jun 14, 2023

Thanks, TIL. I merged the change.

@protesilaos
Copy link
Contributor Author

@casouri You are welcome!

@gitrj95 Maybe that is possible. Though I have not studied the code thoroughly to know the answer.

@casouri
Copy link
Owner

casouri commented Jun 15, 2023

@gitrj95 You can move between nodes on the tree with vundo--move-to-node, grab the buffer (vundo--orig-buffer), and diff the two buffer. I would search for vundo--move-to-node in the source to see how it's used--I can't tell you from the top of my head, because it's been a while since I wrote it ;-)

To be extra save you can clone the original buffer first.

protesilaos added a commit to protesilaos/dotfiles that referenced this pull request Jun 20, 2023
My pull request was merged and now I can use upstream vundo to perform
the diff I want: <casouri/vundo#74>.
@jdtsmith
Copy link
Contributor

jdtsmith commented Dec 2, 2023

@gitrj95 It's very possible to a "mark and diff", and we should definitely add this option. Can reuse some of the marking functionality from the saved buffer state improvements. In fact, I use a d="diff to the last node" capability all the time with vundo; see #56. We can continue the conversation there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants