[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff 717d5b6 121/258: Allow failed line translation
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff 717d5b6 121/258: Allow failed line translation |
Date: |
Wed, 17 May 2017 08:13:35 -0400 (EDT) |
branch: scratch/add-vdiff
commit 717d5b61936b04dd8ef2ce952606ec2ec3be62d1
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Allow failed line translation
---
vdiff.el | 88 +++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 48 insertions(+), 40 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index 7b7f47d..fcea0b1 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -925,29 +925,30 @@ just deleting text in the other buffer."
"Translate LINE in buffer A to corresponding line in buffer
B. Go from buffer B to A if B-to-A is non nil."
(interactive (list (line-number-at-pos) (vdiff--buffer-b-p)))
- (let* ((map (if B-to-A vdiff--b-a-line-map vdiff--a-b-line-map))
- (last-entry
- (catch 'closest
- (let (prev-entry)
- (dolist (entry map)
- (let ((map-line (car 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 (cons (+ (- line (car last-entry)) (cadr last-entry))
- (nth 2 last-entry)))
- (when (called-interactively-p 'interactive)
- (message "This line: %s; Other line %s; vscroll-state %s; entry %s"
- line res (cdr res) last-entry)))))
+ (let ((map (if B-to-A vdiff--b-a-line-map vdiff--a-b-line-map))
+ last-entry res)
+ (when map
+ (setq last-entry
+ (catch 'closest
+ (let (prev-entry)
+ (dolist (entry map)
+ (let ((map-line (car entry)))
+ (cond ((< map-line line)
+ (setq prev-entry entry))
+ ((= map-line line)
+ (throw 'closest entry))
+ (t
+ (throw 'closest prev-entry)))))
+ (throw 'closest prev-entry))))
+ (unless last-entry
+ (setq last-entry (list line line))
+ (message "Error in line translation"))
+ (prog1
+ (setq res (cons (+ (- line (car last-entry)) (cadr last-entry))
+ (nth 2 last-entry)))
+ (when (called-interactively-p 'interactive)
+ (message "This line: %s; Other line %s; vscroll-state %s; entry %s"
+ line res (cdr res) last-entry))))))
(defun vdiff-switch-buffer (line in-b)
"Jump to the line in the other vdiff buffer that corresponds to
@@ -955,7 +956,9 @@ the current one."
(interactive (list (line-number-at-pos) (vdiff--buffer-b-p)))
(vdiff-refresh)
(select-window (vdiff--other-window))
- (vdiff--move-to-line (car (vdiff--translate-line line in-b))))
+ (let ((line (car-safe (vdiff--translate-line line in-b))))
+ (when line
+ (vdiff--move-to-line line))))
(defun vdiff--recenter-both ()
(recenter)
@@ -966,10 +969,11 @@ the current one."
buffer. This is usually not necessary."
(interactive (list (line-number-at-pos)
(not (vdiff--buffer-a-p))))
- (let ((new-line (car (vdiff--translate-line
+ (let ((new-line (car-safe (vdiff--translate-line
line (not in-a)))))
- (vdiff--with-other-window
- (goto-char (vdiff--pos-at-line-beginning new-line)))))
+ (when new-line
+ (vdiff--with-other-window
+ (goto-char (vdiff--pos-at-line-beginning new-line))))))
(defun vdiff-sync-and-center ()
"Sync point in the other vdiff buffer to the line in this
@@ -1021,23 +1025,27 @@ buffer)."
(start-translation
(vdiff--translate-line this-start-line in-b))
(other-curr-start (window-start other-window))
- (other-start-line (car start-translation))
- (other-start-pos (vdiff--pos-at-line-beginning
- other-start-line other-buffer))
- (scroll-amt (cdr start-translation))
+ (other-start-line (car-safe start-translation))
+ (other-start-pos (when other-start-line
+ (vdiff--pos-at-line-beginning
+ other-start-line other-buffer)))
+ (scroll-amt (cdr-safe start-translation))
(this-line (+ (count-lines window-start (point))
this-start-line))
(translation (vdiff--translate-line this-line in-b))
- (other-pos (vdiff--pos-at-line-beginning
- (car translation) other-buffer))
+ (other-pos (when translation
+ (vdiff--pos-at-line-beginning
+ (car translation) other-buffer)))
(vdiff--in-scroll-hook t))
- (set-window-point other-window other-pos)
- (unless (= other-curr-start other-start-pos)
- (set-window-start other-window other-start-pos))
- (vdiff--set-vscroll-and-force-update
- other-window
- (when (eq vdiff-subtraction-style 'full)
- scroll-amt))))))
+ (when (and other-start-pos
+ other-pos)
+ (set-window-point other-window other-pos)
+ (unless (= other-curr-start other-start-pos)
+ (set-window-start other-window other-start-pos))
+ (vdiff--set-vscroll-and-force-update
+ other-window
+ (when (eq vdiff-subtraction-style 'full)
+ scroll-amt)))))))
;; (defun vdiff--post-command-hook ()
;; "Sync scroll for `vdiff--force-sync-commands'."
- [elpa] scratch/add-vdiff e94d187 059/258: Simplify adding overlays, (continued)
- [elpa] scratch/add-vdiff e94d187 059/258: Simplify adding overlays, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4596948 081/258: Reduce load in vdiff--scroll-function, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff d65fcd7 083/258: Simplify commentary, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 0777eda 099/258: Add vdiff-refresh binding to prefix map, Justin Burkett, 2017/05/17
- [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 <=
- [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, 2017/05/17
- [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