emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error when applying hunk in Diff buffer


From: Stefan Monnier
Subject: Re: Error when applying hunk in Diff buffer
Date: Thu, 03 Aug 2006 12:15:11 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>> > Or maybe diff-mode should be able to cope with a diff like this:
>> > [...]
>> > And DTRT?
>> 
>> Yes, maybe diff-mode could use some heuristic to decide which 
>> of the two file names should be used.  Maybe if one of the 
>> two is a backup files (with the ~ at the end) or if one of 
>> the two is read-only, then the default should be to apply the 
>> hunk to the other...
>> 
>> But to tell you the truth, I think there's already too much 
>> heuristic involved in diff-mode's selection of the file, 
>> place, and direction of the hunk application.  So it's 
>> probably better to get used to telling Emacs what you mean, 
>> rather than let Emacs figure out that you meant something 
>> else than what you said.

> I understand what you're saying from a developer's perspective, but I raised
> this as a user from a user's perspective.  I have (AFAIK) always been able
> to do C-x v = and C-c C-a (or frequently their menu entries) and emacs
> happily DTRT.

> Now I find it does not work, barfing about a buffer I didn't open that is
> visiting a file I didn't create.  See what I mean?

> And there is nothing (even in NEWS---assuming a user would look in it) to
> tell me to set vc-stay-local to nil or do C-u C-c C-a (which does not have a
> menu-only entry) to make it work.

Does the patch below provide an acceptable compromise?


        Stefan


--- diff-mode.el        04 Jul 2006 11:22:59 -0400      1.91
+++ diff-mode.el        03 Aug 2006 12:12:45 -0400      
@@ -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,16 @@
     (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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]