;	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

; Uncomment the following and the lowercase colours only for use on console
; If your screen "SNOWS", comment this line
	set $flicker "FALSE"

; CHOOSE ONE OF THE FOLLOWING
; To use a MONO 25-line display, uncomment the following line
;	set $sres "MONO"

; To use a 25-line display, uncomment the following line
;	set $sres "CGA"

; To use a 43-line display, uncomment the following line
;	set $sres "EGA"

; To use a 50-line display, uncomment the following line
	set $sres "VGA"

;	***** 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
write-message "[Setting up....]"
;add-global-mode "GREY"	; uncomment this for MONO
;add-global-mode "black" ; uncomment this for MONO
add-global-mode "blue" ; uncomment for colour
add-global-mode "GREY" ; uncomment for colour

;uncomment the following key to change META from ESC
;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 "view"
		add-mode "red"  ; uncomment for colour
		add-mode "GREY" ; uncomment for colour
;		add-mode "BLACK" ; uncomment for MONO
;		add-mode "grey"  ; uncomment for MONO
		!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
	save-window
	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 "magenta"	; uncomment for colour
		add-mode "WHITE"	; uncomment for colour
;		add-mode "BLACK"	; uncomment for MONO
;		add-mode "grey"		; uncomment for MONO
		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

;Decrement character value

32	store-macro
	set $curchar &band &sub $curchar 1 255
!endm

;Increment character value

33	store-macro
	set $curchar &band &add $curchar 1 255
!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"
		set $hardtab 4
	!endif
	!if &or &seq %rctmp "mss" &seq %rctmp "txt"
		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   LISP~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

bind-to-key execute-macro-24 ^C

24	store-macro	; twiddle
	1 set-mark
	backward-character
	1 kill-region
	backward-character
	yank
	forward-character
!endm

bind-to-key execute-macro-25 ^]

25	store-macro ; twiddle words
	1 set-mark
	end-of-word
	delete-previous-word
	2 set-mark
	previous-word
	yank
	insert-space
	end-of-word
	delete-previous-word
	delete-previous-character
	2 exchange-point-and-mark
	yank
	1 exchange-point-and-mark
!endm

bind-to-key execute-macro-26 FNC

26	store-macro ;	toggle overwrite mode
	!if %overmode
		!goto overoff
	!endif
	add-mode "over"
	set %overmode TRUE
	!return


*overoff
	set %overmode FALSE
	delete-mode "over"
!endm

