From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: charles@aurox.ch (Charles A. Roelli) Newsgroups: gmane.emacs.bugs Subject: bug#21262: 25.0.50; Diff-mode gets confused about its narrowing if hunk source not found Date: Tue, 22 Aug 2017 16:02:17 +0200 Message-ID: References: <87lhdd5e52.fsf@secretsauce.net> <87o9r8bgkg.fsf@users.sourceforge.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503414246 3792 195.159.176.226 (22 Aug 2017 15:04:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 22 Aug 2017 15:04:06 +0000 (UTC) Cc: 21262@debbugs.gnu.org, dima@secretsauce.net To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 22 17:03:54 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkAiY-000051-Cr for geb-bug-gnu-emacs@m.gmane.org; Tue, 22 Aug 2017 17:03:46 +0200 Original-Received: from localhost ([::1]:51382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkAid-0000mK-FG for geb-bug-gnu-emacs@m.gmane.org; Tue, 22 Aug 2017 11:03:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk9ls-00007n-JI for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2017 10:03:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk9lm-00085f-Il for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2017 10:03:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40967) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dk9lm-00084j-Cp for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2017 10:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dk9lm-0006dN-0J for bug-gnu-emacs@gnu.org; Tue, 22 Aug 2017 10:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: charles@aurox.ch (Charles A. Roelli) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Aug 2017 14:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21262 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 21262-submit@debbugs.gnu.org id=B21262.150341056425475 (code B ref 21262); Tue, 22 Aug 2017 14:03:01 +0000 Original-Received: (at 21262) by debbugs.gnu.org; 22 Aug 2017 14:02:44 +0000 Original-Received: from localhost ([127.0.0.1]:49648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dk9lU-0006cp-A5 for submit@debbugs.gnu.org; Tue, 22 Aug 2017 10:02:44 -0400 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:39825) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dk9lS-0006ca-67 for 21262@debbugs.gnu.org; Tue, 22 Aug 2017 10:02:43 -0400 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id AFAFE2250B for <21262@debbugs.gnu.org>; Tue, 22 Aug 2017 13:56:44 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= content-type:content-type:mime-version:references:subject :subject:in-reply-to:to:from:from:message-id:date:date; s=dkim; t=1503410202; x=1504274203; bh=0lMtStlkuvsCISArvttxQxd4gXpN4/b4 fKuHWajuh6s=; b=FdJdkr1V1YTpNlPk6vEL+cC+iRX6qn9huiRG1VYHB/mWfOvm hpTvslsnUN9fuMu5s8ZdDH9EQSx05kwX1193W9xEcifSlErfy79U3JcvVFjn9whF oN3S1jNSiSz7U+ToObkLwCm1J6By/r27Hb2BStFP9I7VnC+2AB6hE3arJS4= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id i0pYIkmmcQdv for <21262@debbugs.gnu.org>; Tue, 22 Aug 2017 13:56:42 +0000 (UTC) Original-Received: from gray (125.85.192.178.dynamic.wline.res.cust.swisscom.ch [178.192.85.125]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id B692A224F8; Tue, 22 Aug 2017 13:56:40 +0000 (UTC) In-reply-to: <87o9r8bgkg.fsf@users.sourceforge.net> (npostavs@users.sourceforge.net) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:136040 Archived-At: --=-=-= Content-Type: text/plain > From: npostavs@users.sourceforge.net > Cc: Dima Kogan , 21262@debbugs.gnu.org > Date: Mon, 21 Aug 2017 20:18:39 -0400 > > Looks like a reasonable fix to me (though I know only a little bit of > diff-mode). Here it is again ignoring whitespace, which I think makes > it easier to see what is happening: > > modified lisp/vc/diff-mode.el > @@ -874,6 +874,8 @@ diff-find-file-name > ;; Flush diff-remembered-files-alist if the default-directory is changed. > (set (make-local-variable 'diff-remembered-defdir) default-directory) > (set (make-local-variable 'diff-remembered-files-alist) nil)) > + (save-restriction > + (widen) > (save-excursion > (unless (looking-at diff-file-header-re) > (or (ignore-errors (diff-beginning-of-file)) > @@ -919,7 +921,7 @@ diff-find-file-name > (file-name-nondirectory file))) > (set (make-local-variable 'diff-remembered-files-alist) > (cons (cons fs file) diff-remembered-files-alist)) > - file)))))) > + file))))))) > > Perhaps we should swap the save-restriction and save-excursion around > though? The elisp manual says: > > If you use both `save-restriction' and `save-excursion' together, > `save-excursion' should come first (on the outside). Otherwise, > the old point value would be restored with temporary narrowing > still in effect. Good point, thank you. I'll apply the attached patch in a few days if there's no further discussion. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-diff-goto-source-when-buffer-is-narrowed-Bug-212.patch >From aac6f9eb7aba0cc6b67b56a748e8ee25f755e8f5 Mon Sep 17 00:00:00 2001 From: "Charles A. Roelli" Date: Tue, 22 Aug 2017 15:57:01 +0200 Subject: [PATCH] Fix 'diff-goto-source' when buffer is narrowed (Bug#21262) * lisp/vc/diff-mode.el (diff-find-file-name): Save the current narrowing, and widen the buffer before searching for the name of the file corresponding to the diff. With thanks to Noam Postavsky. --- lisp/vc/diff-mode.el | 92 +++++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index aa8d778..1d4af54 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -875,51 +875,53 @@ diff-find-file-name (set (make-local-variable 'diff-remembered-defdir) default-directory) (set (make-local-variable 'diff-remembered-files-alist) nil)) (save-excursion - (unless (looking-at diff-file-header-re) - (or (ignore-errors (diff-beginning-of-file)) - (re-search-forward diff-file-header-re nil t))) - (let ((fs (diff-hunk-file-names old))) - (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs))) - (or - ;; use any previously used preference - (cdr (assoc fs diff-remembered-files-alist)) - ;; try to be clever and use previous choices as an inspiration - (cl-dolist (rf diff-remembered-files-alist) - (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf)))) - (if (and newfile (file-exists-p newfile)) (cl-return newfile)))) - ;; look for each file in turn. If none found, try again but - ;; ignoring the first level of directory, ... - (cl-do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files))) - (file nil nil)) - ((or (null files) - (setq file (cl-do* ((files files (cdr files)) - (file (car files) (car files))) - ;; Use file-regular-p to avoid - ;; /dev/null, directories, etc. - ((or (null file) (file-regular-p file)) - file)))) - file)) - ;; .rej patches implicitly apply to - (and (string-match "\\.rej\\'" (or buffer-file-name "")) - (let ((file (substring buffer-file-name 0 (match-beginning 0)))) - (when (file-exists-p file) file))) - ;; If we haven't found the file, maybe it's because we haven't paid - ;; attention to the PCL-CVS hint. - (and (not prefix) - (boundp 'cvs-pcl-cvs-dirchange-re) - (save-excursion - (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) - (diff-find-file-name old noprompt (match-string 1))) - ;; if all else fails, ask the user - (unless noprompt - (let ((file (expand-file-name (or (car fs) "")))) - (setq file - (read-file-name (format "Use file %s: " file) - (file-name-directory file) file t - (file-name-nondirectory file))) - (set (make-local-variable 'diff-remembered-files-alist) - (cons (cons fs file) diff-remembered-files-alist)) - file)))))) + (save-restriction + (widen) + (unless (looking-at diff-file-header-re) + (or (ignore-errors (diff-beginning-of-file)) + (re-search-forward diff-file-header-re nil t))) + (let ((fs (diff-hunk-file-names old))) + (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs))) + (or + ;; use any previously used preference + (cdr (assoc fs diff-remembered-files-alist)) + ;; try to be clever and use previous choices as an inspiration + (cl-dolist (rf diff-remembered-files-alist) + (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf)))) + (if (and newfile (file-exists-p newfile)) (cl-return newfile)))) + ;; look for each file in turn. If none found, try again but + ;; ignoring the first level of directory, ... + (cl-do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files))) + (file nil nil)) + ((or (null files) + (setq file (cl-do* ((files files (cdr files)) + (file (car files) (car files))) + ;; Use file-regular-p to avoid + ;; /dev/null, directories, etc. + ((or (null file) (file-regular-p file)) + file)))) + file)) + ;; .rej patches implicitly apply to + (and (string-match "\\.rej\\'" (or buffer-file-name "")) + (let ((file (substring buffer-file-name 0 (match-beginning 0)))) + (when (file-exists-p file) file))) + ;; If we haven't found the file, maybe it's because we haven't paid + ;; attention to the PCL-CVS hint. + (and (not prefix) + (boundp 'cvs-pcl-cvs-dirchange-re) + (save-excursion + (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) + (diff-find-file-name old noprompt (match-string 1))) + ;; if all else fails, ask the user + (unless noprompt + (let ((file (expand-file-name (or (car fs) "")))) + (setq file + (read-file-name (format "Use file %s: " file) + (file-name-directory file) file t + (file-name-nondirectory file))) + (set (make-local-variable 'diff-remembered-files-alist) + (cons (cons fs file) diff-remembered-files-alist)) + file))))))) (defun diff-ediff-patch () -- 2.9.4 --=-=-=--