This is a synch from FSF Emacs a friend of mine has asked for. Will
commit Friday or so if nobody objects:
2010-08-18 Mike Sperber <mike(a)xemacs.org>
* files.el (diff-files-for-recover): Abstract this out out
(diff-buffer-with-file): Add from (GPLv2) FSF Emacs.
(recover-file): Use `diff-files-for-recover'.
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
diff --git a/lisp/files.el b/lisp/files.el
＠＠ -3060,6 +3060,83 ＠＠
+(defun diff-buffer-with-file (&optional buffer)
+ "View the differences between BUFFER and its associated file.
+This requires the external program `diff' to be in your `exec-path'."
+ (interactive "bBuffer: ")
+ (with-current-buffer (get-buffer (or buffer (current-buffer)))
+ (if (and buffer-file-name
+ (file-exists-p buffer-file-name))
+ (let ((tempfile (make-temp-file "buffer-content-")))
+ (write-region (point-min) (point-max) tempfile nil 'nomessage)
+ (diff-files-for-recover "File"
+ buffer-file-name tempfile buffer-file-name tempfile
+ (sit-for 0))
+ (when (file-exists-p tempfile)
+ (delete-file tempfile))))
+ (message "Buffer %s has no associated file on disc" (buffer-name))
+ ;; Display that message for 1 second so that user can read it
+ ;; in the minibuffer.
+ (sit-for 1)))
+ ;; return always nil, so that save-buffers-kill-emacs will not move
+ ;; over to the next unsaved buffer when calling `d'.
+(defun diff-files-for-recover (purpose file-1 file-2
+ failed-file-1 failed-file-2
+ "Diff two files for recovering or comparing against the last saved version.
+PURPOSE is an informational string used for naming the resulting buffer.
+FILE-1 and FILE-2 are the two files to compare.
+FAILED-FILE-1 and FAILED-FILE-2 are the names of files for which we should
+generate directory listings on failure.
+CODING-SYSTEM is the coding system of the resulting buffer."
+ (with-output-to-temp-buffer (concat "*" purpose " Diff*")
+ (buffer-disable-undo standard-output)
+ (let ((coding-system-for-read coding-system))
+ (condition-case ferr
+ (apply #'call-process
+ nil standard-output nil
+ (list file-1 file-2)))
+ (if (fboundp 'diff-mode)
+ (set-buffer standard-output)
+ (declare-fboundp (diff-mode)))))
+ (let ((switches
+ (if (file-symlink-p failed-file-2)
+ (setq switches (concat switches "L")))
+ (set-buffer standard-output)
+ ;; XEmacs had the following line, not in FSF.
+ (setq default-directory (file-name-directory failed-file-2))
+ ;; Use insert-directory-safely,
+ ;; not insert-directory, because
+ ;; these files might not exist.
+ ;; In particular, FAILED-FILE-2 might not
+ ;; exist if the auto-save file
+ ;; was for a buffer that didn't
+ ;; visit a file, such as
+ ;; "*mail*". The code in v20.x
+ ;; called `ls' directly, so we
+ ;; need to emulate what `ls' did
+ ;; in that case.
+ (insert-directory-safely failed-file-1 switches)
+ (insert-directory-safely failed-file-2 switches))
+ (princ "Error during diff: ")
+ (display-error ferr standard-output)))))))
(defcustom save-some-buffers-query-display-buffer t
"*Non-nil makes `\\[save-some-buffers]' switch to the buffer offered for
＠＠ -3689,44 +3766,7 ＠＠
(write-region (point-min) (point-max)
temp nil 'silent)))
- (with-output-to-temp-buffer "*Autosave Diff*"
- (buffer-disable-undo standard-output)
- (let ((coding-system-for-read
- (condition-case ferr
- (apply #'call-process
- nil standard-output nil
- (list temp file-name)))
- (let ((switches
- (if (file-symlink-p file)
- (setq switches (concat switches "L")))
- (set-buffer standard-output)
- ;; XEmacs had the following line, not in FSF.
- (setq default-directory (file-name-directory file))
- ;; Use insert-directory-safely,
- ;; not insert-directory, because
- ;; these files might not exist.
- ;; In particular, FILE might not
- ;; exist if the auto-save file
- ;; was for a buffer that didn't
- ;; visit a file, such as
- ;; "*mail*". The code in v20.x
- ;; called `ls' directly, so we
- ;; need to emulate what `ls' did
- ;; in that case.
- (insert-directory-safely file switches)
- (insert-directory-safely file-name switches))
- (princ "Error during diff: ")
- (display-error ferr
+ (diff-files-for-recover "Autosave" temp file-name file file-name
(ignore-errors (kill-buffer buffer))
XEmacs-Patches mailing list