[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff e556705 151/258: Simplify scroll function
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff e556705 151/258: Simplify scroll function |
Date: |
Wed, 17 May 2017 08:13:41 -0400 (EDT) |
branch: scratch/add-vdiff
commit e55670506b55bfcf5609e2898c5cd8ce6e7e90bc
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Simplify scroll function
---
vdiff.el | 102 ++++++++++++++++++++++++++++-----------------------------------
1 file changed, 45 insertions(+), 57 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index 697d765..de47cfe 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -246,6 +246,9 @@ because those are handled differently.")
(cadr vdiff--buffers)
(car vdiff--buffers)))))
+(defun vdiff--all-windows ()
+ (mapcar #'get-buffer-window vdiff--buffers))
+
(defun vdiff--all-overlays (ovr)
(overlay-get ovr 'vdiff-hunk-overlays))
@@ -1228,82 +1231,67 @@ buffer)."
(lambda ()
(unless vdiff--setting-vscroll
(let ((vdiff--setting-vscroll t))
- (when vscroll
+ (when (eq vdiff-subtraction-style 'full)
(set-window-vscroll window vscroll))
(force-window-update window))))))
(defun vdiff--flag-new-command ()
(setq vdiff--new-command t))
+(defun vdiff--other-win-scroll-data (window window-start &optional buf-c)
+ ;; need other-win, start-pos, pos and scroll-amt
+ (let* ((other-buf (nth (if buf-c 1 0) (vdiff--unselected-buffers)))
+ (other-win (nth (if buf-c 1 0) (vdiff--unselected-windows)))
+ (start-line (line-number-at-pos window-start))
+ (start-trans (vdiff--translate-line start-line))
+ (start-trans (if buf-c
+ (cdr start-trans)
+ (car start-trans)))
+ (trans (vdiff--translate-line
+ (+ (count-lines window-start (point))
+ start-line)))
+ (trans (if buf-c (cdr trans) (car trans))))
+ (when (and start-trans trans)
+ (list other-win
+ (vdiff--pos-at-line-beginning (car start-trans) other-buf)
+ (vdiff--pos-at-line-beginning (car trans) other-buf)
+ (cdr start-trans)))))
+
(defun vdiff--scroll-function (&optional window window-start)
"Sync scrolling of all vdiff windows."
(let* ((window (or window (selected-window)))
- (window-start (or window-start (window-start)))
- (buf-a (car vdiff--buffers))
- (buf-b (cadr vdiff--buffers))
- (buf-c (nth 2 vdiff--buffers))
- (win-a (get-buffer-window buf-a))
- (win-b (get-buffer-window buf-b))
- (win-c (when buf-c (get-buffer-window buf-c))))
+ (window-start (or window-start (window-start))))
(when (and (eq window (selected-window))
- (window-live-p win-a)
- (window-live-p win-b)
- (window-live-p win-c)
- (memq window (list win-a win-b win-c))
+ (cl-every #'window-live-p (vdiff--all-windows))
+ (vdiff--buffer-p)
(not vdiff--in-scroll-hook)
vdiff--new-command)
(setq vdiff--new-command nil)
- (let* ((in-b (eq window win-b))
- (other-windows (vdiff--unselected-windows))
- (other-buffers (vdiff--unselected-buffers))
+ (let* ((2-scroll-data (vdiff--other-win-scroll-data
+ window window-start))
+ (2-win (nth 0 2-scroll-data))
+ (2-start-pos (nth 1 2-scroll-data))
+ (2-pos (nth 2 2-scroll-data))
+ (2-scroll (nth 3 2-scroll-data))
;; 1 is short for this; 2 is the first other and 3 is the second
- (1-start-line (line-number-at-pos window-start))
- (1-line (+ (count-lines window-start (point))
- 1-start-line))
- (start-translation
- (vdiff--translate-line 1-start-line))
- (translation (vdiff--translate-line 1-line))
- (2-start-trans (car start-translation))
- (2-trans (car translation))
- (2-win (car other-windows))
- (2-buf (car other-buffers))
- (2-curr-start (window-start 2-win))
- (2-start-line (car 2-start-trans))
- (2-start-pos (when 2-start-line
- (vdiff--pos-at-line-beginning
- 2-start-line 2-buf)))
- (2-scroll-amt (cdr 2-start-trans))
- (2-pos (when translation
- (vdiff--pos-at-line-beginning (car 2-trans) 2-buf)))
(vdiff--in-scroll-hook t))
- (when (and 2-start-pos 2-pos)
+ (when (and 2-pos 2-start-pos)
(set-window-point 2-win 2-pos)
- (unless (= 2-curr-start 2-start-pos)
- (set-window-start 2-win 2-start-pos))
- (vdiff--set-vscroll-and-force-update
- 2-win (when (eq vdiff-subtraction-style 'full)
- 2-scroll-amt)))
+ (set-window-start 2-win 2-start-pos)
+ (vdiff--set-vscroll-and-force-update 2-win 2-scroll))
(when vdiff-3way-mode
- (let* ((3-win (cadr other-windows))
- (3-buf (cadr other-buffers))
- (3-start-trans (cdr start-translation))
- (3-trans (cdr translation))
- (3-curr-start (window-start 3-win))
- (3-start-line (car 3-start-trans))
- (3-start-pos
- (when 3-start-line
- (vdiff--pos-at-line-beginning 3-start-line 3-buf)))
- (3-scroll-amt (cdr 3-start-trans))
- (3-pos
- (when translation
- (vdiff--pos-at-line-beginning (car 3-trans) 3-buf))))
+ (let*
+ ((3-scroll-data (vdiff--other-win-scroll-data
+ window window-start t))
+ (3-win (nth 0 3-scroll-data))
+ (3-start-pos (nth 1 3-scroll-data))
+ (3-pos (nth 2 3-scroll-data))
+ (3-scroll (nth 3 3-scroll-data))
+ (vdiff--in-scroll-hook t))
(when (and 3-start-pos 3-pos)
(set-window-point 3-win 3-pos)
- (unless (= 3-curr-start 3-start-pos)
- (set-window-start 3-win 3-start-pos))
- (vdiff--set-vscroll-and-force-update
- 3-win (when (eq vdiff-subtraction-style 'full)
- 3-scroll-amt)))))))))
+ (set-window-start 3-win 3-start-pos)
+ (vdiff--set-vscroll-and-force-update 3-win 3-scroll))))))))
;; (defun vdiff--post-command-hook ()
;; "Sync scroll for `vdiff--force-sync-commands'."
- [elpa] scratch/add-vdiff d46f686 094/258: Make README table narrower, (continued)
- [elpa] scratch/add-vdiff d46f686 094/258: Make README table narrower, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 803fd6d 098/258: Add subtraction style option, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 5f2c72c 105/258: Change alignment algorithm, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff f481a82 112/258: Add refresh timer delay, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 28d28b7 116/258: Add restore windows command, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 905be9c 122/258: Map remove refinements command, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 717d5b6 121/258: Allow failed line translation, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b267885 137/258: Merge branch 'gvol-master', Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8daa391 133/258: Add case and whitespace toggles, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 95a1230 154/258: Fix vscroll bug, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e556705 151/258: Simplify scroll function,
Justin Burkett <=
- [elpa] scratch/add-vdiff f36b6b2 162/258: Fix line-translation error, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 13f553f 163/258: Fix fold logic for diff3, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 88e7f1c 178/258: Remove min-window-width, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 679617c 199/258: Force update of window-start on manual scroll-function, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff dcf811e 188/258: Add new on-quit options, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c82f2b5 090/258: Add docs on refinements, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3fcf4b9 101/258: Fix sign problem in adding hunk overlays, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 9346e46 106/258: Simplify method for setting vscroll, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c46b76b 111/258: Set window point on scroll, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff fd8c973 109/258: Remove post-command-hook, Justin Burkett, 2017/05/17