[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff 4ea6afb 082/258: Add docstrings and rearrange s
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff 4ea6afb 082/258: Add docstrings and rearrange some calls |
Date: |
Wed, 17 May 2017 08:13:27 -0400 (EDT) |
branch: scratch/add-vdiff
commit 4ea6afbe9a083bfd1c1f9c0048c2b8f4713993b0
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Add docstrings and rearrange some calls
---
vdiff.el | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index e8c9cff..a1691c5 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -258,6 +258,7 @@ text on the first line, and the width of the buffer."
(1+ (overlay-end ovr)))))))
(defmacro vdiff--with-other-window (&rest body)
+ "Execute BODY in other vdiff window."
`(when (and (vdiff--buffer-p)
(not vdiff--inhibit-window-switch)
(vdiff--other-window))
@@ -269,7 +270,8 @@ text on the first line, and the width of the buffer."
,@body)
(setq vdiff--inhibit-window-switch nil)))))
-(defmacro vdiff--with-both-buffers (&rest body)
+(defmacro vdiff--with-all-buffers (&rest body)
+ "Execute BODY in all vdiff buffers."
`(dolist (buf vdiff--buffers)
(when (buffer-live-p buf)
(with-current-buffer buf
@@ -313,10 +315,13 @@ text on the first line, and the width of the buffer."
(cons beg (or end beg))))))
(defun vdiff--diff-refresh-1 (_proc event)
+ "This is the sentinel for `vdiff-refresh'. It does the job of
+parsing the diff output and triggering the overlay updates."
(cond ((string= "finished\n" event)
;; means no difference between files
(setq vdiff--diff-data nil)
- (vdiff--refresh-overlays))
+ (vdiff--refresh-overlays)
+ (vdiff--refresh-line-maps))
((string= "exited abnormally with code 1\n" event)
(setq vdiff--diff-data nil)
(let (res)
@@ -330,20 +335,23 @@ text on the first line, and the width of the buffer."
code nil (match-string 4) (match-string 5))))
(push (list code a-range b-range) res))))
(setq vdiff--diff-data (nreverse res)))
- (vdiff--refresh-overlays))
+ (vdiff--refresh-overlays)
+ (vdiff--refresh-line-maps))
((string-match-p "exited abnormally with code" event)
(setq vdiff--diff-data nil)
(vdiff--refresh-overlays)
+ (vdiff--refresh-line-maps)
(message "vdiff process error: %s" event))))
(defun vdiff--remove-all-overlays ()
- (vdiff--with-both-buffers
+ "Remove all vdiff overlays in both vdiff buffers."
+ (vdiff--with-all-buffers
(remove-overlays (point-min) (point-max) 'vdiff t)))
(defun vdiff-save-buffers ()
"Save all vdiff buffers."
(interactive)
- (vdiff--with-both-buffers (save-buffer)))
+ (vdiff--with-all-buffers (save-buffer)))
;; * Add overlays
@@ -485,8 +493,8 @@ text on the first line, and the width of the buffer."
(vdiff--add-change-overlay this-len))))
(defun vdiff--refresh-overlays ()
+ "Delete and recreate overlays in both buffers."
(vdiff--remove-all-overlays)
- (vdiff--refresh-line-maps)
(save-excursion
(let ((a-buffer (car vdiff--buffers))
(b-buffer (cadr vdiff--buffers))
@@ -547,6 +555,10 @@ text on the first line, and the width of the buffer."
;; * Moving changes
(defun vdiff--region-or-close-overlay ()
+ "Return region bounds if active. Otherwise check if there is an
+overlay at point and return it if there is. If this fails check a
+line above. Always search to the end of the current line as
+well. This only returns bounds for `interactive'."
(if (region-active-p)
(prog1
(list (region-beginning) (region-end))
@@ -592,6 +604,7 @@ changes under point or on the immediately preceding line."
(vdiff-send-changes beg end t))
(defun vdiff--transmit-change-overlay (ovr)
+ "Send text in OVR to corresponding overlay in other buffer."
(if (not (overlayp ovr))
(message "No change found")
(let* ((addition (eq 'addition (overlay-get ovr 'vdiff-type)))
@@ -609,6 +622,8 @@ changes under point or on the immediately preceding line."
(delete-overlay ovr))))
(defun vdiff--transmit-subtraction-overlay (ovr)
+ "Same idea as `vdiff--transmit-change-overlay' except we are
+just deleting text in the other buffer."
(if (not (overlayp ovr))
(message "No change found")
(let* ((other-ovr (overlay-get ovr 'vdiff-other-overlay)))
@@ -620,6 +635,8 @@ changes under point or on the immediately preceding line."
;; * Scrolling and line syncing
(defun vdiff--refresh-line-maps ()
+ "Sync information in `vdiff--line-map' with
+`vdiff--diff-data'."
(let (new-map)
(dolist (entry vdiff--diff-data)
(let* ((code (car entry))
@@ -652,6 +669,8 @@ changes under point or on the immediately preceding line."
(setq vdiff--line-map (cons (list 0 0) (nreverse new-map)))))
(defun vdiff--translate-line (line &optional B-to-A)
+ "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* ((last-entry
(catch 'closest
@@ -714,6 +733,8 @@ buffer and center both buffers at this line."
(recenter)))
(defun vdiff--pos-at-line-beginning (line &optional buffer)
+ "Return position at beginning of LINE in BUFFER (or current
+buffer)."
(with-current-buffer (or buffer (current-buffer))
(save-excursion
(vdiff--move-to-line line)
@@ -800,6 +821,7 @@ buffer and center both buffers at this line."
(define-fringe-bitmap 'vdiff--top-left-angle vdiff--top-left-angle-bits)
(defun vdiff--set-open-fold-props (ovr)
+ "Set overlay properties to open fold OVR."
(overlay-put ovr 'vdiff-fold-open t)
(overlay-put ovr 'display nil)
(overlay-put ovr 'before-string
@@ -813,6 +835,7 @@ buffer and center both buffers at this line."
" " 'display '(left-fringe vdiff--bottom-left-angle))))
(defun vdiff--set-closed-fold-props (ovr)
+ "Set overlay properties to close fold OVR."
(overlay-put ovr 'vdiff-fold-open nil)
(overlay-put ovr 'before-string nil)
(overlay-put ovr 'line-prefix nil)
@@ -859,6 +882,8 @@ folds in the region."
;; * Movement
(defun vdiff--nth-change (&optional n find-folds)
+ "Return point at Nth change overlay in buffer. Use folds
+instead of changes with non-nil FIND-FOLDS."
(let* ((n (or n 1))
(reverse (< n 0))
pnt)
@@ -960,11 +985,12 @@ asked to select two buffers."
(split-window-horizontally))
(switch-to-buffer-other-window buffer-b)
(setq vdiff--buffers (list buffer-a buffer-b))
- (vdiff--with-both-buffers
+ (vdiff--with-all-buffers
(vdiff-mode 1))
(vdiff-refresh)))
(defun vdiff-exit ()
+ "Exit `vdiff-mode' and clean up."
(interactive)
(dolist (buf vdiff--buffers)
(with-current-buffer buf
@@ -1037,12 +1063,12 @@ enabled automatically if `vdiff-lock-scrolling' is
non-nil."
(cond (vdiff-scroll-lock-mode
(unless vdiff-mode
(vdiff-mode 1))
- (vdiff--with-both-buffers
+ (vdiff--with-all-buffers
(add-hook 'window-scroll-functions #'vdiff--scroll-function nil t)
(add-hook 'post-command-hook #'vdiff--post-command-hook nil t))
(message "Scrolling locked"))
(t
- (vdiff--with-both-buffers
+ (vdiff--with-all-buffers
(remove-hook 'window-scroll-functions #'vdiff--scroll-function t)
(remove-hook 'post-command-hook #'vdiff--post-command-hook t))
(message "Scrolling unlocked"))))
- [elpa] scratch/add-vdiff d25fe21 054/258: More arg name changes, (continued)
- [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
- [elpa] scratch/add-vdiff cce8eb1 086/258: Don't close fold on point after change, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8a88f84 074/258: Use simpler strategy for updating windows on line move, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c5589a1 089/258: Delete temp files on deactivation, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4dc6c89 077/258: Add next/prev fold commands and update hydra, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4ea6afb 082/258: Add docstrings and rearrange some calls,
Justin Burkett <=
- [elpa] scratch/add-vdiff 52c675a 096/258: Add hydra screenshot, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1276208 103/258: Recenter after next/prev hunk, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 4ee7fca 104/258: Set intangible property for closed folds, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 16eb802 107/258: Update README, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 0dc9fde 114/258: Try not to move point on change transmission, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff cc24574 115/258: Fix scroll update for other subtraction styles, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c912ebc 120/258: Don't use window-size-change-hook, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7561f87 100/258: Split line maps, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 32756c3 131/258: A little better than a WIP now, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 5a6623f 012/258: Update README, Justin Burkett, 2017/05/17