[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/add-vdiff 83f0788 118/258: Don't make temp files global
From: |
Justin Burkett |
Subject: |
[elpa] scratch/add-vdiff 83f0788 118/258: Don't make temp files global |
Date: |
Wed, 17 May 2017 08:13:35 -0400 (EDT) |
branch: scratch/add-vdiff
commit 83f0788c6755b3234b87cafa15766eda2e62ea79
Author: justbur <address@hidden>
Commit: justbur <address@hidden>
Don't make temp files global
---
vdiff.el | 133 +++++++++++++++++++++++++++++++--------------------------------
1 file changed, 65 insertions(+), 68 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index 80d3369..982b1f6 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -164,8 +164,6 @@ be a need to include commands that scroll the buffer here,
because those are handled differently.")
(defvar vdiff--buffers nil)
-(defvar vdiff--temp-files nil)
-(defvar vdiff--word-diff-temp-files nil)
(defvar vdiff--process-buffer " *vdiff* ")
(defvar vdiff--word-diff-output-buffer " *vdiff-word* ")
(defvar vdiff--diff-data nil)
@@ -282,19 +280,20 @@ because those are handled differently.")
(defun vdiff-refresh ()
"Asynchronously refresh diff information."
(interactive)
- (let* ((cmd (mapconcat #'identity
+ (let* ((tmp-a (make-temp-file "vdiff-a-"))
+ (tmp-b (make-temp-file "vdiff-b-"))
+ (cmd (mapconcat #'identity
(list
vdiff-diff-program
vdiff-diff-program-args
- (car vdiff--temp-files)
- (cadr vdiff--temp-files))
+ tmp-a tmp-b)
" "))
(proc (get-buffer-process
vdiff--process-buffer)))
(with-current-buffer (car vdiff--buffers)
- (write-region nil nil (car vdiff--temp-files) nil 'quietly))
+ (write-region nil nil tmp-a nil 'quietly))
(with-current-buffer (cadr vdiff--buffers)
- (write-region nil nil (cadr vdiff--temp-files) nil 'quietly))
+ (write-region nil nil tmp-b nil 'quietly))
(when proc
(kill-process proc))
(with-current-buffer (get-buffer-create vdiff--process-buffer)
@@ -303,6 +302,8 @@ because those are handled differently.")
vdiff--process-buffer
vdiff--process-buffer
cmd))
+ (process-put proc 'vdiff-tmp-a tmp-a)
+ (process-put proc 'vdiff-tmp-b tmp-b)
(set-process-sentinel proc #'vdiff--diff-refresh-1)))
(defun vdiff--normalize-range (code buf-a beg end)
@@ -320,29 +321,34 @@ because those are handled differently.")
"This is the sentinel for `vdiff-refresh'. It does the job of
parsing the diff output and triggering the overlay updates."
(unless vdiff--inhibit-diff-data-update
- (setq vdiff--diff-data nil)
- (cond ((string= "finished\n" event)
- ;; means no difference between files
- (vdiff--refresh-overlays)
- (vdiff--refresh-line-maps))
- ((string= "exited abnormally with code 1\n" event)
- (let (res)
- (with-current-buffer (process-buffer proc)
- (goto-char (point-min))
- (while (re-search-forward vdiff--diff-code-regexp nil t)
- (let* ((code (match-string 3))
- (a-range (vdiff--normalize-range
- code t (match-string 1) (match-string 2)))
- (b-range (vdiff--normalize-range
- 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-line-maps))
- ((string-match-p "exited abnormally with code" event)
- (vdiff--refresh-overlays)
- (vdiff--refresh-line-maps)
- (message "vdiff process error: %s" event)))
+ (let (finished)
+ (cond ((string= "finished\n" event)
+ ;; means no difference between files
+ (setq vdiff--diff-data nil)
+ (setq finished t))
+ ((string= "exited abnormally with code 1\n" event)
+ (setq vdiff--diff-data nil)
+ (setq finished t)
+ (let (res)
+ (with-current-buffer (process-buffer proc)
+ (goto-char (point-min))
+ (while (re-search-forward vdiff--diff-code-regexp nil t)
+ (let* ((code (match-string 3))
+ (a-range (vdiff--normalize-range
+ code t (match-string 1) (match-string 2)))
+ (b-range (vdiff--normalize-range
+ code nil (match-string 4) (match-string
5))))
+ (push (list code a-range b-range) res))))
+ (setq vdiff--diff-data (nreverse res))))
+ ((string-match-p "exited abnormally with code" event)
+ (setq vdiff--diff-data nil)
+ (setq finished t)
+ (message "vdiff process error: %s" event)))
+ (when finished
+ (vdiff--refresh-overlays)
+ (vdiff--refresh-line-maps)
+ (delete-file (process-get proc 'vdiff-tmp-a))
+ (delete-file (process-get proc 'vdiff-tmp-b))))
(setq vdiff--diff-stale nil)))
(defun vdiff--remove-all-overlays ()
@@ -389,8 +395,8 @@ parsing the diff output and triggering the overlay updates."
(overlayp other-ovr))
(let* ((a-words (vdiff--overlay-to-words this-ovr syntax-code))
(b-words (vdiff--overlay-to-words other-ovr syntax-code))
- (tmp-file-a (car vdiff--word-diff-temp-files))
- (tmp-file-b (cadr vdiff--word-diff-temp-files))
+ (tmp-file-a (make-temp-file "vdiff-word-a-"))
+ (tmp-file-b (make-temp-file "vdiff-word-b-"))
(out-buffer (get-buffer-create
vdiff--word-diff-output-buffer))
(a-result '())
@@ -398,30 +404,33 @@ parsing the diff output and triggering the overlay
updates."
(write-region a-words nil tmp-file-a nil 'quietly)
(write-region b-words nil tmp-file-b nil 'quietly)
(with-current-buffer out-buffer (erase-buffer))
- (when (= 1 (call-process
- vdiff-diff-program nil out-buffer nil tmp-file-a tmp-file-b))
- (with-current-buffer out-buffer
- (goto-char (point-min))
- (while (re-search-forward vdiff--diff-code-regexp nil t)
- (let ((a-change (list (string-to-number (match-string 1))))
- (b-change (list (string-to-number (match-string 4)))))
- (forward-line 1)
- (while (and (not (eobp))
- (not (looking-at-p vdiff--diff-code-regexp)))
- (cond ((looking-at-p "^<")
- (push (buffer-substring-no-properties
- (+ 2 (point)) (line-end-position))
- a-change))
- ((looking-at-p "^>")
- (push (buffer-substring-no-properties
- (+ 2 (point)) (line-end-position))
- b-change)))
- (forward-line 1))
- (when (cdr a-change)
- (push (nreverse a-change) a-result))
- (when (cdr b-change)
- (push (nreverse b-change) b-result))))
- (cons (nreverse a-result) (nreverse b-result)))))))
+ (let ((exit-code (call-process
+ vdiff-diff-program nil out-buffer nil tmp-file-a
tmp-file-b)))
+ (delete-file tmp-file-a)
+ (delete-file tmp-file-b)
+ (when (= exit-code 1)
+ (with-current-buffer out-buffer
+ (goto-char (point-min))
+ (while (re-search-forward vdiff--diff-code-regexp nil t)
+ (let ((a-change (list (string-to-number (match-string 1))))
+ (b-change (list (string-to-number (match-string 4)))))
+ (forward-line 1)
+ (while (and (not (eobp))
+ (not (looking-at-p vdiff--diff-code-regexp)))
+ (cond ((looking-at-p "^<")
+ (push (buffer-substring-no-properties
+ (+ 2 (point)) (line-end-position))
+ a-change))
+ ((looking-at-p "^>")
+ (push (buffer-substring-no-properties
+ (+ 2 (point)) (line-end-position))
+ b-change)))
+ (forward-line 1))
+ (when (cdr a-change)
+ (push (nreverse a-change) a-result))
+ (when (cdr b-change)
+ (push (nreverse b-change) b-result))))
+ (cons (nreverse a-result) (nreverse b-result))))))))
(defun vdiff-refine-this-hunk (&optional syntax-code ovr)
"Highlight word differences in current hunk.
@@ -1300,12 +1309,6 @@ changes. This will be enabled automatically after calling
commands like `vdiff-files' or `vdiff-buffers'."
nil " vdiff" 'vdiff-mode-map
(cond (vdiff-mode
- (setq vdiff--temp-files
- (list (make-temp-file "vdiff--temp-a-")
- (make-temp-file "vdiff--temp-b-")))
- (setq vdiff--word-diff-temp-files
- (list (make-temp-file "vdiff--overlay-diff-temp-a-")
- (make-temp-file "vdiff--overlay-diff-temp-b-")))
(setq cursor-in-non-selected-windows nil)
(add-hook 'after-save-hook #'vdiff-refresh nil t)
(add-hook 'window-size-change-functions
@@ -1331,12 +1334,6 @@ commands like `vdiff-files' or `vdiff-buffers'."
(setq vdiff--a-b-line-map nil)
(setq vdiff--b-a-line-map nil)
(setq vdiff--window-configuration nil)
- (dolist (file vdiff--temp-files)
- (delete-file file))
- (setq vdiff--temp-files nil)
- (dolist (file vdiff--word-diff-temp-files)
- (delete-file file))
- (setq vdiff--word-diff-temp-files nil)
(when (process-live-p vdiff--process-buffer)
(kill-process vdiff--process-buffer))
(when (buffer-live-p vdiff--process-buffer)
- [elpa] scratch/add-vdiff 14abb75 078/258: Allow jumping to subtraction overlays, (continued)
- [elpa] scratch/add-vdiff 14abb75 078/258: Allow jumping to subtraction overlays, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff a15b0e5 084/258: Move point before closing fold, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 425d50b 085/258: Add vdiff-close-other-folds, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 6516112 075/258: Minor formatting, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 968047f 093/258: Change wording in a docstring, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff ad0e8c3 091/258: Make mirrored-commands private and rename, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 309e912 108/258: Refresh automatically on idle after change, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 5b1b342 119/258: Remove duplicated code in vdiff-files, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 750a1bc 124/258: Fix bug in remove-refinements, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c8cba47 125/258: Fix package, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 83f0788 118/258: Don't make temp files global,
Justin Burkett <=
- [elpa] scratch/add-vdiff 72fe0fa 130/258: Don't update diff info while sending changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff c6e30a2 136/258: Merge pull request #9 from gvol/master, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 53c2a6b 153/258: Fix receiving changes, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 5dcdc97 158/258: Remove other-window, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 7029054 159/258: Comment out vdiff-buffers3, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 97d7098 174/258: Add screenshot of three way diff, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 8b79246 171/258: Make sure we're in a vdiff buffer on refresh, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 42f56ae 177/258: Don't jump to beginning of buffer on start, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 192dbfe 166/258: Release vdiff-buffers3, Justin Burkett, 2017/05/17
- [elpa] scratch/add-vdiff 1d8f6e7 185/258: Use correct mode for three way diff on quit, Justin Burkett, 2017/05/17