; Groom a code file into troff by:
;
;     (a) untabifying
;     (b) converting C/C++ backslash sequences to use double backslashes
;     (c) writing the current file to a file of the same whole name with the
;         .me extension.
; If the add-more-troff arg is true, then .(t 0 ... .)t0 brackets are added at
; the beginning and ending of the file.
;

(defun dot () (point))

(defun groom-code-to-me (add-more-troff)
"Groom a code file into troff by:

    (a) untabifying
    (b) converting C/C++ backslash sequences to use double backslashes
    (c) writing the current file to a file of the same whole name with the
        .me extension.
If the add-more-troff arg is true, then a standard -me header is added and
.(t 0 ... .)t0 brackets are placed at the beginning and ending of the file."

    (interactive)

    ; Untabify.
    (end-of-buffer)
    (setq d (dot))
    (beginning-of-buffer)
    (untabify (dot) d)

    ; Convert badkslash sequences (*love* these backslash sequences).
    (beginning-of-buffer)
    (replace-regexp "\\\\\\([nt0]\\)" "\\\\\\\\\\1")

    ; Add .(t 0 ... .)t 0 if we're supposed to.
    (if add-more-troff
      (progn
	(beginning-of-buffer)
	(insert-string
	  (concat
	    ".sz 11\n"
	    ".ds ~ /usersgfisher/nroff\n"
	    ".so \\*~/stdhdr.me\n"
	    ".(t 0\n"
	  )
	)
	(end-of-buffer)
	(insert-string ".)t 0\n")
      )
    )

    ; Write to filename.me
    (write-file
        (concat (buffer-file-name) ".me")
    )
)