From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pete Lee" Newsgroups: gmane.emacs.devel Subject: Re: diff mode weirdness Date: Sun, 14 Sep 2008 16:13:59 -0500 Message-ID: References: <4my71xt92o.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_184788_24022515.1221426839690" X-Trace: ger.gmane.org 1221426860 16727 80.91.229.12 (14 Sep 2008 21:14:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Sep 2008 21:14:20 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: joakim@verona.se Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 14 23:15:16 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Keyw7-0006BX-2X for ged-emacs-devel@m.gmane.org; Sun, 14 Sep 2008 23:15:16 +0200 Original-Received: from localhost ([127.0.0.1]:45353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Keyv5-0007Ql-Ra for ged-emacs-devel@m.gmane.org; Sun, 14 Sep 2008 17:14:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Keyuz-0007QU-T6 for emacs-devel@gnu.org; Sun, 14 Sep 2008 17:14:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Keyuy-0007Q6-4K for emacs-devel@gnu.org; Sun, 14 Sep 2008 17:14:04 -0400 Original-Received: from [199.232.76.173] (port=38921 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Keyuy-0007Px-1u for emacs-devel@gnu.org; Sun, 14 Sep 2008 17:14:04 -0400 Original-Received: from nf-out-0910.google.com ([64.233.182.186]:46723) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Keyuw-00067w-VT for emacs-devel@gnu.org; Sun, 14 Sep 2008 17:14:04 -0400 Original-Received: by nf-out-0910.google.com with SMTP id c7so1016082nfi.26 for ; Sun, 14 Sep 2008 14:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=uHOJtuG446JPwA0LzXn/sdYMoJEp5Q7z3MD5iKWXamw=; b=lpeorrCIE68V+pHlWtFswWT74ZJR6IUF4p8oTElnCSrNXPiohjaR7T00b43+P4hu/r HodarwiW6/FLMfTSkrm+wZ5zepn4fguuW5/Q5DNQGSiSx3uoOrYtGZh0ILODwkMaPXU1 +7xb2eJannS9ZDnVJfrH2XoeIqL+X8tDVaElk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=E0dqBhtnGr5r3VMIlRToqTvyDalTcyWBdzD/FFpsecmM/qiOSAP7tT4fvXpDNvlPcZ XyS2L0WnyI1mC8BwhfxCLRTdRKi5to//FbwxsHRp5yw13fPCl9uxdakpMHq6YdsUtrEc 4lhCwpcvPS7LTQkmk8ErzYJ8I7fjmfgxlnOXs= Original-Received: by 10.210.12.18 with SMTP id 18mr6254615ebl.83.1221426839632; Sun, 14 Sep 2008 14:13:59 -0700 (PDT) Original-Received: by 10.210.49.16 with HTTP; Sun, 14 Sep 2008 14:13:59 -0700 (PDT) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:103884 Archived-At: ------=_Part_184788_24022515.1221426839690 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Worked for me as well... Thanks. On Sun, Sep 14, 2008 at 4:01 PM, wrote: > Stefan Monnier writes: > > >> copy between the snips and save as /tmp/test.diff > > > >> Then open the file... > > > >> The modeline will continuously prompt for: > >> Use file Version: /tmp/test > > > > Does the patch below fix the problem for you? > > Yes this patch appears to work! > Thanks! > > > > > > > Stefan > > > > > > --- diff-mode.el.~1.150.~ 2008-08-13 17:49:14.000000000 -0400 > > +++ diff-mode.el 2008-09-12 21:52:53.000000000 -0400 > > @@ -723,7 +723,7 @@ > > (fs (diff-hunk-file-names current-prefix-arg))) > > (unless fs (error "No file name to look for")) > > (list old (read-file-name (format "File for %s: " (car fs)) > > - nil (diff-find-file-name old) t)))) > > + nil (diff-find-file-name old 'noprompt) > t)))) > > (let ((fs (diff-hunk-file-names old))) > > (unless fs (error "No file name to look for")) > > (push (cons fs name) diff-remembered-files-alist))) > > @@ -756,11 +756,10 @@ > > (list (if old (match-string 2) (match-string 4)) > > (if old (match-string 4) (match-string 2))))))))) > > > > -(defun diff-find-file-name (&optional old batch prefix) > > +(defun diff-find-file-name (&optional old noprompt prefix) > > "Return the file corresponding to the current patch. > > Non-nil OLD means that we want the old file. > > -Non-nil BATCH means to prefer returning an incorrect answer than to > prompt > > -the user. > > +Non-nil NOPROMPT means to prefer returning nil than to prompt the user. > > PREFIX is only used internally: don't use it." > > (unless (equal diff-remembered-defdir default-directory) > > ;; Flush diff-remembered-files-alist if the default-directory is > changed. > > @@ -801,16 +800,15 @@ > > (boundp 'cvs-pcl-cvs-dirchange-re) > > (save-excursion > > (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) > > - (diff-find-file-name old batch (match-string 1))) > > - ;; Invent something, if necessary. > > - (when batch > > - (or (car fs) default-directory)) > > + (diff-find-file-name old noprompt (match-string 1))) > > ;; if all else fails, ask the user > > - (let ((file (read-file-name (format "Use file %s: " (or (first > fs) "")) > > + (unless noprompt > > + (let ((file (read-file-name (format "Use file %s: " > > + (or (first fs) "")) > > nil (first fs) t (first fs)))) > > (set (make-local-variable 'diff-remembered-files-alist) > > (cons (cons fs file) diff-remembered-files-alist)) > > - file))))) > > + file)))))) > > > > > > (defun diff-ediff-patch () > > @@ -1286,7 +1284,7 @@ > > (set (make-local-variable 'add-log-current-defun-function) > > 'diff-current-defun) > > (set (make-local-variable 'add-log-buffer-file-name-function) > > - 'diff-find-file-name)) > > + (lambda () (diff-find-file-name nil 'noprompt)))) > > > > ;;;###autoload > > (define-minor-mode diff-minor-mode > > @@ -1547,7 +1545,7 @@ > > > > (defsubst diff-xor (a b) (if a (if (not b) a) b)) > > > > -(defun diff-find-source-location (&optional other-file reverse) > > +(defun diff-find-source-location (&optional other-file reverse noprompt) > > "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED). > > BUF is the buffer corresponding to the source file. > > LINE-OFFSET is the offset between the expected and actual positions > > @@ -1555,7 +1553,8 @@ > > POS is a pair (BEG . END) indicating the position of the text in the > buffer. > > SRC and DST are the two variants of text as returned by > `diff-hunk-text'. > > SRC is the variant that was found in the buffer. > > -SWITCHED is non-nil if the patch is already applied." > > +SWITCHED is non-nil if the patch is already applied. > > +NOPROMPT, if non-nil, means not to prompt the user." > > (save-excursion > > (let* ((other (diff-xor other-file diff-jump-to-old-file)) > > (char-offset (- (point) (progn (diff-beginning-of-hunk > 'try-harder) > > @@ -1565,8 +1564,8 @@ > > ;; (e.g. because an empty line truncates the hunk > mid-course), > > ;; leading to potentially nasty surprises for the user. > > (_ (diff-sanity-check-hunk)) > > - (hunk (buffer-substring (point) > > - (save-excursion (diff-end-of-hunk) > (point)))) > > + (hunk (buffer-substring > > + (point) (save-excursion (diff-end-of-hunk) (point)))) > > (old (diff-hunk-text hunk reverse char-offset)) > > (new (diff-hunk-text hunk (not reverse) char-offset)) > > ;; Find the location specification. > > @@ -1578,7 +1577,8 @@ > > 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) (error "Can't find the > file"))) > > + (file (or (diff-find-file-name other noprompt) > > + (error "Can't find the file"))) > > (buf (find-file-noselect file))) > > ;; Update the user preference if he so wished. > > (when (> (prefix-numeric-value other-file) 8) > > @@ -1718,14 +1718,18 @@ > > (when (looking-at diff-hunk-header-re) > > (forward-line 1) > > (re-search-forward "^[^ ]" nil t)) > > - (destructuring-bind (buf line-offset pos src dst &optional switched) > > - (diff-find-source-location) > > + (destructuring-bind (&optional buf line-offset pos src dst switched) > > + ;; Use `noprompt' since this is used in which-func-mode and > such. > > + (ignore-errors ;Signals errors in place of > prompting. > > + (diff-find-source-location nil nil 'noprompt)) > > + (when buf > > (beginning-of-line) > > (or (when (memq (char-after) '(?< ?-)) > > ;; Cursor is pointing at removed text. This could be a removed > > ;; function, in which case, going to the source buffer will > > ;; not help since the function is now removed. Instead, > > - ;; try to figure out the function name just from the > code-fragment. > > + ;; try to figure out the function name just from the > > + ;; code-fragment. > > (let ((old (if switched dst src))) > > (with-temp-buffer > > (insert (car old)) > > @@ -1734,7 +1738,7 @@ > > (add-log-current-defun)))) > > (with-current-buffer buf > > (goto-char (+ (car pos) (cdr src))) > > - (add-log-current-defun)))))) > > + (add-log-current-defun))))))) > > > > (defun diff-ignore-whitespace-hunk () > > "Re-diff the current hunk, ignoring whitespace differences." > > > -- > Joakim Verona > ------=_Part_184788_24022515.1221426839690 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Worked for me as well... Thanks.

On Sun, Sep 14, 2008 at 4:01 PM, <joakim@verona.se> wrote:
Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> copy between the snips and save as /tmp/test.diff
>
>> Then open the file...
>
>> The modeline will continuously prompt for:
>> Use file Version: /tmp/test
>
> Does the patch below fix the problem for you?

Yes this patch appears to work!
Thanks!

>
>
>         Stefan
>
>
> --- diff-mode.el.~1.150.~     2008-08-13 17:49:14.000000000 -0400
> +++ diff-mode.el      2008-09-12 21:52:53.000000000 -0400
> @@ -723,7 +723,7 @@
>         (fs (diff-hunk-file-names current-prefix-arg)))
>       (unless fs (error "No file name to look for"))
>       (list old (read-file-name (format "File for %s: " (car fs))
> -                            nil (diff-find-file-name old) t))))
> +                            nil (diff-find-file-name old 'noprompt) t))))
>    (let ((fs (diff-hunk-file-names old)))
>      (unless fs (error "No file name to look for"))
>      (push (cons fs name) diff-remembered-files-alist)))
> @@ -756,11 +756,10 @@
>              (list (if old (match-string 2) (match-string 4))
>                    (if old (match-string 4) (match-string 2)))))))))
>
> -(defun diff-find-file-name (&optional old batch prefix)
> +(defun diff-find-file-name (&optional old noprompt prefix)
>    "Return the file corresponding to the current patch.
>  Non-nil OLD means that we want the old file.
> -Non-nil BATCH means to prefer returning an incorrect answer than to prompt
> -the user.
> +Non-nil NOPROMPT means to prefer returning nil than to prompt the user.
>  PREFIX is only used internally: don't use it."
>    (unless (equal diff-remembered-defdir default-directory)
>      ;; Flush diff-remembered-files-alist if the default-directory is changed.
> @@ -801,16 +800,15 @@
>           (boundp 'cvs-pcl-cvs-dirchange-re)
>           (save-excursion
>             (re-search-backward cvs-pcl-cvs-dirchange-re nil t))
> -         (diff-find-file-name old batch (match-string 1)))
> -       ;; Invent something, if necessary.
> -       (when batch
> -         (or (car fs) default-directory))
> +         (diff-find-file-name old noprompt (match-string 1)))
>         ;; if all else fails, ask the user
> -       (let ((file (read-file-name (format "Use file %s: " (or (first fs) ""))
> +       (unless noprompt
> +         (let ((file (read-file-name (format "Use file %s: "
> +                                             (or (first fs) ""))
>                                  nil (first fs) t (first fs))))
>        (set (make-local-variable 'diff-remembered-files-alist)
>             (cons (cons fs file) diff-remembered-files-alist))
> -      file)))))
> +           file))))))
>
>
>  (defun diff-ediff-patch ()
> @@ -1286,7 +1284,7 @@
>    (set (make-local-variable 'add-log-current-defun-function)
>         'diff-current-defun)
>    (set (make-local-variable 'add-log-buffer-file-name-function)
> -       'diff-find-file-name))
> +       (lambda () (diff-find-file-name nil 'noprompt))))
>
>  ;;;###autoload
>  (define-minor-mode diff-minor-mode
> @@ -1547,7 +1545,7 @@
>
>  (defsubst diff-xor (a b) (if a (if (not b) a) b))
>
> -(defun diff-find-source-location (&optional other-file reverse)
> +(defun diff-find-source-location (&optional other-file reverse noprompt)
>    "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED).
>  BUF is the buffer corresponding to the source file.
>  LINE-OFFSET is the offset between the expected and actual positions
> @@ -1555,7 +1553,8 @@
>  POS is a pair (BEG . END) indicating the position of the text in the buffer.
>  SRC and DST are the two variants of text as returned by `diff-hunk-text'.
>    SRC is the variant that was found in the buffer.
> -SWITCHED is non-nil if the patch is already applied."
> +SWITCHED is non-nil if the patch is already applied.
> +NOPROMPT, if non-nil, means not to prompt the user."
>    (save-excursion
>      (let* ((other (diff-xor other-file diff-jump-to-old-file))
>          (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder)
> @@ -1565,8 +1564,8 @@
>             ;; (e.g. because an empty line truncates the hunk mid-course),
>             ;; leading to potentially nasty surprises for the user.
>             (_ (diff-sanity-check-hunk))
> -        (hunk (buffer-substring (point)
> -                                (save-excursion (diff-end-of-hunk) (point))))
> +        (hunk (buffer-substring
> +                  (point) (save-excursion (diff-end-of-hunk) (point))))
>          (old (diff-hunk-text hunk reverse char-offset))
>          (new (diff-hunk-text hunk (not reverse) char-offset))
>          ;; Find the location specification.
> @@ -1578,7 +1577,8 @@
>                                  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) (error "Can't find the file")))
> +        (file (or (diff-find-file-name other noprompt)
> +                     (error "Can't find the file")))
>          (buf (find-file-noselect file)))
>        ;; Update the user preference if he so wished.
>        (when (> (prefix-numeric-value other-file) 8)
> @@ -1718,14 +1718,18 @@
>      (when (looking-at diff-hunk-header-re)
>        (forward-line 1)
>        (re-search-forward "^[^ ]" nil t))
> -    (destructuring-bind (buf line-offset pos src dst &optional switched)
> -     (diff-find-source-location)
> +    (destructuring-bind (&optional buf line-offset pos src dst switched)
> +        ;; Use `noprompt' since this is used in which-func-mode and such.
> +     (ignore-errors                ;Signals errors in place of prompting.
> +          (diff-find-source-location nil nil 'noprompt))
> +      (when buf
>        (beginning-of-line)
>        (or (when (memq (char-after) '(?< ?-))
>           ;; Cursor is pointing at removed text.  This could be a removed
>           ;; function, in which case, going to the source buffer will
>           ;; not help since the function is now removed.  Instead,
> -         ;; try to figure out the function name just from the code-fragment.
> +              ;; try to figure out the function name just from the
> +              ;; code-fragment.
>           (let ((old (if switched dst src)))
>             (with-temp-buffer
>               (insert (car old))
> @@ -1734,7 +1738,7 @@
>               (add-log-current-defun))))
>         (with-current-buffer buf
>           (goto-char (+ (car pos) (cdr src)))
> -         (add-log-current-defun))))))
> +              (add-log-current-defun)))))))
>
>  (defun diff-ignore-whitespace-hunk ()
>    "Re-diff the current hunk, ignoring whitespace differences."
>
--
Joakim Verona

------=_Part_184788_24022515.1221426839690--