[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff a094450 048/258: Tweak line translation rules f
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff a094450 048/258: Tweak line translation rules for better scrolling |
Date: |
Wed, 17 May 2017 08:13:21 -0400 (EDT) |
branch: scratch/add-vdiff
commit a0944503cb7c309d2e3a6f6f8ad4ab09f18b5aad
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Tweak line translation rules for better scrolling
Want returned line to be monotonic; otherwise, scrolling jumps up and down
---
vdiff.el | 92 ++++++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 58 insertions(+), 34 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index ba23f82..d3261bd 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -637,47 +637,71 @@ changes under point or on the immediately preceding line."
(a-beg (car a-lines))
(a-end (or (cdr-safe a-lines)
(car a-lines)))
+ (a-len (1+ (- a-end a-beg)))
(b-lines (nth 2 entry))
(b-beg (car b-lines))
(b-end (or (cdr-safe b-lines)
- (car b-lines))))
+ (car b-lines)))
+ (b-len (1+ (- b-end b-beg))))
(cond ((string= code "d")
- (push (cons (1- a-beg) b-beg) new-map)
- (push (cons (1+ a-end) (1+ b-end)) new-map))
+ (push (list (1- a-beg) b-beg nil t entry) new-map)
+ (push (list (1+ a-end) (1+ b-end) nil nil entry) new-map))
((string= code "a")
- (push (cons a-beg (1- b-beg)) new-map)
- (push (cons (1+ a-end) (1+ b-end)) new-map))
- ((and (string= code "c"))
- (push (cons (1- a-beg) (1- b-beg)) new-map)
- (push (cons (1+ a-end) (1+ b-end)) new-map)))))
- (setq vdiff--line-map (nreverse new-map))))
+ (push (list a-beg (1- b-beg) t nil entry) new-map)
+ (push (list (1+ a-end) (1+ b-end) nil nil entry) new-map))
+ ((> a-len b-len)
+ (push (list (1- a-beg) (1- b-beg) nil nil entry) new-map)
+ (push (list (+ a-beg b-len) b-end nil t entry) new-map)
+ (push (list (1+ a-end) (1+ b-end) nil nil entry) new-map))
+ ((< a-len b-len)
+ (push (list (1- a-beg) (1- b-beg) nil nil entry) new-map)
+ (push (list a-end (+ b-beg a-len) t nil entry) new-map)
+ (push (list (1+ a-end) (1+ b-end) nil nil entry) new-map))
+
+ (t
+ (push (list (1- a-beg) (1- b-beg) nil nil entry) new-map)
+ (push (list (1+ a-end) (1+ b-end) nil nil entry) new-map)))))
+ (setq vdiff--line-map (cons (list 0 0) (nreverse new-map)))))
(defun vdiff--translate-line (line &optional B-to-A)
- (let ((nearest-line
- (catch 'closest
- (let (prev-entry)
- (dolist (entry vdiff--line-map)
- (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
- (+ (- line (car nearest-line)) (cdr nearest-line)))
- (t line))))
+ (interactive (list (line-number-at-pos) (vdiff--buffer-b-p)))
+ (let* ((last-entry
+ (catch 'closest
+ (let (prev-entry)
+ (dolist (entry vdiff--line-map)
+ (let ((map-line
+ (if B-to-A (cadr entry) (car entry)))
+ (prev-map-line
+ (when prev-entry
+ (if B-to-A (cadr prev-entry) (car prev-entry)))))
+ (cond ((< map-line line)
+ (setq prev-entry entry))
+ ((= map-line line)
+ (throw 'closest entry))
+ (t
+ (throw 'closest prev-entry)))))
+ (throw 'closest prev-entry))))
+ res)
+ (unless last-entry
+ (setq last-entry (list line line))
+ (message "Error in line translation"))
+ (prog1
+ (setq res
+ (let ((this-map-line
+ (if B-to-A (cadr last-entry) (car last-entry)))
+ (this-in-subtraction (nth (if B-to-A 3 2) last-entry))
+ (other-map-line
+ (if B-to-A (car last-entry) (cadr last-entry)))
+ (other-in-subtraction (nth (if B-to-A 2 3) last-entry)))
+ (cond (other-in-subtraction
+ (1+ other-map-line))
+ (this-in-subtraction
+ (1- other-map-line))
+ (t
+ (+ (- line this-map-line) other-map-line)))))
+ (when (called-interactively-p)
+ (message "This line: %s; Other line %s; In sub %s; entry %s" line res
(nth (if B-to-A 2 3) last-entry) last-entry))
+ )))
(defun vdiff-goto-corresponding-line (line in-b)
"Jump to the line in the other vdiff buffer that corresponds to
- [elpa] branch scratch/add-vdiff created (now 819ea4b), Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b6b37a5 022/258: Broaden search for overlays at point, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4b7f3d1 004/258: Make buffer names easier to read in functions, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1155601 014/258: Fix problem with restarting mode and temp files, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1b96390 021/258: Use fringes for open folds, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8a51468 025/258: Don't close fold on point on refresh, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4d5299e 031/258: Fix alignment of folds next to subtractions, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff f826315 033/258: Increase default fold padding, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 3e1169c 043/258: Screenshot showing off theme integration, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff a094450 048/258: Tweak line translation rules for better scrolling,
Justin Burkett <=
- [elpa] scratch/add-vdiff 0fd1837 063/258: Update screenshot, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b02b59e 072/258: Whitespace cleanup, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff b2ba7ab 070/258: Move hydra to main file and avoid dependency, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff bfdfc74 053/258: Modify gitignore, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d25fe21 054/258: More arg name changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 875e6ce 057/258: Merge pull request #2 from purcell/patch-1, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1640078 061/258: Merge remote-tracking branch 'origin/master', Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c6c959d 071/258: Fix nth-change at beginning and end of buffer, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d07e9fb 056/258: Fix typo in package description, remove redundant "for Emacs", Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 69c85cb 080/258: Better way to trigger other window update, Justin Burkett, 2017/05/17