Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

The cursor after quit the ediff session is not restored #39

Open
c02y opened this issue Oct 27, 2016 · 10 comments
Open

The cursor after quit the ediff session is not restored #39

c02y opened this issue Oct 27, 2016 · 10 comments

Comments

@c02y
Copy link

c02y commented Oct 27, 2016

After quitting the ediff session for two different files, the point/cursor will be at the left-top (the head of Differences tree sentence in the ztree buffer) corner of the ztree buffer instead of the point/cursor where the ediff starts.

xiongtx added a commit to xiongtx/ztree that referenced this issue Jan 28, 2017
Clean up Ediff buffers and restore window configuration (back to `ztree`)
after quitting Ediff session.
xiongtx added a commit to xiongtx/ztree that referenced this issue Jan 28, 2017
Clean up Ediff buffers and restore window configuration (back to `ztree`)
after quitting Ediff session.
xiongtx added a commit to xiongtx/ztree that referenced this issue Jan 28, 2017
Clean up Ediff buffers and restore window configuration (back to `ztree`)
after quitting Ediff session.
fourier added a commit that referenced this issue Feb 8, 2017
@fourier
Copy link
Owner

fourier commented Feb 8, 2017

@c02y Hi, could you please verify if the latest version fixes your issue.

@c02y
Copy link
Author

c02y commented Feb 9, 2017

The same result, after quitting ediff, the cursor will jump to the left corner of the ztree buffer.

@rchar01
Copy link

rchar01 commented Feb 15, 2018

I can't reproduce that event.
Cursor is always at the last position.
Probably the problem was solved after recent updates.

@fourier
Copy link
Owner

fourier commented Feb 15, 2018

@c02y could you please try to reproduce it on the latest version from MELPA?

@fourier
Copy link
Owner

fourier commented Apr 8, 2018

Tried to reproduce this issue and couldn't, the cursor is on the position where we left it. Hence I close this issues since there is no updates on how to reproduce it for a year.

@fourier fourier closed this as completed Apr 8, 2018
@c02y
Copy link
Author

c02y commented Apr 9, 2018

I just tried the latest version of ztree (20180408), it is the same result, the cursor will move to the left corner of the buffer after quitting the ediff session.

UPDATE:
FYI: In my old configuration, I make Emacs to open a new frame for comparing two files, and close the new opened frame, kill the two files once I quit the ediff session. When using ztree in such configuration , after quitting ediff session, my cursor will be at the left corner of the ztree buffer.

I tried to remove all my configuration and just install ztree package, then ztree-diff two dirs, RET at two mismatched files, since I removed my old configuration including ediff, Emacs will open the two files comparing windows in the same frame, after I quit the ediff session, the two files will not be killed, I have to manually kill them, anyway, after I kill one window(there are two windows in the current frame, so I close one window), I switch back to the ztree buffer, the cursor is at the right place where the ediff session is started, but the layout is pretty weird, I don't know the word to describe it, but I got two screenshots, one for ztree buffer before opening ediff session, one for after switching back the ztree buffer.
screenshot_2018-04-09_10-13-07-start
screenshot_2018-04-09_10-14-20-after

@fourier fourier reopened this Apr 9, 2018
@fourier
Copy link
Owner

fourier commented Apr 9, 2018

I now understand your issue. The problem is that ztree buffer has changed since the windows size has changed. You need to press "g" to refresh the buffer.

fourier added a commit that referenced this issue Apr 9, 2018
- The window configurations are now stored as a stack rather
  than one buffer-local variable
- Introduced global hook on window configuration change
  to redraw the contents of visible ztree buffers
@fourier
Copy link
Owner

fourier commented Apr 9, 2018

Ok, please @c02y try again now. I've tested with default emacs running with "emacs -q" and manually loaded ztree sources.

@c02y
Copy link
Author

c02y commented Apr 10, 2018

I tried in the minimal configuration, the layout is normal now, but in my old configuration, it is still the same result, I'll try to analyze my configuration piece by piece.


UPDATE1:

In the minimal configuration, If I RET at the Orphan file, ztree will open the single file in Emacs(no ediff session), after I kill the single buffer, back to the ztree buffer, the cursor will still be moved to the left corner of the ztree buffer.


UPDATE2:

It seems the cursor-move-to-left-corner problem is caused by my ediff related configuration.

Either of these two parts will make the cursor move to the left corner of ztree buffer once I quit the ediff session, I have to comment out both of them.

Part1:

;; delete these buffers (if they are not modified) after q
(setq ediff-keep-variants nil)

Part2:

;; use new frame (fullscreen) for ediff session and close the frame after exiting
(defvar pre-ediff-window-configuration nil
  "window configuration to use")
(defvar new-ediff-frame-to-use nil
  "new frame for ediff to use")
(defun save-my-window-configuration ()
  (interactive)
  (setq pre-ediff-window-configuration (current-window-configuration))
  (select-frame-set-input-focus (setq new-ediff-frame-to-use (new-frame)))
  (toggle-frame-fullscreen))
(add-hook 'ediff-before-setup-hook 'save-my-window-configuration)
(defun restore-my-window-configuration ()
  (interactive)
  (when (framep new-ediff-frame-to-use)
	(delete-frame new-ediff-frame-to-use)
	(setq new-ediff-frame-to-use nil))
  (when (window-configuration-p pre-ediff-window-configuration)
	(set-window-configuration pre-ediff-window-configuration)))
(add-hook 'ediff-after-quit-hook-internal 'restore-my-window-configuration)

Let's ignore the Orphan file first and focus on my ediff configuration now.

If I enable part1 and disable part2(no new frame will be created), the cursor will be normal once I quit the ediff session .

If I disable part1 and enable part2, a new frame will be created, if I don't quit ediff and switch back to the ztree frame, I can see that the cursor is already at the left corner of the ztree buffer, and the layout is different too. Check the 3 screenshots (Note that the line with underline is where my cursor is).

Screenshot 1, before the ediff session is started, the cursor is at the mismatched-files line:
screenshot_2018-04-10_10-50-45

Screenshot 2, not quit ediff session and switch back to ztree frame, the cursor is at the left cursor, the layout is wrong:
screenshot_2018-04-10_10-51-09

Screenshot 3, after quitting ediff session, the cursor is at the left cursor of the ztree buffer and the layout is normal now:
screenshot_2018-04-10_11-01-02

Hopes the info I've collected will help you with solving this problem completely.

@trapperhoney
Copy link

I just independently stumbled across this same problem. For me, it was related to the ediff-keep-variants option described above. The following was sufficient to reproduce with version 20210415.1947 of ztree (with sample directories a and b):

emacs -Q \
  --eval '(package-initialize)' \
  --eval '(setq-default ediff-keep-variants nil)' \
  --eval '(ztree-diff "a" "b")'

At first I thought this may be related to the fact that there are prompts that come up to confirm closing the ediff variant buffers. But short circuiting the prompts with hint like

(defun always-y (f &rest r)
  (cl-letf (((symbol-function 'y-or-n-p)(lambda (prompt) t)))(apply f r)))
(advice-add 'ediff-quit :around #'always-y)

doesn't help. The cursor still gets reset to the beginning of the ztree buffer. Looking at the ediff cleanup code, I didn't see anything obvious that would make ztree behave differently...

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

No branches or pull requests

4 participants