(let ((inhibit-read-only t)
(target (current-buffer)))
(erase-buffer)
- (pcase-dolist (`(,file . ,reps) edits)
- (when (and reps file (file-readable-p file))
+ (pcase-dolist (`(,buf . ,reps) edits)
+ (when (and reps buf)
(with-temp-buffer
(let ((diff (current-buffer))
(tokens nil))
(with-temp-buffer
- (insert-file-contents file)
+ (insert-buffer-substring buf)
(let ((refactor-replacement-functions
(list (lambda (token) (push token tokens)))))
(refactor--apply-replacements reps))
- (diff-no-select file (current-buffer) nil t diff))
+ (diff-no-select buf (current-buffer) nil t diff))
(with-current-buffer target
(let ((start (point)))
(insert-buffer-substring diff)
(put-text-property start (point)
- 'refactor-replacement-tokens tokens))))))))
+ 'refactor-replacement-tokens tokens)
+ (put-text-property start (point) 'diff-new buf))))))))
(add-hook 'diff-apply-hunk-functions
#'refactor-run-replacement-functions-from-diff nil t)
(buffer-enable-undo (current-buffer))
(while edits
(let ((buffer-reps (car edits)))
(refactor--query-apply-buffer-reps
- (car buffer-reps) (cdr buffer-reps))
+ (car buffer-reps)
+ (sort (cdr buffer-reps) :key #'cadr))
(setq edits (cdr edits)))))
(`(all . ,reps)
(setcdr (car edits) reps)
diff-context-mid-hunk-header-re nil t)
(error "Can't find the hunk separator"))
(match-string 1)))))
- (file (or (diff-find-file-name other noprompt)
- (error "Can't find the file")))
- (revision (and other diff-vc-backend
- (if reverse (nth 1 diff-vc-revisions)
- (or (nth 0 diff-vc-revisions)
- ;; When diff shows changes in working revision
- (vc-working-revision file)))))
- (buf (if revision
- (let ((vc-find-revision-no-save t))
- (vc-find-revision (expand-file-name file) revision diff-vc-backend))
- ;; NOPROMPT is only non-nil when called from
- ;; `which-function-mode', so avoid "File x changed
- ;; on disk. Reread from disk?" warnings.
- (find-file-noselect file noprompt))))
+ (buf (or (get-text-property (point) (if other 'diff-old 'diff-new))
+ (let* ((file (or (diff-find-file-name other noprompt)
+ (error "Can't find the file")))
+ (revision (and other diff-vc-backend
+ (if reverse (nth 1 diff-vc-revisions)
+ (or (nth 0 diff-vc-revisions)
+ ;; When diff shows changes in working revision
+ (vc-working-revision file))))))
+ (if revision
+ (let ((vc-find-revision-no-save t))
+ (vc-find-revision (expand-file-name file) revision diff-vc-backend))
+ ;; NOPROMPT is only non-nil when called from
+ ;; `which-function-mode', so avoid "File x changed
+ ;; on disk. Reread from disk?" warnings.
+ (find-file-noselect file noprompt))))))
;; Update the user preference if he so wished.
(when (> (prefix-numeric-value other-file) 8)
(setq diff-jump-to-old-file other))