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

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

[elpa] externals/ace-window ac89475 73/92: Fix handling of horizontally


From: Stefan Monnier
Subject: [elpa] externals/ace-window ac89475 73/92: Fix handling of horizontally scrolled windows and buffer-begin error
Date: Wed, 17 Mar 2021 18:39:25 -0400 (EDT)

branch: externals/ace-window
commit ac89475dcb9eac40fe0a6b1c7da58c506abe8718
Author: Bob Weiner <rsw@gnu.org>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    Fix handling of horizontally scrolled windows and buffer-begin error
    
    Re #78
    Fixes #142
    Fixes #166
    Fixes #168
---
 ace-window.el | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/ace-window.el b/ace-window.el
index 2753c19..458a300 100644
--- a/ace-window.el
+++ b/ace-window.el
@@ -268,6 +268,10 @@ or
   "Store the read-only empty buffers which had to be modified.
 Modify them back eventually.")
 
+(defvar aw--windows-hscroll nil
+  "List of (window . hscroll-columns) items, each listing a window whose
+  horizontal scroll will be restored upon ace-window action completion.")
+
 (defun aw--done ()
   "Clean up mode line and overlays."
   ;; mode line
@@ -281,8 +285,20 @@ Modify them back eventually.")
       (when (string= (buffer-string) " ")
         (let ((inhibit-read-only t))
           (delete-region (point-min) (point-max))))))
+  (aw--restore-windows-hscroll)
   (setq aw-empty-buffers-list nil))
 
+(defun aw--restore-windows-hscroll ()
+  "Restore horizontal scroll of windows from `aw--windows-hscroll' list."
+  (let (wnd hscroll)
+    (mapc (lambda (wnd-and-hscroll)
+            (setq wnd (car wnd-and-hscroll)
+                  hscroll (cdr wnd-and-hscroll))
+            (when (window-live-p wnd)
+              (set-window-hscroll wnd hscroll)))
+          aw--windows-hscroll))
+  (setq aw--windows-hscroll nil))
+
 (defun aw--overlay-str (wnd pos path)
   "Return the replacement text for an overlay in WND at POS,
 accessible by typing PATH."
@@ -312,18 +328,35 @@ accessible by typing PATH."
              (max 0 (1- (string-width old-str)))
              ?\ ))))))
 
+(defun aw--point-visible-p ()
+  "Return non-nil if point is visible in the selected window, else nil when 
horizontal scrolling has moved it off screen."
+  (and (>= (- (current-column) (window-hscroll)) 0)
+       (< (- (current-column) (window-hscroll))
+          (window-width))))
+
 (defun aw--lead-overlay (path leaf)
   "Create an overlay using PATH at LEAF.
 LEAF is (PT . WND)."
   ;; Properly adds overlay in visible region of most windows except for any one
   ;; receiving output while this function is executing, since that moves point,
   ;; potentially shifting the added overlay outside the window's visible 
region.
-  (let ((wnd (cdr leaf)))
+  (let ((wnd (cdr leaf))
+        ;; Prevent temporary movement of point from scrolling any window.
+        (scroll-margin 0))
     (with-selected-window wnd
       (when (= 0 (buffer-size))
         (push (current-buffer) aw-empty-buffers-list)
         (let ((inhibit-read-only t))
           (insert " ")))
+      ;; If point is not visible due to horizontal scrolling of the
+      ;; window, this next expression temporarily scrolls the window
+      ;; right until point is visible, so that the leading-char can be
+      ;; seen when it is inserted.  When ace-window's action finishes,
+      ;; the horizontal scroll is restored by (aw--done).
+      (while (and (not (aw--point-visible-p))
+                  (not (zerop (window-hscroll)))
+                  (progn (push (cons (selected-window) (window-hscroll)) 
aw--windows-hscroll) t)
+                  (not (zerop (scroll-right)))))
       (let* ((prev)
              (vertical-pos (if (eq aw-char-position 'left) -1 0))
              (horizontal-pos (if (zerop (window-hscroll)) 0 (1+ 
(window-hscroll))))
@@ -340,7 +373,7 @@ LEAF is (PT . WND)."
                 (while (and (/= prev (point)) (eolp))
                   (setq prev (point))
                   (unless (bobp)
-                    (line-move -1 nil)
+                    (line-move -1 t)
                     (move-to-column horizontal-pos)))
                 (recenter vertical-pos)
                 (point)))
@@ -564,6 +597,7 @@ selected window).
 Prefixed with two \\[universal-argument]'s, deletes the selected
 window."
   (interactive "p")
+  (setq avy-current-path "")
   (cl-case arg
     (0
      (let ((aw-ignore-on (not aw-ignore-on)))
@@ -588,12 +622,12 @@ window."
 This is determined by their respective window coordinates.
 Windows are numbered top down, left to right."
   (let* ((f1 (window-frame wnd1))
-        (f2 (window-frame wnd2))
-        (e1 (window-edges wnd1))
-        (e2 (window-edges wnd2))
-        (p1 (frame-position f1))
-        (p2 (frame-position f2))
-        (nl (or (null (car p1)) (null (car p2)))))
+         (f2 (window-frame wnd2))
+         (e1 (window-edges wnd1))
+         (e2 (window-edges wnd2))
+         (p1 (frame-position f1))
+         (p2 (frame-position f2))
+         (nl (or (null (car p1)) (null (car p2)))))
     (cond ((and (not nl) (< (car p1) (car p2)))
            (not aw-reverse-frame-list))
           ((and (not nl) (> (car p1) (car p2)))



reply via email to

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