 ;;; Code:
 
 (defvar in-memory-this nil
-  "This source buffer")
+  "This source buffer.")
 
 (defvar in-memory-other nil
-  "The other source buffer")
+  "The other source buffer.")
 
 (defun in-memory-line ()
   "Return the current line."

    (define-key map "q" 'bury-buffer)
    (define-key map (kbd "RET") 'in-memory-diff-visit)
    map)
  "Keymap for In Memory Diff mode")

(define-derived-mode in-memory-diff-mode fundamental-mode "extra-lines")

(defun in-memory-insert (lines1 lines2)
  "Insert all the lines of LINES1 not in LINES2
in the current buffer."
  (dolist (line lines1)
    (when (not (member line lines2))
      (insert line "\n"))))

(defun in-memory-diff (buffer1 buffer2)
  "Show the difference between two buffers

BUFFER1 and BUFFER2 are treated as a set of unordered lines, as
one would excpect for a file like ~/.authinfo.gpg, for example.
We don't use diff(1) to diff the buffers and don't write
temporary files to disk."
  (interactive "bBuffer A: \nbBuffer B: ")
  (let ((lines (mapcar (lambda (buf)
			 (with-current-buffer buf
			   (split-string (buffer-string) "\n")))
		       (list buffer1 buffer2))))
    
    (with-current-buffer (get-buffer-create "*A*")
      (let ((inhibit-read-only t))
	(erase-buffer)
	(apply 'in-memory-insert lines))
      (in-memory-diff-mode)
      (set (make-local-variable 'in-memory-this) buffer1)
      (set (make-local-variable 'in-memory-other) buffer2)
      (display-buffer (current-buffer)))
    (with-current-buffer (get-buffer-create "*B*")
      (let ((inhibit-read-only t))
	(erase-buffer)
	(apply 'in-memory-insert (reverse lines)))
      (in-memory-diff-mode)
      (set (make-local-variable 'in-memory-this) buffer2)
      (set (make-local-variable 'in-memory-other) buffer1)


;; `in-memory-diff' takes two source buffers and treats their content
;; as a set of unordered lines, as one would excpect for a file like
;; ~/.authinfo.gpg, for example.  We don't use diff(1) to diff the
;; buffers and thus we don't write temporary files to disk.  The result
;; is two buffers, *A* and *B*.  Each contains the lines the other
;; buffer does not contain.  These files are in a major mode with the
;; following interesting keys bindings:
;;
;; c – copy the current line to the other source buffer
