fourier / ztree

Directory tree comparison mode for Emacs
http://www.emacswiki.org/emacs/ZtreeDiff
GNU General Public License v3.0
239 stars 21 forks source link

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

Open c02y opened 7 years ago

c02y commented 7 years ago

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.

fourier commented 7 years ago

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

c02y commented 7 years ago

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

rchar01 commented 6 years ago

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

fourier commented 6 years ago

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

fourier commented 6 years ago

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.

c02y commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

c02y commented 6 years ago

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 commented 1 year ago

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...