Open edkolev opened 7 years ago
Hi, thanks for the question!
Would it be possible to preserve the window layout?
Absolutely, I was actually just looking at the code for the built-in winner-mode
for preserving my editing layout when I switch to dumb-diff and back.
I would imagine the following workflow: after dumb-diff-set-region-as-buffer1 and dumb-diff-set-region-as-buffer2 are executed, a new window is created below (now windows get closed). Maybe the Dumb Diff - 1 and Dumb Diff - 2 windows become unnecessary, and the original windows can be used instead of these temporary windows.
Thanks for sharing this. This makes a ton of sense. I will definitely be supporting this as either an option when calling dumb-diff
or as its own interactive function (maybe something like dumb-diff-result-only
).
Nice!
Maybe this will be of help for restoring the window layout https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Configurations.html
I guess you'll need a dumb-diff-quit
command which will restore the layout.
@edkolev First attempt at this (#3) is now available via MELPA. Please let me know if you have any feedback. Thanks!
Hm, could you let me know in what order the commands 1. dumb-diff
, 2. dumb-diff-set-region-as-buffer1
, 3. dumb-diff-set-region-as-buffer2
should be executed?
This order of commands does it for me: 2, 3, 1, then dumb-diff-quit
correctly restores the previous layout.
I would suggest that dumb-diff
interactively prompts for 1 or 2 buffers in case dumb-diff-set-region-as-buffer1 / 2
hasn't been called yet.
Here's a small example (I haven't tested it) which always prompts for 2 buffers:
(defun dumb-diff (buf-a buf-b)
(interactive
(let* ((buffer-a
(get-buffer
(read-buffer
"Buffer 1: " (current-buffer))))
(get-buffer
(read-buffer
(format "[Buffer 1 %s] Buffer 2: " buffer-a)
(window-buffer (next-window (selected-window) nil 0)))))
(list buffer-a buffer-b)))
...
)
The above snippet is copied and modified from vdiff
Regarding the implementation, here's a simple way to store the layout: https://github.com/LouisKottmann/zygospore.el/blob/master/zygospore.el#L50
And then restore it: https://github.com/LouisKottmann/zygospore.el/blob/master/zygospore.el#L55
Hope you don't mind the brain dump above, just shared some raw ideas :)
Regarding this specific issue #2, seems like it can be closed.
One more thing: this snippet will bind C-c q
globally:
(use-package dumb-diff
:bind (("C-c d" . dumb-diff)
("C-c 1" . dumb-diff-set-region-as-buffer1)
("C-c 2" . dumb-diff-set-region-as-buffer2)
("C-c q" . dumb-diff-quit))
:ensure t)
Would be better to bind dumb-diff-quit
only when the minor mode is enabled (again, untested snippet):
(use-package dumb-diff
:bind (("C-c d" . dumb-diff)
("C-c 1" . dumb-diff-set-region-as-buffer1)
("C-c 2" . dumb-diff-set-region-as-buffer2)
:map dumb-diff-mode-map
("C-c q" . dumb-diff-quit))
:ensure t)
Hm, could you let me know in what order the commands 1. dumb-diff, 2. dumb-diff-set-region-as-buffer1, 3. dumb-diff-set-region-as-buffer2 should be executed?
So for this case 2,3,1 or 3,2,1 should work.
I would suggest that dumb-diff interactively prompts for 1 or 2 buffers in case dumb-diff-set-region-as-buffer1 / 2 hasn't been called yet.
Thanks for this! I think I'll make this be an option (maybe (setq dumb-diff-prompt-for-empty-buffers t)
?) because I want to keep it simple so if a novice calls dumb-diff
they get a UI they can interact with immediately.
Regarding the implementation, here's a simple way to store the layout: [...]
Thanks again! Any idea if this is better than the current-window-configuration
/set-window-configuration
I am doing now?
Hope you don't mind the brain dump above, just shared some raw ideas :)
I don't mind at all. I really appreciate any feedback. Thanks!
One more thing: this snippet will bind C-c q globally
I was trying to keep it simple to illustrate usage (I am personally using a more complicated hydra
), but you're right I should update it for anyone that blindly copies stuff.
Any idea if this is better than the current-window-configuration/set-window-configuration I am doing now?
No, I'm not aware of the differences.
Here's a vim plugin which is similar to dumb-diff https://github.com/AndrewRadev/linediff.vim
It's main usage is: run :Linediff
on two regions, then the "diff mode layout" is enabled. Just FYI
Hi, this package seems useful to me, thanks for sharing it through melpa.
Would it be possible to preserve the window layout? I would imagine the following workflow: after
dumb-diff-set-region-as-buffer1
anddumb-diff-set-region-as-buffer2
are executed, a new window is created below (now windows get closed). Maybe the*Dumb Diff - 1*
and*Dumb Diff - 2*
windows become unnecessary, and the original windows can be used instead of these temporary windows.