;	EMACS.RC:	Standard micro Startup program
;			for MicroEMACS 3.9d and above
;			(C)opyright 1987 by Daniel M Lawrence
;			Last Update: 10/20/87

set $discmd FALSE
write-message "[Setting up....]"

; If you screen "SNOWS", comment this line
	set $flicker "FALSE"

; To use an IBM-PC EGA card, uncomment the following line
;	set $sres "EGA"

;	***** Rebind the Function key group

bind-to-key search-forward		FN1
bind-to-key search-reverse		FN2
bind-to-key hunt-forward		FN3
bind-to-key hunt-backward		FN4
bind-to-key execute-macro-1		FN5
bind-to-key execute-macro-2		FN6
bind-to-key next-window			FN7
bind-to-key execute-macro-3		FN8
bind-to-key save-file			FN9
bind-to-key exit-emacs			FN0

bind-to-key execute-macro-10		S-FN1
bind-to-key execute-macro-11		S-FN2
bind-to-key execute-macro-12		S-FN3
bind-to-key execute-macro-13		S-FN4
bind-to-key execute-macro-14		S-FN5
bind-to-key execute-macro-15		S-FN6
bind-to-key execute-macro-16		S-FN7
bind-to-key execute-macro-17		S-FN8
bind-to-key execute-macro-18		S-FN9
bind-to-key execute-macro-19		S-FN0

;	Set Default Global modes

add-global-mode "blue"
;bind-to-key next-page FN<
;bind-to-key previous-page FNC
;bind-to-key meta-prefix `

;	Toggle function key window display

1	store-macro
	!if %rcfkeys
		!goto rcfoff
	!endif

;	toggle function key window on
	save-window
	1 next-window
	!if &sequal $cbufname "emacs.hlp"
		delete-window
	!endif
	!if &not &sequal $cbufname "Function Keys"
		1 split-current-window
		1 select-buffer "Function Keys"
		add-mode "red"
		!force 5 resize-window
		1 goto-line
	!endif
	set %rcfkeys TRUE
	!force restore-window
	!if &sequal $cbufname "Function Keys"
		next-window
	!endif
	write-message "[Function key window ON]"
	!return

	;Toggle the function key window off
*rcfoff
	save-window
	1 next-window
	!if &sequal "Function Keys" $cbufname
		delete-window
	!endif
	!force restore-window
	write-message "[Function key window OFF]"
	set %rcfkeys FALSE
!endm

;	Toggle HELP file onscreen

2 store-macro
	1 next-window

	;Make sure the function key window isn't up!
	!if &sequal $cbufname "Function Keys"
		delete-window
	!endif
	set %rcfkeys FALSE

	;Bring up page 1
	!if &not &seq $cbufname "emacs.hlp"
		help
		8 resize-window
		add-mode "red"
		beginning-of-file
		2 forward-character
	!endif

*rchelp

	write-message "[PgUp/PgDn] Page    [FN6] EXIT     ^G  Exit leaving page on screen"
	update-screen
	set %rctmp &gtcmd
	!if &seq %rctmp FNZ
		beginning-of-line
		!force search-reverse "=>"
		1 redraw-display
		!goto rchelp
	!endif
	!if &seq %rctmp FNV
		beginning-of-line
		2 forward-character
		!force search-forward "=>"
		1 redraw-display
		!goto rchelp
	!endif
	!if &seq %rctmp FN6
		delete-window
		!if &seq %rcfkeys TRUE
			set %rcfkeys FALSE
			execute-macro-1
		!endif
		write-message "[Help Exited]"
		!return
	!endif
	!if &seq %rctmp ^G
		next-window
		set %rcfkeys FALSE
		write-message "[Help Aborted]"
		!return
	!endif
	!goto rchelp
!endm

;	Load a new page

3	store-macro
	!if &seq &find newpage.cmd ""
		write-message "[Can not find NEWPAGE.CMD]"
		!return
	!endif
	execute-file newpage.cmd
!endm

;procedure to clean out the current page (which is nothing right now)

store-procedure	clean
	; nothing by default
!endm

;	Set up auto CMODE

20	store-macro
	set %rctmp &sin $cfname "."
	!if &equ %rctmp 0
		!return
	!endif
	set %rctmp &mid $cfname &add %rctmp 1 5
	!if &or &seq %rctmp "c" &seq %rctmp "h"
		add-mode "cmode"
	!endif
	!if &seq %rctmp "mss"
		add-mode "wrap"
	!endif
!endm
set $readhook execute-macro-20

;	This function activates the function key window as
;	a legitimate place to call up function keys

21	store-macro

	;remember where we started, and do the mouse movement
	save-window
	mouse-move-down

	;If not in the function key window... leave
	!if &not &sequal $cbufname "Function Keys"
		!return
	!endif

	;Find out what function key were gonna do
	add-mode magic
	2 forward-character
	set %rctmp $search
	!force search-reverse "[fF][0-9]"
	!if &seq $status FALSE
		delete-mode magic
		set $search %rctmp
		!return
	!endif

	;we are on the "f" or "F".  Get the function key type and number now
	set $search %rctmp
	set %fcase lower
	!if &equ $curchar 70
		set %fcase upper
	!endif
	1 forward-character
	set %fnum &chr $curchar
	1 forward-character
	set %fnum &cat %fnum &chr $curchar
	set %fnum &add %fnum 0
	!if &equ %fnum 10
		set %fnum "0"
	!endif
	set %fname &cat "FN" %fnum
	!if &seq %fcase upper
		set %fname &cat "S-" %fname
	!endif

	;save the function
	set %rccmd &bind %fname
	delete-mode MAGIC

	;swallow the up-button
	set %rctmp &gtc

	;restore the window and exit
	restore-window

	;and then execute it
	execute-named-command &ind %rccmd
!endm	
bind-to-key execute-macro-21 MSa

;	bring up the function key window

	1 split-current-window
	select-buffer "Function Keys"
	insert-string "f1 search-> f2 <-search Û    MicroEMACS:  Text Editor~n"
	insert-string "f3 hunt->   f4 <-hunt   Û ~n"
	insert-string "f5 fkeys    f6 help     Û  Available function key Pages include:~n"
	insert-string "f7 nxt wind f8 pg[    ] Û    WORD  BOX  EMACS  PASCAL  C   COBOL~n"
	insert-string "f9 save     f10 exit    Û  [use the f8 key to load Pages]~n"
	unmark-buffer
	delete-window
	set %rcfkeys FALSE
	execute-macro-1
	set $discmd TRUE
