# HG changeset patch # User Stefan Monnier # Date 1157998279 0 # Node ID 200db4ae9b541eed743f946b736965184c59e0b0 # Parent bc928adbd68a9770e9998bf217a6c84f284da4bf (diff-apply-hunk-to-backup-file): New var. (diff-apply-hunk): Use it to ask for confirmation. diff -r bc928adbd68a -r 200db4ae9b54 lisp/ChangeLog --- a/lisp/ChangeLog Mon Sep 11 17:16:07 2006 +0000 +++ b/lisp/ChangeLog Mon Sep 11 18:11:19 2006 +0000 @@ -1,3 +1,8 @@ +2006-09-11 Stefan Monnier + + * diff-mode.el (diff-apply-hunk-to-backup-file): New var. + (diff-apply-hunk): Use it to ask for confirmation. + 2006-09-11 Reiner Steib * emacs-lisp/cl.el (pushnew): Add missing `,'. diff -r bc928adbd68a -r 200db4ae9b54 lisp/diff-mode.el --- a/lisp/diff-mode.el Mon Sep 11 17:16:07 2006 +0000 +++ b/lisp/diff-mode.el Mon Sep 11 18:11:19 2006 +0000 @@ -1259,6 +1259,7 @@ (t "Hunk %s at offset %d lines")) msg line-offset))) +(defvar diff-apply-hunk-to-backup-file nil) (defun diff-apply-hunk (&optional reverse) "Apply the current hunk to the source file and go to the next. @@ -1275,6 +1276,17 @@ (cond ((null line-offset) (error "Can't find the text to patch")) + ((with-current-buffer buf + (and buffer-file-name + (backup-file-name-p buffer-file-name) + (not diff-apply-hunk-to-backup-file) + (not (set (make-local-variable 'diff-apply-hunk-to-backup-file) + (yes-or-no-p (format "Really apply this hunk to %s? " + (file-name-nondirectory + buffer-file-name))))))) + (error (substitute-command-keys + (format "Use %s\\[diff-apply-hunk] to apply it to the other file" + (if (not reverse) "\\[universal-argument] "))))) ((and switched ;; A reversed patch was detected, perhaps apply it in reverse. (not (save-window-excursion