;	FORTH.CMD:	Forthmacs MENU Page
;			for MicroEMACS 3.9e and above
;			(C)opyright 1988 by Daniel Lawrence
;			(C)opyright 1995 hs

; set up the "clean"; ********************************************
store-procedure clean
	delete-buffer "[Macro 10]"
	delete-buffer "[Macro 11]"
	delete-buffer "[Macro 12]"
!endm

; make sure the function key window is up
set %rcfkeys FALSE
execute-macro-1
write-message "Loading..."

; Write out the page instructions
save-window
1 next-window
beginning-of-file
set $curcol 25
overwrite-string " F1 whatis:               F2 whatis cursor-word"
next-line
set $curcol 25
overwrite-string "                                               "
next-line
set $curcol 25
overwrite-string "                                               "
next-line
set $curcol 18
overwrite-string "4th "
set $curcol 25
overwrite-string "                                               "
next-line
set $curcol 25
overwrite-string "                                               "
unmark-buffer
beginning-of-file
!force restore-window
update-screen

; ********************************************
;	find onlinehelp in whatis_doc for keyboard given word
10 store-macro
	set %what "Type in word to search for "
	set %what  @%what
	run getonline
	!endm
bind-to-key execute-macro-10 S-FN1

; ********************************************
;	find online help in whatis_doc for word under cursor
11 store-macro
	run isolate-word
	run getonline
	!endm
bind-to-key execute-macro-11 S-FN2

; Search for beginning of word, bounds are defined by non-space-characters
store-procedure to-front-word
	!if &les $curchar 33
		!force previous-word
	!endif
	!while &and  &gre $curchar 32  &not $bufbeg
		backward-character
	!endwhile
	!while &les $curchar 33
		!force forward-character
	!endwhile
	!endm

; isolate word at Cursor in %what
store-procedure isolate-word
	set %tmpcol  $curcol
	set %tmpline $curline
	run to-front-word
	set %what ""
	!while &gre $curchar 32
		set %what  &cat %what   &chr $curchar
		forward-character
	!endwhile
	set $curline %tmpline
	set $curcol %tmpcol
	!endm

; procedure to get help-info in whatis.doc for string contained in %what
store-procedure getonline
;	setup windows for use
	save-window
	set $discmd FALSE
	1 next-window 
	!force 1 split-current-window
	!force find-file "Forthmacs:risc_os.whatis_doc"
!if $status
	add-mode "green"
	add-mode "WHITE"
	add-mode "EXACT"
	beginning-of-file
	write-message &cat "Searching for  " %what
	set %what  &cat "
" %what
*onlineloop
	!force search-forward %what
	!if $status
		!if &less $curchar 33
			set %tmpcol  $curcol
			set %tmpline $curline
			beginning-of-line
			next-line
			!force 1 resize-window
			!while &les $curchar 33
				next-line
				grow-window
			!endwhile
			set $curline %tmpline
			set $curcol %tmpcol
			1 redraw-display
			update-screen
			set %what "Press RETURN to continue"
			set %what  @%what
			write-message ""
		!else
			!goto onlineloop
		!endif
	!else
		write-message "No information in whatis_doc"
	!endif

!else
	write-message "problems with whatis_doc"
!endif
	!force 1 delete-window
	!force restore-window
	execute-macro-1
	execute-macro-1
	set $discmd TRUE
!endm

write-message "[Forthmacs MENU page loaded]"
