;	EMACS.RC:	Startup file for MicroEMACS 3.8
;
;			This file is executed everytime the
;			editor is entered

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

; If you screen "SNOWS", uncomment this line
;	set $flicker "TRUE"

; If you are on an IBM-PC EGA card and want to force the
; screen to EGA mode, uncomment the following line
;	set $sres "EGA"

;	***** Rebind the Function key group

bind-to-key search-forward		FNP
bind-to-key search-reverse		FNQ
bind-to-key hunt-forward		FNR
bind-to-key hunt-backward		FNS
bind-to-key next-window			FNT
bind-to-key execute-macro		FNU
bind-to-key find-file			FNV
bind-to-key execute-file		FNW
bind-to-key save-file			FNX
bind-to-key exit-emacs			FNY

bind-to-key apropos			FNr
bind-to-key describe-key		FNs
bind-to-key fill-paragraph		FNt
bind-to-key shell-command		FNx
bind-to-key i-shell			FNy

;	set screen colors
add-global-mode "black"

;	toggle function key window off
1 store-macro
	save-window
	1 next-window
	!if &sequal "Function Keys" $cbufname
		delete-window
	!endif
	bind-to-key execute-macro-14 FNp
!force	restore-window
	write-message "[Function key window OFF]"
!endm

;	toggle function key window back on
14 store-macro
	1 next-window
	!if &sequal $cbufname "emacs.hlp"
		execute-macro-11
	!endif
	!if &not &sequal $cbufname "Function Keys"
		1 split-current-window
		select-buffer "Function Keys"
		add-mode "red"
!force		5 resize-window
		beginning-of-file
	!endif
	bind-to-key execute-macro-1 FNp
	2 next-window
	write-message "[Function key window ON]"
!endm

;	Enter Help
2 store-macro
	1 next-window		;Make sure the function key window isn't up!
	!if &sequal $cbufname "Function Keys"
		delete-window
		bind-to-key execute-macro-14 FNp
	!endif
	help
	8 resize-window
	bind-to-key execute-macro-12 FNt
	bind-to-key execute-macro-13 FNs
	bind-to-key execute-macro-11 FNq
	bind-to-key execute-macro-15 ^XO
	bind-to-key execute-macro-15 ^XP
	bind-to-key execute-macro-15 FN4
	add-mode "red"
	beginning-of-file
	2 forward-character
	clear-message-line
!endm

;	Exit Help
11 store-macro
	bind-to-key previous-page FNt
	bind-to-key next-page FNs
	bind-to-key execute-macro-2 FNq
	bind-to-key next-window ^XO
	bind-to-key previous-window ^XP
	bind-to-key next-window FN4
	delete-window
	clear-message-line
!endm

;	don't allow these commands from within the HELP screen
15	store-macro
	write-message "[Use F2 to exit HELP]"
!endm

;	last help page
12 store-macro
	beginning-of-line
	search-reverse "=>"
	1 redraw-display
!endm

;	next help page
13 store-macro
	beginning-of-line
	2 forward-character
	search-forward "=>"
	1 redraw-display
!endm

;	reformat indented paragraph

6 store-macro
	write-message "                    [Fixing paragraph]"
	set $discmd "FALSE"
	kill-region
	2 split-current-window
	select-buffer "[temp]"
	yank
	beginning-of-file
	replace-string "~n	" "~n"
	66 set-fill-column
	fill-paragraph
	77 set-fill-column
	beginning-of-file
	handle-tab
	replace-string ~n "~n	"
	end-of-file
	2 delete-previous-character
	beginning-of-file
	set-mark
	end-of-file
	kill-region
	unmark-buffer
	delete-window
	yank
	delete-buffer "[temp]"
	set $discmd "TRUE"
	write-message "                    [Fixed paragraph]"
!endm

;	indent region

7 store-macro
	write-message "                    [Indenting region]"
	kill-region
	2 split-current-window
	select-buffer "[temp]"
	yank
	beginning-of-file
	handle-tab
	replace-string "~n" "~n	"
	end-of-file
	4 delete-previous-character
	beginning-of-file
	set-mark
	write-message "                    [Indenting region]"
	end-of-file
	kill-region
	unmark-buffer
	delete-window
	yank
	delete-buffer "[temp]"
	write-message "                    [Region Indented]"
!endm

;	undent region

8 store-macro
	write-message "                    [Undenting region]"
	kill-region
	2 split-current-window
	select-buffer "[temp]"
	yank
	beginning-of-file
	delete-next-character
	replace-string "~n	" "~n"
	end-of-file
	2 delete-previous-character
	beginning-of-file
	set-mark
	write-message "                    [Undenting region]"
	end-of-file
	kill-region
	unmark-buffer
	delete-window
	yank
	delete-buffer "[temp]"
	write-message "                    [Region undented]"
!endm

;	bring up the function key window

	1 split-current-window
	select-buffer "Function Keys"
	add-mode "red"
	5 resize-window
	insert-string "f1 search      f2 search back | F1 toggle function list F2 toggle help file~n"
	insert-string "f3 hunt        f4 hunt back   | F3 find command/apropos F4 describe key~n"
	insert-string "f5 next window f6 exec macro  | F5 reformat paragraph   F6 ref undented region~n"
	insert-string "f7 find file   f8 exec file   | F7 indent region        F8 undent region~n"
	insert-string "f9 save file  f10 exit emacs  | F9 execute DOS command F10 shell up~n"
	beginning-of-file
	unmark-buffer
	next-window
	set $discmd "TRUE"
	write-message "[Emacs is READY]"
