;;
;; Macros for obtaining manual pages and then attributing them.
;;
;; Author: Kevin Buettner
;;
;; $Header: /usr/build/vile/vile/macros/RCS/manpage.rc,v 1.13 2000/06/27 23:28:37 tom Exp $
;;

store-procedure ShowManpage "Prompt for, and display a manual-page"
	~local %filter %manpage %manpagebuf $error-buffer
	set-variable %filter &lookup e+l+p &cat vile-manfilt $exec-suffix
	~if &seq %filter ""
		write-message "[Cannot find manpage-filter]"
		~return
	~endif
	set-variable %manpage &query "man page? "
	~if &or &seq %manpage "ERROR" &seq %manpage ""
		~return
	~endif
	set-variable %manpagebuf &cat "<" &cat %manpage ">"
	set terse
	~force select-buffer %manpagebuf
	~if &not $status
		edit-file &cat "!man " &cat %manpage &cat " | " %filter
		setl txtmode
		setl autocolor=0
		~force rename-buffer %manpagebuf
		~force error-buffer %manpagebuf
		write-message "[Attaching bold and underline attributes...]"
		goto-beginning-of-file
		setl noview
		attribute-cntl_a-sequences-til end-of-file
		unmark-buffer
		setl view
		goto-beginning-of-file
		unsetv $cfilname
		write-message "[Done formatting manual page.]"
	~endif
	set noterse
~endm
bind-key ShowManpage ^X-m

store-procedure ShowFormatted "Render the current buffer with nroff -man or -ms"
	~local %type %filter %manpagesrc %manpagebuf $error-buffer
	set-variable %filter &lookup e+l+p &cat vile-manfilt $exec-suffix
	~if &seq %filter ""
		write-message "[Cannot find manpage-filter]"
		~return
	~endif
	~if &sin $cbufname "<"
		set-variable %manpagebuf $cbufname
		set-variable %manpagesrc &mid $cbufname 2 &sub &len $cbufname 2
		~force select-buffer %manpagesrc
		~if &not $status
			write-message &cat "Buffer not found: " %manpagesrc
			~return
		~endif
	~else
		set-variable %manpagebuf &cat "<" &cat $cbufname ">"
	~endif
	set terse
	~force kill-buffer %manpagebuf
	setv %type &path end $cfilname
	~if &seq $majormode "html"
		edit-file &cat "!cat " &cat $cfilname &cat " | lynx -stdin -with_backspaces -dump | " %filter
	~elseif &seq %type ".ms"
		edit-file &cat "!tbl " &cat $cfilname &cat " | nroff -ms | " %filter
	~else
		edit-file &cat "!tbl " &cat $cfilname &cat " | nroff -man | " %filter
	~endif
	setl txtmode
	setl autocolor=0
	~force rename-buffer %manpagebuf
	~force error-buffer %manpagebuf
	write-message "[Attaching bold and underline attributes...]"
	goto-beginning-of-file
	setl noview
	attribute-cntl_a-sequences-til end-of-file
	unmark-buffer
	setl view
	goto-beginning-of-file
	unsetv $cfilname
	write-message "[Done formatting manual page.]"
	set noterse
~endm
bind-key ShowFormatted ^X-n
