aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles A. Roelli2017-08-22 15:57:01 +0200
committerCharles A. Roelli2017-08-27 14:14:46 +0200
commit208a3cb05f4d954abc9dd6c8cd858ef2bedd7cb4 (patch)
tree52d2ef0ae997c8b89ec4bcc918c2d9989cc9c8c5
parentd309ce429912a39c4f19877f23cf36116b679818 (diff)
downloademacs-208a3cb05f4d954abc9dd6c8cd858ef2bedd7cb4.tar.gz
emacs-208a3cb05f4d954abc9dd6c8cd858ef2bedd7cb4.zip
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.
-rw-r--r--lisp/vc/diff-mode.el92
1 files changed, 47 insertions, 45 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index aa8d77882ec..1d4af54db93 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -875,51 +875,53 @@ PREFIX is only used internally: don't use it."
875 (set (make-local-variable 'diff-remembered-defdir) default-directory) 875 (set (make-local-variable 'diff-remembered-defdir) default-directory)
876 (set (make-local-variable 'diff-remembered-files-alist) nil)) 876 (set (make-local-variable 'diff-remembered-files-alist) nil))
877 (save-excursion 877 (save-excursion
878 (unless (looking-at diff-file-header-re) 878 (save-restriction
879 (or (ignore-errors (diff-beginning-of-file)) 879 (widen)
880 (re-search-forward diff-file-header-re nil t))) 880 (unless (looking-at diff-file-header-re)
881 (let ((fs (diff-hunk-file-names old))) 881 (or (ignore-errors (diff-beginning-of-file))
882 (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs))) 882 (re-search-forward diff-file-header-re nil t)))
883 (or 883 (let ((fs (diff-hunk-file-names old)))
884 ;; use any previously used preference 884 (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs)))
885 (cdr (assoc fs diff-remembered-files-alist)) 885 (or
886 ;; try to be clever and use previous choices as an inspiration 886 ;; use any previously used preference
887 (cl-dolist (rf diff-remembered-files-alist) 887 (cdr (assoc fs diff-remembered-files-alist))
888 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf)))) 888 ;; try to be clever and use previous choices as an inspiration
889 (if (and newfile (file-exists-p newfile)) (cl-return newfile)))) 889 (cl-dolist (rf diff-remembered-files-alist)
890 ;; look for each file in turn. If none found, try again but 890 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf))))
891 ;; ignoring the first level of directory, ... 891 (if (and newfile (file-exists-p newfile)) (cl-return newfile))))
892 (cl-do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files))) 892 ;; look for each file in turn. If none found, try again but
893 (file nil nil)) 893 ;; ignoring the first level of directory, ...
894 ((or (null files) 894 (cl-do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files)))
895 (setq file (cl-do* ((files files (cdr files)) 895 (file nil nil))
896 (file (car files) (car files))) 896 ((or (null files)
897 ;; Use file-regular-p to avoid 897 (setq file (cl-do* ((files files (cdr files))
898 ;; /dev/null, directories, etc. 898 (file (car files) (car files)))
899 ((or (null file) (file-regular-p file)) 899 ;; Use file-regular-p to avoid
900 file)))) 900 ;; /dev/null, directories, etc.
901 file)) 901 ((or (null file) (file-regular-p file))
902 ;; <foo>.rej patches implicitly apply to <foo> 902 file))))
903 (and (string-match "\\.rej\\'" (or buffer-file-name "")) 903 file))
904 (let ((file (substring buffer-file-name 0 (match-beginning 0)))) 904 ;; <foo>.rej patches implicitly apply to <foo>
905 (when (file-exists-p file) file))) 905 (and (string-match "\\.rej\\'" (or buffer-file-name ""))
906 ;; If we haven't found the file, maybe it's because we haven't paid 906 (let ((file (substring buffer-file-name 0 (match-beginning 0))))
907 ;; attention to the PCL-CVS hint. 907 (when (file-exists-p file) file)))
908 (and (not prefix) 908 ;; If we haven't found the file, maybe it's because we haven't paid
909 (boundp 'cvs-pcl-cvs-dirchange-re) 909 ;; attention to the PCL-CVS hint.
910 (save-excursion 910 (and (not prefix)
911 (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) 911 (boundp 'cvs-pcl-cvs-dirchange-re)
912 (diff-find-file-name old noprompt (match-string 1))) 912 (save-excursion
913 ;; if all else fails, ask the user 913 (re-search-backward cvs-pcl-cvs-dirchange-re nil t))
914 (unless noprompt 914 (diff-find-file-name old noprompt (match-string 1)))
915 (let ((file (expand-file-name (or (car fs) "")))) 915 ;; if all else fails, ask the user
916 (setq file 916 (unless noprompt
917 (read-file-name (format "Use file %s: " file) 917 (let ((file (expand-file-name (or (car fs) ""))))
918 (file-name-directory file) file t 918 (setq file
919 (file-name-nondirectory file))) 919 (read-file-name (format "Use file %s: " file)
920 (set (make-local-variable 'diff-remembered-files-alist) 920 (file-name-directory file) file t
921 (cons (cons fs file) diff-remembered-files-alist)) 921 (file-name-nondirectory file)))
922 file)))))) 922 (set (make-local-variable 'diff-remembered-files-alist)
923 (cons (cons fs file) diff-remembered-files-alist))
924 file)))))))
923 925
924 926
925(defun diff-ediff-patch () 927(defun diff-ediff-patch ()