[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff bac92b3 037/258: Improve line translation and c
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff bac92b3 037/258: Improve line translation and command mirroring |
Date: |
Wed, 17 May 2017 08:13:18 -0400 (EDT) |
branch: scratch/add-vdiff
commit bac92b3af67d6e853a4335bd873affc202e1494b
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Improve line translation and command mirroring
---
vdiff.el | 47 ++++++++++++++++++++++++++++-------------------
1 file changed, 28 insertions(+), 19 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index 8ee95e6..34c1804 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -177,7 +177,6 @@ lines hidden."
(defvar vdiff--diff-code-regexp
"^\\([0-9]+\\),?\\([0-9]+\\)?\\([adc]\\)\\([0-9]+\\),?\\([0-9]+\\)?")
(defvar vdiff--inhibit-window-switch nil)
-(defvar vdiff--scroll-command-cnt 0)
(defvar vdiff--inhibit-sync nil)
(defvar vdiff--line-map nil)
@@ -613,14 +612,24 @@ changes under point or on the immediately preceding line."
(defun vdiff--translate-line (line &optional B-to-A)
(let ((nearest-line
(catch 'closest
- (let (closest)
+ (let (prev-entry)
(dolist (entry vdiff--line-map)
- (if (> (if B-to-A
- (cdr entry)
- (car entry)) line)
- (throw 'closest closest)
- (setq closest entry)))
- (throw 'closest closest)))))
+ (let ((map-line
+ (if B-to-A (cdr entry) (car entry)))
+ (prev-map-line
+ (when prev-entry
+ (if B-to-A (cdr prev-entry) (car prev-entry)))))
+ (cond ((< map-line line)
+ (setq prev-entry entry))
+ ((= map-line line)
+ (throw 'closest entry))
+ ((and prev-map-line
+ (< (- line prev-map-line)
+ (- map-line line)))
+ (throw 'closest prev-entry))
+ (t
+ (throw 'closest entry)))))
+ (throw 'closest prev-entry)))))
(cond ((and nearest-line B-to-A)
(+ (- line (cdr nearest-line)) (car nearest-line)))
(nearest-line
@@ -697,21 +706,22 @@ buffer and center both buffers at this line."
;; they are next-line and previous-line
(when (and (memq real-this-command vdiff-mirrored-commands)
(not vdiff--inhibit-sync))
- (let ((this-line (line-number-at-pos))
+ (let* ((this-line (line-number-at-pos))
+ (other-line (vdiff--translate-line
+ this-line (vdiff--buffer-b-p)))
;; This is necessary to not screw up the cursor column after calling
;; next-line or previous-line again from the other buffer
temporary-goal-column)
(vdiff--with-other-window
(ignore-errors
(let ((vdiff--inhibit-sync t))
- (call-interactively real-this-command))
- (if (< vdiff--scroll-command-cnt 40)
- (cl-incf vdiff--scroll-command-cnt)
- ;; (message "syncing lines")
- (setq vdiff--scroll-command-cnt 0)
- (vdiff--move-to-line
- (vdiff--translate-line
- this-line (vdiff--buffer-a-p)))))))))
+ (when (or
+ (not (memq this-command '(next-line previous-line)))
+ (and (eq this-command 'next-line)
+ (< (line-number-at-pos) other-line))
+ (and (eq this-command 'previous-line)
+ (> (line-number-at-pos) other-line)))
+ (call-interactively real-this-command))))))))
(defun vdiff-open-fold (beg end)
"Open folds between BEG and END, as well as corresponding ones
@@ -899,8 +909,7 @@ commands like `vdiff-files' or `vdiff-buffers'."
(when (process-live-p vdiff--process-buffer)
(kill-process vdiff--process-buffer))
(when (buffer-live-p vdiff--process-buffer)
- (kill-buffer vdiff--process-buffer))
- (setq vdiff--scroll-command-cnt 0))))
+ (kill-buffer vdiff--process-buffer)))))
(define-minor-mode vdiff-scroll-lock-mode
"Lock scrolling between vdiff buffers. This minor mode will be
- [elpa] scratch/add-vdiff 10b7760 018/258: Add faces, (continued)
- [elpa] scratch/add-vdiff 10b7760 018/258: Add faces, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 952440e 002/258: Initial commit, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 245850f 028/258: Load cl-lib for using its function, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 988c476 027/258: Add new defcustoms to README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b77efe3 008/258: Add README and improve docstrings, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff ce10994 003/258: Introduce defcustoms and use lists instead of .., Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff ad6035d 015/258: Implement folding of unchanged lines, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff af75c6d 036/258: Add vdiff-exit, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e8834fa 035/258: Fix fold size calcs, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 9547850 041/258: Use diff faces from theme, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff bac92b3 037/258: Improve line translation and command mirroring,
Justin Burkett <=
- [elpa] scratch/add-vdiff 6b6f6e7 044/258: Force fold refresh on window size change, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff e005d43 058/258: Delete overlays right away on sending changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1cf0730 055/258: Fix compiler warnings, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 697bb79 060/258: Prefer last element of multiple in line map, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3207365 064/258: Satisfy compiler, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8b6cb54 218/258: vdiff-magit: Port resolve, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 617265b 238/258: vdiff-magit: Remove unused magit-ediff code, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 6f89757 231/258: vdiff-magit: Resurrect resolve, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 0f8dd15 239/258: vdiff: Improve a couple of docstrings, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d8cfb8f 243/258: vdiff: Don't use scroll-lock-mode programmatically, Justin Burkett, 2017/05/17