# left and right cursor-keys with line-wraparound

map `left'   `ifelse l `if !t `up last'' left'
map `right'  `ifelse r `if !b `down first'' right'


# shift-(cursor key): up and down one page, left and right one word

map `s-up'   `pageup'
map `s-dow'  `pagedown'
map `s-lef'  `wleft'
map `s-rig'  `wright'


# alt-(cursor key): top and bottom of screen, left and right 40 characters

map `a-up'   `screentop'
map `a-dow'  `screenbottom'
map `a-lef'  `repeat 40 left'
map `a-rig'  `repeat 40 right'


# shift-alt-(cursor key): top and bottom of file, first and last character of line

map `sa-up'  `top'
map `sa-dow' `bottom'
map `sa-lef' `first'
map `sa-rig' `last'


# ctrl-(cursor key): scroll up and down

map `c-up'   `scrollup'
map `c-dow'  `scrolldown'


# allow use of mouse to select, copy and delete blocks of text; separate clipboards are maintained for the left and right mouse-buttons;
# shift-(left-mouse-button click): define start and end of current block; automatically copies block into left clipboard; automatically undefines old block
# ctrl-(left-mouse-button click): goto start of current block
# alt-(left-mouse-button click): goto end of current block
# shift-alt-(left-mouse-button click): copy contents of left clipboard above to the line clicked upon
# ctrl-shift-alt-(left-mouse-button click): delete current block after copying it into left clipboard

resettoggle 179
map `sL-lmb'   `if 179 unblock tomouse block ifelse cb `bsave ram:dme.L.clip settoggle 179' `resettoggle 179''
map `cL-lmb'   `goto start'
map `aL-lmb'   `goto end'
map `saL-lmb'  `tomouse insfile ram:dme.L.clip'
map `csaL-lmb' `bsave ram:dme.L.clip bdelete'


# same as definitions above, except utilize right mouse-button and operate upon the right clipboard

map `sR-rmb'   `if 179 unblock tomouse block ifelse cb `bsave ram:dme.R.clip settoggle 179' `resettoggle 179''
map `cR-rmb'   `goto start'
map `aR-rmb'   `goto end'
map `saR-rmb'  `tomouse insfile ram:dme.R.clip'
map `csaR-rmb' `bsave ram:dme.R.clip bdelete'


# return:	return-with-indent which handles DME bug of adding 2 lines at the end of a file;
# shift-return: return-with-indent-and-text-split which handles DME bug of adding 2 lines at the end of a file;

map `return'   `last  ifelse b `split firstnb down down deline' `split firstnb down'  '
map `s-return' `ifelse  b  `split down down deline up firstnb'  `split firstnb'  repeat cleft `first down ` ' up'  firstnb down'


# del:		 TRUE delete, including end-of-line join; handles rich and varied set of bugs with join command
# shift-del:	 TRUE word-delete, etc.
# shift-alt-del: line-delete

map `del'    `ifelse !r del `ifelse l `if !b deline' `resettoggle 1 resettoggle 2 source ram:join.edrc'''
map `s-del'  `ifelse ca `resettoggle 0' `settoggle 0' settoggle 3 while 3 `ifelse !r del `ifelse l `if !b deline' `resettoggle 1 resettoggle 2 source ram:join.edrc'' ifelse 0 `resettoggle 3' `if !ca `resettoggle 3''''
map `sa-del' `deline'


# bs:		TRUE backspace, including end-of-line join; handles rich and varied set of bugs with join command
# shift-bs:	TRUE word-backspace, etc.
# shift-alt-bs: line-delete

map `bs'     `ifelse l `ifelse t up `up last'' left ifelse !r del `ifelse l `if !b deline' `resettoggle 1 resettoggle 2 source ram:join.edrc'''
map `s-bs'   `settoggle 3 while 3 `ifelse l `ifelse t up `up last'' left ifelse l `resettoggle 3' `left if !ca `resettoggle 3' right' if !ca `resettoggle 3' ifelse !r del `ifelse l `if !b deline' `resettoggle 1 resettoggle 2 source ram:join.edrc''''
map `sa-bs'  `deline'


# prompt: replace current file with new one; prompt: open new window with new file

map `f1'     `escimm `newfile ''
map `s-f1'   `escimm `newwindow newfile ''


# prompt: insert file before current line; prompt: change name of current file

map `f2'     `escimm `insfile ''
map `s-f2'   `escimm `chfilename ''


#prompt: save file as ?; save current file

map `f3'     `escimm `saveas ''
map `s-f3'   `saveold'


#safe quit; save current file then quit

map `f4'     `quit'
map `s-f4'   `saveold quit'


#execute the right and left clipboards as macros

map `f5'     `source dme.R.clip'
map `s-f5'   `source dme.L.clip'


# open small windows to view contents of the left and right clipboards

map `f6'     `topedge 12 height 45 newwindow newfile dme.R.clip topedge 1 height 360'
map `s-f6'   `topedge 58 height 45 newwindow newfile dme.L.clip topedge 1 height 360'

# find previous occurrence of find-string
# find/replace previous occurrence of find-string; differs from prevr in that it will change word under the cursor (allowing you to selectively find-and-replace with a minimum of keystrokes)
# prompt: find/replace all previous occurrences of find-string

map `f7'     `prev'
map `s-f7'   `ifelse r `if !b `down first'' `right' prevr'
map `sa-f7'  `escimm `ifelse r  `if !b `down first'' `right'  prevr  repeat -1 prevr''


# find next occurrence of find-string
# find/replace next occurrence of find-string; differs from findr in that it will change word under the cursor (allowing you to selectively find-and-replace with a minimum of keystrokes)
# prompt: find/replace all subsequent occurrences of find-string

map `f8'     `next'
map `s-f8'   `ifelse l `if !t `up last'' `left' nextr'
map `sa-f8'  `escimm `ifelse l  `if !t `up last'' `left'  nextr  repeat -1 nextr''


# prompt: define find-string and search for previous occurrence of it
# prompt: define find-string and replace-string and search for previous occurrence of find-string

map `f9'     (escimm (findstr `) prev)
map `s-f9'   (escimm (findstr `) escimm (repstr `) prev)


# prompt: define find-string and search for next occurrence of it
# prompt: define find-string and replace-string and search for next occurrence of find-string

map `f10'    (escimm (findstr `) next)
map `s-f10'  (escimm (findstr `) escimm (repstr `) next)


# miscellaneous

map `c-g'    `escimm `goto ''
map `c-k'    `remeol'
map `tab'    `tab'
map `s-tab'  `backtab'


insertmode on
savetabs on
tabstop 3
pageset 96


# this macro is required for the del-key and bs-key definitions; if you use this macro in your .edrc file, be sure to change the pathname to that of the directory containing your copy of the join macro

execute `copy "Macro Disk:s/join.edrc"   ram:'

