Function: highlight-compare-with-file

highlight-compare-with-file is an autoloaded, interactive and byte-compiled function defined in hilit-chg.el.gz.

Signature

(highlight-compare-with-file FILE-B)

Documentation

Compare this buffer with a file, and highlight differences.

If the buffer has a backup filename, it is used as the default when this function is called interactively.

If the current buffer is visiting the file being compared against, it also will have its differences highlighted. Otherwise, the file is read in temporarily but the buffer is deleted.

If the buffer is read-only, differences will be highlighted but no property changes are made, so M-x highlight-changes-next-change (highlight-changes-next-change) and M-x highlight-changes-previous-change (highlight-changes-previous-change) will not work.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/hilit-chg.el.gz
;;;###autoload
(defun highlight-compare-with-file (file-b)
  "Compare this buffer with a file, and highlight differences.

If the buffer has a backup filename, it is used as the default when
this function is called interactively.

If the current buffer is visiting the file being compared against, it
also will have its differences highlighted.  Otherwise, the file is
read in temporarily but the buffer is deleted.

If the buffer is read-only, differences will be highlighted but no property
changes are made, so \\[highlight-changes-next-change] and
\\[highlight-changes-previous-change] will not work."
  (interactive
   (let ((file buffer-file-name)
	 (file-name nil)
	 (file-dir nil))
     (and file
	  (setq file-name (file-name-nondirectory file)
		file-dir (file-name-directory file)))
     (setq file-name (make-backup-file-name file-name))
     (unless (file-exists-p file-name)
	     (setq file-name nil))
     (list (read-file-name
	    "Find to compare with: "	;; prompt
	    file-dir			;; directory
	    nil				;; default
	    nil				;; existing
	    file-name)			;; initial
	   )))
  (let* ((buf-a (current-buffer))
	 (file-a (buffer-file-name))
	 (existing-buf (get-file-buffer file-b))
	 (buf-b (or existing-buf
		    (find-file-noselect file-b))))
    (highlight-markup-buffers buf-a file-a buf-b file-b (not existing-buf))
    (unless existing-buf
      (kill-buffer buf-b))))