[net.emacs] New man.ml

jim (03/08/83)

The man.ml in the Gosling emacs distribution puts a manual page into a
window by running the "man" command and piping the output into the
window.  This can be very slow.  On some systems, pre-formatted man
pages are kept in /usr/man/cat?, and man.ml can be made much faster by
visiting the cat files directly instead of running man, which involves
forking shells, etc.

Here is a modified man.ml to visit the cat files.  It is just something
I hacked up one day, and should probably be tested and spruced up a bit
before actually being installed by anyone.  If any of you mlisp hackers
want to fix it up, or have a better one already, I'd like to hear from
you.

	- James Rees
	...!decvax!microsoft!uw-beaver!jim
	Jim@uw-vlsi

(defun 
    (manual-entry subj subjfile errmsg
	(setq subj (arg 1 "Subject: "))
	(setq errmsg "")
	(temp-use-buffer "Manual entry")
	(erase-buffer)
	(temp-use-buffer "Scratch")
	(setq needs-checkpointing 0)
	(erase-buffer)
	(set-mark)
	(filter-region
	    (concat "/usr/ucb/whereis -m -M /usr/man/cat? -f " subj))
	(previous-line)
	(if (error-occured (search-forward " "))
	    (save-excursion
		(message "No formatted entry, trying unformatted ...")
		(sit-for 0)
		(temp-use-buffer "Manual entry")
		(set-mark)
		(filter-region (concat "/usr/ucb/man " subj))
		(if (< (buffer-size) 80)
		    (progn
			(beginning-of-file)
			(set-mark)
			(end-of-line)
			(setq errmsg (region-to-string))
		    )
		)
	    )
	    (progn
		(while (! (eolp))
		    (set-mark)
		    (if (error-occured (search-forward " "))
			(end-of-line)
			(delete-previous-character)
		    )
		    (setq subjfile (region-to-string))
		    (save-excursion
			(temp-use-buffer "Manual entry")
			(end-of-file)
			(insert-file subjfile)
		    )
		)
	    )
	)
	(if (!= (length errmsg) 0)
	    (message errmsg)
	    (progn
		(pop-to-buffer "Manual entry")
		(beginning-of-file)
		(message "Still working, be patient ...")
		(sit-for 0)
		(error-occured (re-replace-string "_\b" ""))
		(error-occured (re-replace-string
				   "^[A-Z][A-Z]*([0-9]*).*)$"
				   ""))
		(error-occured (re-replace-string "^Printed [0-9].*[0-9]$" ""))
		(error-occured (re-replace-string "\n\n\n\n*" "\n\n"))
		(if (looking-at "\n\n*")
		    (progn
			(region-around-match 0)
			(erase-region)))
		(setq buffer-is-modified 0)
	    )
	)
	(novalue)
    )
)