;;
;; Macros for obtaining manual pages and then attributing them.
;;
;; Author: Kevin Buettner
;;
;; $Header: /usr/build/vile/vile/macros/RCS/manpage.rc,v 1.8 1999/10/18 10:16:23 tom Exp $
;;

store-procedure ShowManpage "Prompt for, and display a manual-page"
	~local %filter %manpage %manpagebuf
	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
		~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
		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 %filter %manpagesrc %manpagebuf
	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
	~if &sin $cfilname ".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
	~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
	write-message "[Done formatting manual page.]"
	set noterse
~endm
bind-key ShowFormatted ^X-n
