emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ztree 4879576 19/23: Issue #39: restore cursor position


From: Stefan Monnier
Subject: [elpa] externals/ztree 4879576 19/23: Issue #39: restore cursor position and window configuration
Date: Thu, 17 Dec 2020 23:17:06 -0500 (EST)

branch: externals/ztree
commit 487957664cedc61d70feccc881092eef6746977b
Author: Alexey Veretennikov <alexey.veretennikov@gmail.com>
Commit: Alexey Veretennikov <alexey.veretennikov@gmail.com>

    Issue #39: restore cursor position and window configuration
    
    - 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
---
 ztree-diff.el | 13 +++++++++----
 ztree-view.el | 11 +++++++++++
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/ztree-diff.el b/ztree-diff.el
index 5629237..3ff39fb 100644
--- a/ztree-diff.el
+++ b/ztree-diff.el
@@ -28,6 +28,7 @@
 ;;; Commentary:
 
 ;;; Code:
+(eval-when-compile (require 'cl))
 (require 'ztree-view)
 (require 'ztree-diff-model)
 
@@ -101,8 +102,10 @@ By default paths starting with dot (like .git) are 
ignored")
 (defvar-local ztree-diff-wait-message nil
   "Message showing while constructing the diff tree.")
 
-(defvar-local ztree-diff-ediff-previous-window-configuration nil
-  "Window configuration prior to calling `ediff'.")
+(defvar ztree-diff-ediff-previous-window-configurations nil
+  "Window configurations prior to calling `ediff'.
+A queue of window configurations, allowing
+to restore last configuration even if there were a couple of ediff sessions")
 
 ;;;###autoload
 (define-minor-mode ztreediff-mode
@@ -238,7 +241,8 @@ Argument NODE node containing paths to files to call a diff 
on."
 See the Info node `(ediff) hooks'.
 
 This hook function removes itself."
-  (setq ztree-diff-ediff-previous-window-configuration 
(current-window-configuration))
+  (push (current-window-configuration) 
ztree-diff-ediff-previous-window-configurations)
+  (setq ztree-prev-position (cons (line-number-at-pos (point)) 
(current-column)))
   (remove-hook 'ediff-before-setup-hook 
#'ztree-diff-ediff-before-setup-hook-function))
 
 (defun ztree-diff-ediff-quit-hook-function ()
@@ -247,7 +251,8 @@ This hook function removes itself."
 See the Info node `(ediff) hooks'.
 
 This hook function removes itself."
-  (set-window-configuration ztree-diff-ediff-previous-window-configuration)
+  (set-window-configuration (pop 
ztree-diff-ediff-previous-window-configurations))
+  (ztree-refresh-buffer)
   (remove-hook 'ediff-quit-hook #'ztree-diff-ediff-quit-hook-function))
 
 (defun ztree-diff-ediff (file-a file-b &optional startup-hooks)
diff --git a/ztree-view.el b/ztree-view.el
index c539699..e053210 100644
--- a/ztree-view.el
+++ b/ztree-view.el
@@ -745,6 +745,16 @@ change the root node to the node specified."
   (ztree-scroll-to-line
    (+ count (line-number-at-pos))))
 
+;;;###autoload
+(defun ztree-view-on-window-configuration-changed ()
+  "Hook called then window configuration changed to resize buffer's contents"
+  ;; refresh visible ztree buffers
+  (walk-windows (lambda (win) 
+                  (with-current-buffer (window-buffer win)
+                    (when (derived-mode-p 'ztree-mode)
+                      (ztree-refresh-buffer))))
+                nil 'visible))
+
 (defun ztree-view (
                    buffer-name
                    start-node
@@ -788,6 +798,7 @@ Optional argument NODE-SIDE-FUN Determines the side of the 
node."
     (setq ztree-node-face-fun face-fun)
     (setq ztree-node-action-fun action-fun)
     (setq ztree-node-side-fun node-side-fun)
+    (add-hook 'window-configuration-change-hook 
#'ztree-view-on-window-configuration-changed)
     (ztree-refresh-buffer)))
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]