home *** CD-ROM | disk | FTP | other *** search
/ Tools en Utilities / CDASS_5.ISO / shell / file / auror200.arj / EXT.AML < prev    next >
Encoding:
Text File  |  1995-01-26  |  71.4 KB  |  2,793 lines

  1.  
  2. // ───────────────────────────────────────────────────────────────────
  3. // The Aurora Editor v2.0
  4. // Copyright 1993-1995 nuText Systems. All Rights Reserved Worldwide.
  5. //
  6. // Editor library extensions (included by MAIN.AML)
  7. //
  8. // *You should be very familiar with AML before making changes here*
  9. // If you have made any changes, save this file and select 'Recompile
  10. // the Editor' <alt f2> from the Set menu. Exit and re-enter the
  11. // editor for your changes to take effect.
  12. // ───────────────────────────────────────────────────────────────────
  13.  
  14. // ───────────────────────────────────────────────────────────────────
  15. //  All windows
  16. // ───────────────────────────────────────────────────────────────────
  17.  
  18.   object  a
  19.  
  20.     // get the drive and path portion of a filespec
  21.     function  getpath (file)
  22.       return  file [1 : pos "\\" file 'r']
  23.     end
  24.  
  25.     // get the name and extension portion of a filespec
  26.     function  getname (file)
  27.       return  file [(pos "\\" file 'r') + 1 : 0]
  28.     end
  29.  
  30.     // get the extension portion of a filespec
  31.     function  getext (file)
  32.       p = pos '.' file 'r'
  33.       if? p file [p : TO_END]
  34.     end
  35.  
  36.     // append a default extension for filenames that don't have one
  37.     function  defext (file extension)
  38.       if pos '.' file then
  39.         file
  40.       else
  41.         file + '.' + extension
  42.       end
  43.     end
  44.  
  45.     // force a filename to have an extension
  46.     function  forceext (file ext)
  47.       p = pos '.' file 'r'
  48.       return (if? p  file [1 : p]  file + '.') + ext
  49.     end
  50.  
  51.     // generate <shiftdown>, <shiftup> events from raw <shiftkey> event
  52.     function  <shiftkey> (newstate oldstate)
  53.       send ( if newstate & 3 and not (oldstate & 3) then
  54.                "shiftdown"
  55.              elseif oldstate & 3 and not (newstate & 3) then
  56.                "shiftup"
  57.              end )
  58.     end
  59.  
  60.     // generate multi-key events
  61.     function  prefix (keycode)
  62.       keyname = locase (getkeyname keycode)
  63.       say  keyname + "<more...>"
  64.       keyname2 = locase (getkeyname (getkey))
  65.       queue  keyname + keyname2
  66.       // allow the <ctrl> key to be held down...
  67.       if keyname  [1:5] == "<ctrl" and keyname2 [1:5] == "<ctrl" then
  68.         queue   keyname + '<' + keyname2 [7 : TO_END]
  69.       end
  70.       display
  71.     end
  72.  
  73.     // repeat keys for a user-specified number of times
  74.     function  askrepkey
  75.       var keystring
  76.       var i
  77.       say "Enter keys to repeat, then <esc>:"
  78.       hidecursor
  79.       keycode = getkey
  80.       while keycode <> <esc> do
  81.         keystring = keystring + (char2 keycode)
  82.         keycode = getkey
  83.       end
  84.       if keystring then
  85.         count = ask "Number of repetitions"
  86.         if count then
  87.           strlen = sizeof keystring
  88.           while count do
  89.             j = 1
  90.             while j < strlen do
  91.               queuekey (bin2int keystring [j : 2])
  92.               j = j + 2
  93.             end
  94.             repeat
  95.               dispatch
  96.             until not event?
  97.             count = count - 1
  98.           end
  99.         end
  100.       end
  101.     end
  102.  
  103.     // a simple file picklist
  104.     function  picklist (filespec title)
  105.       filespec = qualify filespec (getbufname)
  106.       repeat
  107.         filespec = askfile filespec  filespec + title _FmgrSort _FmgrOpt
  108.       until not (filespec and (dir? filespec))
  109.       return filespec
  110.     end
  111.  
  112.     // execute a fully qualified DOS program
  113.     // (saving and restoring the current path)
  114.     function  os (program options)
  115.       cp = getcurrpath
  116.       currpath (getpath (getbufname))
  117.       r = exec program options
  118.       currpath cp
  119.       return r
  120.     end
  121.  
  122.     // shell to DOS by executing COMMAND.COM
  123.     function  shell
  124.       os (getenv "COMSPEC") "ch"
  125.     end
  126.  
  127.     // execute DOS commands, programs, and .bat files
  128.     function  run (file options)
  129.       if file then
  130.         os (getenv "COMSPEC") + " /c " + file  options
  131.       else
  132.         shell
  133.       end
  134.     end
  135.  
  136.     // execute DOS commands or programs and capture the output
  137.     // via DOS piping (will not capture .bat file output)
  138.     function  runcap (command options)
  139.       _cap = _cap + 1
  140.       capfile = qualify  "capture." + _cap  (getbufname)
  141.       run  command + '>' + capfile  options
  142.       open capfile
  143.       deletefile capfile
  144.     end
  145.  
  146.     // translate an AML compiler error code to an error message
  147.     function  errormsg (error)
  148.       case error
  149.         when 1001  "Can't open file"
  150.         when 1002, 1003  "Read error"
  151.         when 1004  "Not an executable macro file"
  152.         when 1031  "Write error"
  153.         when 1032  "Can't open compiler output file"
  154.         when 1101  "No closing quote"
  155.         when 1102  "No closing bracket"
  156.         when 1103  "Invalid symbol"
  157.         when 1104  "Invalid key or event"
  158.         when 1301  "No terminator"
  159.         when 1302  "Unexpected end of source"
  160.         when 1303  "No closing parenthesis"
  161.         when 1310  "Unexpected argument"
  162.         when 1311  "Unexpected terminator"
  163.         when 1312  "Unexpected function"
  164.         when 1313  "Unexpected operator"
  165.         when 1319  "Identifier '" + (geterror 's') + "' not defined"
  166.         when 1320  "Bad assignment"
  167.         when 1330  "Bad when clause"
  168.         when 1336  "Improperly placed break"
  169.         when 1337  "Invalid reference"
  170.         when 1501  "Can't open include file " + (geterror 's')
  171.         when 1502  "Include level exceeded"
  172.         when 1503  "Can't include compiled file in expression"
  173.         when 1504  "Include must be at top level"
  174.         when 1505  "Define can't be nested"
  175.         when 1506  "Function must be at top level"
  176.         when 1507  "Can't redefine builtin function"
  177.         when 1508  "Duplicated function argument"
  178.         when 1509  "Object statement not permitted"
  179.         when 1701  "Too many variables"
  180.         when 1702  "Too many function arguments"
  181.         when 1703  "Function or expression too large"
  182.         when 1704, 1705, 1707   "Internal stack overflow"
  183.         when 1706  "Out of symbol space"
  184.         otherwise "Fatal compilation error " + error
  185.       end
  186.     end
  187.  
  188.     // compile a macro with error messages
  189.     // the cursor is moved to any syntax errors
  190.     function  compilemacro2 (source dest msg)
  191.       if not source then
  192.         source = getbufname
  193.       end
  194.       say (if? msg msg "Compiling...")
  195.       source = qualify (defext source "aml") (getbufname)
  196.       error = compilemacro source (if? dest dest (forceext source 'x'))
  197.  
  198.       if error then
  199.  
  200.         // get additional error info
  201.         column = geterror 'k'
  202.         line = geterror 'l'
  203.         file = geterror 'f'
  204.  
  205.         // translate error code to an error message
  206.         msg = errormsg error
  207.  
  208.         // position the cursor to the error
  209.         if error <> 1001 and (open file) then
  210.           gotopos column line
  211.           send "onfound"
  212.         end
  213.  
  214.         // display the error
  215.         msgbox  file + " (line " + line + ", col " + column + "): " + msg
  216.                 "Error!" 'b'
  217.       else
  218.         say "Done."
  219.       end
  220.  
  221.       return error
  222.     end
  223.  
  224.     // regenerate the editor boot macro (a.x)
  225.     function  regen (msg)
  226.       dest = bootpath "main.x"
  227.       error = compilemacro2 (bootpath "main.aml") dest msg
  228.       if not error then
  229.         bootfile = bootpath "a.x"
  230.         deletefile bootfile
  231.         renamefile dest bootfile
  232.       end
  233.       return error
  234.     end
  235.  
  236.     // regenerate the editor boot macro (a.x) with a message
  237.     function  recompile
  238.       if not regen then
  239.         msgbox "Exit and re-enter for changes to take effect. "
  240.       end
  241.     end
  242.  
  243.     // regenerate the editor boot macro (a.x) with a message,
  244.     // and integrate current config variables in compilation
  245.     function  saveconfig
  246.       configx = bootpath "config.x"
  247.       saveobject "prf" configx
  248.       regen "Saving..."
  249.       deletefile configx
  250.     end
  251.  
  252.     // load and run a compiled macro file
  253.     function  includemacro2 (macrofile)
  254.       includemacro (qualify (forceext
  255.                  (if? macrofile macrofile (getbufname)) 'x') (getbufname))
  256.     end
  257.  
  258.     // load, run, and discard a compiled macro file
  259.     function  runmacro2 (macrofile)
  260.       runmacro (qualify (forceext
  261.                  (if? macrofile macrofile (getbufname)) 'x') (getbufname))
  262.     end
  263.  
  264.     // send a string to the default printer device
  265.     function  printstr (string)
  266.       if string then
  267.         fileid = openfile _PrtDev 'w'
  268.         if fileid then
  269.           writefile fileid string
  270.           closefile fileid
  271.         end
  272.       end
  273.     end
  274.  
  275.     // open a new file
  276.     function  opennew (file options)
  277.       prevbufname = getbufname
  278.       buffer = createbuf
  279.       if buffer then
  280.         setbufname (qualify (if? file file "NEW.TXT") prevbufname)
  281.         openbuf buffer options
  282.       end
  283.     end
  284.  
  285.     // toggle the video mode between 80x25 and 80x50
  286.     function  togglemode
  287.       videomode 80 (if? getvidrows == 25  50 25)
  288.     end
  289.  
  290.  
  291.     // search/replace with verification
  292.     // (returns the number of replacements made)
  293.     function  replver (searchstr replstr options)
  294.  
  295.       var title
  296.       var count
  297.  
  298.       repeat
  299.         length = find searchstr options
  300.         if length then
  301.  
  302.           if not title then
  303.             title = gettitle
  304.             settitle  "Replace (Yes/No/All/One/Reverse/Undo/Quit)? "
  305.             // remove global for next find
  306.             options = sub 'g' '' options
  307.           end
  308.  
  309.           send "onfound" length
  310.  
  311.           // get keycode and convert to lower case
  312.           p = getkey | 020h
  313.           case p
  314.  
  315.             when <y>, <o>, <a>
  316.               undobegin
  317.               l = (replace searchstr replstr  (sub 'r' '' options) + "*z") - 1
  318.               if not (pos 'r' options) then
  319.                 right l
  320.               end
  321.               count = count + 1
  322.               if p <> <y> then
  323.                 length = ''
  324.                 if p == <a> then
  325.                   count = count + (replace searchstr replstr  options + "az")
  326.                 end
  327.               end
  328.               undoend
  329.  
  330.             when <u>
  331.               if count then
  332.                 undo
  333.                 count = count - 1
  334.                 if pos 'r' options then
  335.                   right 1
  336.                 else
  337.                   if getcol == 1 then
  338.                     if up then
  339.                       col 16000
  340.                     end
  341.                   else
  342.                     left l
  343.                   end
  344.                 end
  345.               end
  346.  
  347.             when <n>
  348.                // do nothing
  349.  
  350.             when <r>
  351.                options = if? (pos 'r' options) (sub 'r' '' options)  options + 'r'
  352.  
  353.             otherwise
  354.               if not count then
  355.                 count = '0'
  356.               end
  357.               break
  358.           end
  359.         end
  360.       until not length
  361.  
  362.       if title then
  363.         settitle title
  364.       end
  365.  
  366.       return count
  367.     end
  368.  
  369.  
  370.     // search for a multi-string search argument
  371.     function  search (searchstr reverse rep refopt refrepl)
  372.  
  373.       var replstr
  374.       var options
  375.  
  376.       // split up search multi-string
  377.       if pos '/' searchstr then
  378.         n = splitstr '' searchstr  ref searchstr  ref replstr  ref options
  379.         if n > 1 then
  380.           if n == 2 then
  381.             options = replstr
  382.             replstr = ''
  383.             // case sensitive
  384.             if not options then
  385.               options = 'c'
  386.             end
  387.           end
  388.         end
  389.       end
  390.  
  391.       if searchstr then
  392.  
  393.         // default options
  394.         if not options then
  395.           options = _SearchOpt
  396.           if n > 2 then
  397.             options = options + _ReplaceOpt
  398.           end
  399.         end
  400.  
  401.         // reverse search direction if specified
  402.         if reverse then
  403.           options = if pos 'r' options then
  404.                       sub 'r' '' options
  405.                     else
  406.                       options + 'r'
  407.                     end
  408.         end
  409.  
  410.         // remove global for repeat find
  411.         if rep and (pos 'g' options) then
  412.           options = sub 'g' '' options
  413.         end
  414.  
  415.         // return values for calling function to check
  416.         refopt  = options
  417.         refrepl = n >= 3
  418.  
  419.         // resurface marked window for block search
  420.         if pos 'b' options then
  421.           buffer = getmarkbuf
  422.           if buffer and buffer <> getcurrbuf then
  423.             currwin (getcurswin (getcurrcurs buffer))
  424.           end
  425.         end
  426.  
  427.         // search and replace
  428.         if n >= 3 then
  429.  
  430.           // do the replace
  431.           if pos 'a' options then
  432.             replace searchstr replstr options
  433.           else
  434.             replver searchstr replstr options
  435.           end
  436.  
  437.         // search only
  438.         else
  439.           find searchstr options
  440.         end
  441.       end
  442.     end
  443.  
  444.     // hot key for file mgr and file picklists
  445.     function onhotkey (character)
  446.       searchstr = '^[~]' + (upcase character)
  447.       if find searchstr 'x' then
  448.         adjustrow getviewrows / 3
  449.         return
  450.       else
  451.         line = getrow
  452.         gotopos 1 1
  453.         if find searchstr 'x' then
  454.           adjustrow getviewrows / 3
  455.           return
  456.         end
  457.         // not found
  458.         beep 320 70
  459.         row line
  460.       end
  461.     end
  462.  
  463.  
  464.   object  mon
  465.  
  466.     // erase key macros
  467.     function  erasekey2 (options)
  468.       if erasekey options then
  469.         _kd = TRUE
  470.         display
  471.         say (if? (pos options 'a') "All keys macros erased"
  472.                                    "Scrap key macro erased")
  473.       end
  474.     end
  475.  
  476.     // toggle the key macro record mode
  477.     function  record
  478.       if not playing? then
  479.         _kd = TRUE
  480.         if not setting? 'R' then
  481.           erasekey
  482.           record_on = TRUE
  483.         end
  484.         setting 'R' TOGGLE
  485.         say "Record" + (if? record_on "ing..." " OFF")
  486.       end
  487.     end
  488.  
  489.     // play a key macro
  490.     function  play (keymacro)
  491.       setdisplay OFF
  492.       if not (playkey keymacro) then
  493.         say "No key macro to play." 'b'
  494.       end
  495.       setdisplay ON
  496.     end
  497.  
  498.  
  499. // ───────────────────────────────────────────────────────────────────
  500. //  Edit windows and File Manager windows
  501. // ───────────────────────────────────────────────────────────────────
  502.  
  503.   object  edit_fmgr
  504.  
  505.     // close all windows
  506.     function  closeall (options)
  507.       setxobj "__G" ON 'a'
  508.       begdesk
  509.       while getwincount and (send "close" options) end
  510.       enddesk
  511.       setxobj "__G" OFF 'a'
  512.     end
  513.  
  514.     // move the cursor to any edge of a mark
  515.     function  gotomark (options)
  516.       if mark? then
  517.  
  518.         window = getcurswin (getcurrcurs (getmarkbuf))
  519.         if window then
  520.           currwin window
  521.         end
  522.  
  523.         // left or right
  524.         if pos 'l' options then
  525.           col (getmarkleft)
  526.         elseif pos 'r' options then
  527.           col (getmarkright)
  528.         end
  529.  
  530.         // top or bottom
  531.         if pos 't' options then
  532.           row (getmarktop)
  533.         elseif pos 'b' options then
  534.           row (getmarkbot)
  535.         end
  536.  
  537.         if window then
  538.           send "onfound"
  539.         end
  540.  
  541.       else
  542.         say "Block not found" 'b'
  543.       end
  544.     end
  545.  
  546.     // goto a bookmark with message
  547.     function  gotobook2 (bookmark)
  548.       msg = "Bookmark '" + bookmark + "'"
  549.       if gotobook bookmark then
  550.         window = getcurswin (getcurrcurs (getbookbuf bookmark))
  551.         if window <> getcurrwin then
  552.           currwin window
  553.         end
  554.         display
  555.         say msg
  556.       else
  557.         say msg + " not found"  'b'
  558.       end
  559.     end
  560.  
  561.     // prompt to goto a bookmark
  562.     function  askbook (msg)
  563.       askx (if? msg msg "Bookmark Name") "_book" "gotobook2"
  564.     end
  565.  
  566.     // cycle though all existing bookmarks
  567.     function  cyclebook
  568.       repeat
  569.         l = _lb
  570.         bookmark = if? l (getprevbook l) (getcurrbook)
  571.         buffer = getcurrbuf
  572.         while not bookmark and buffer do
  573.           buffer = getprevbuf buffer
  574.           bookmark = getcurrbook buffer
  575.         end
  576.         _lb = bookmark
  577.       until bookmark or not l
  578.       gotobook2 bookmark
  579.     end
  580.  
  581.     // print the current buffer or mark
  582.     function  print (options)
  583.       printstr _PrtIni
  584.       header = _PrtHdr
  585.       if not (posnot ' ' header) or (dir? (getbufname)) then
  586.         date = getdate
  587.         header = getbufname + "   (" + date [posnot ' ' date : TO_END] +
  588.                                  ' ' + gettime + ')'
  589.       end
  590.       if not ( if pos 'b' options  then printblock _PrtDev header ''
  591.                 else    printbuf _PrtDev header end ) then
  592.         say "Print failed" 'b'
  593.       end
  594.     end
  595.  
  596.     // replace/append/cancel or ok/cancel menus
  597.     function  askrac (file menuname)
  598.       if _ConRpl == 'y' and (locatefile file) then
  599.         locase (popup (if? menuname menuname "rac" )
  600.                         file + " Exists" +
  601.                         (if? menuname == "ok" ". Replace?")) [1]
  602.       else
  603.         'r'
  604.       end
  605.     end
  606.  
  607.     // generic prompt to change a configuration variable
  608.     function  askc (pstring variable history)
  609.       newvalue = ask pstring history (lookup variable "prf")
  610.       if newvalue then
  611.         setxobj variable newvalue "prf"
  612.       end
  613.     end
  614.  
  615.     // prompts to change specific configuration variables
  616.     function  askbinary  askc "Binary Line Length"  "BinaryLength"     end
  617.     function  askdelim   askc "Line Delimiter String in Hex" "LineDlm" end
  618.     function  asktabw    askc "Tab Width"      "TabWidth"    end
  619.     function  asktabv    askc "Variable Tabs"  "VarTabs"     end
  620.     function  asklmarg   askc "Left Margin"    "LMargin"     end
  621.     function  askrmarg   askc "Right Margin"   "RMargin"     end
  622.     function  askclip    askc "Clipboard Name" "ClipName"    end
  623.     function  askprthdr  askc "Current Header/Footer" "PrtHdr" end
  624.  
  625.     // generic prompt with command execution
  626.     function  askx (pstring history func parm2)
  627.       parm1 = ask pstring history
  628.       if parm1 then
  629.         send func parm1 parm2
  630.         if history then
  631.           addhistory history parm1
  632.         end
  633.         return 1
  634.       end
  635.     end
  636.  
  637.     // open prompt
  638.     function  askopen
  639.       file = ask "[file/ibcenz] Open" "_load"
  640.       if file then
  641.         // addhistory not needed for open
  642.         open file
  643.       end
  644.     end
  645.  
  646.     // open binary prompt
  647.     function  askopenb
  648.       askx "File to open in Binary Mode" "_load" "open" 'b'
  649.     end
  650.  
  651.     // macro expression prompt
  652.     function  askeval
  653.       if askx "Macro Expression" "_cmd" "eval" then
  654.         error = geterror 'c'
  655.         if error then
  656.           msgbox "Expression column " + (geterror 'k') +
  657.                  ": " + (errormsg error)  "Error" 'b'
  658.         end
  659.       end
  660.     end
  661.  
  662.     // prompt to include a macro
  663.     function  askimacro
  664.       askx "Include Macro File"  "_load" "includemacro2"
  665.     end
  666.  
  667.     // prompt to run a macro
  668.     function  askrmacro
  669.       askx "Run Macro File"  "_load" "runmacro2"
  670.     end
  671.  
  672.     // prompt to compile a macro
  673.     function  askcmacro
  674.       askx "Compile Macro File"  "_load" "compilemacro2"
  675.     end
  676.  
  677.     // macro picklist
  678.     function  pickmacro
  679.       macro = askfile getbootpath + "MACRO\\*.X" "Select a macro to run"
  680.                       _FmgrSort _FmgrOpt "maclist"
  681.       if macro then
  682.         runmacro macro
  683.       end
  684.     end
  685.  
  686.     // DOS command prompt
  687.     function  askrun
  688.       askx "DOS Command" "_os" "run" "ck"
  689.     end
  690.  
  691.     // prompt to capture DOS output
  692.     function  askruncap
  693.       askx "Capture DOS Output" "_os" "runcap" 'c'
  694.     end
  695.  
  696.     // open key macro file with messages
  697.     function  openkey2 (file)
  698.       if openkey file then
  699.         say (getname file) + " loaded"
  700.       else
  701.         say "Load failed" 'b'
  702.       end
  703.     end
  704.  
  705.     // prompt to open a key macro file
  706.     function  askopenkey
  707.       file = ask "Key macro filename" "_load"
  708.       if file then
  709.         openkey2 (qualify (defext file "mac") (getbufname))
  710.       end
  711.     end
  712.  
  713.     // prompt to save current key macros
  714.     function  asksavekey
  715.       file = ask "Save current key macros as" "_load"
  716.       if file then
  717.         file = qualify (defext file "mac") (getbufname)
  718.         if pos (askrac file "ok") "or" 'i' then
  719.           if not savekey file then
  720.             say "Save failed" 'b'
  721.           end
  722.         end
  723.       end
  724.     end
  725.  
  726.     // search files for a string in multi-string format with msgs
  727.     function  searchfiles (s)
  728.       var searchstr
  729.       var filespec
  730.       var options
  731.       n = splitstr '' s  ref searchstr  ref filespec  ref options
  732.       if n < 3 then
  733.         options = _SearchOpt
  734.         if n < 2 then
  735.           filespec = '.'
  736.         end
  737.       end
  738.       if searchstr then
  739.         r = scanfiles filespec searchstr options
  740.         if r <= 0 then
  741.           say (if? r filespec s) + " not found" 'b'
  742.         else
  743.           addhistory "_find" (joinstr '' searchstr options)
  744.         end
  745.       end
  746.     end
  747.  
  748.     // prompt to scan files for a string
  749.     function  askscan
  750.       scanstring = if _PromptStyle == 'd' then
  751.                      scandlg
  752.                    else
  753.                      ask "[string/files/iwx] Scan" "_scan"
  754.                    end
  755.       if scanstring then
  756.         searchfiles scanstring
  757.         addhistory "_scan" scanstring
  758.       end
  759.     end
  760.  
  761.     // reload the current file from disk
  762.     function  reopen (file)
  763.       open (if? file file getbufname) 'r'
  764.     end
  765.  
  766.     // open last file or directory
  767.     function  openlast
  768.       file = gethiststr "_load"
  769.       if file then
  770.         open file
  771.       end
  772.     end
  773.  
  774.     // open an AML configuration file in boot directory
  775.     function  opencfg (file)
  776.       open (bootpath  file + ".aml")
  777.     end
  778.  
  779.     // quick reference help
  780.     function  quickref (options openopt)
  781.       quickfile = getbootpath + (if? options <> 'o' "DOC\\") +
  782.                     case options [1]
  783.                       when 'l'  "LANGUAGE.DOX"
  784.                       when 'f'  "FUNCTION.DOX"
  785.                       when 'q'  "QUICKFUN.DOX"
  786.                       when 'o'  "ORDERFRM.DOC"
  787.                       when 't'  "TIPS.DOX"
  788.                       otherwise "USER.DOX"
  789.                     end
  790.       if (wintype? "edit") and (pos 'w' options) then
  791.         wordstr = send "getword" "a-zA-Z0-9?"
  792.       end
  793.       open quickfile openopt
  794.       if wordstr then
  795.         gotopos 1 1
  796.         // find string in reference
  797.         if find (char 0ffh) + wordstr + (char 0ffh) then
  798.           right
  799.           send "onfound" (sizeof wordstr)
  800.         // not found? then try function header in EXT.AML
  801.         elseif poschar 'fq' options then
  802.           close
  803.           ext = bootpath "EXT.AML"
  804.           closeit = _MultCopy == 'n' and not (findbuf ext)
  805.           open ext openopt
  806.           gotopos 1 1
  807.           n = find "function #" + wordstr  'x'
  808.           if n then
  809.             send "onfound" n
  810.           // still not found? then go back to reference
  811.           else
  812.             if closeit then
  813.               close
  814.             end
  815.             open quickfile openopt
  816.           end
  817.         end
  818.       end
  819.     end
  820.  
  821.     // popup menu to change the default prompt style
  822.     function  askprompt
  823.       menu "prompts"
  824.         item " &Command line" 1
  825.         item " &One-line box" 2
  826.         item " &Two-line box" 3
  827.         item " &Dialog box"   4
  828.       end
  829.       newtype = popup (getcurrbuf) "Select a Prompt Style" 25
  830.       if newtype then
  831.         setobj _PromptStyle "c12d" [newtype] "prf"
  832.       end
  833.       destroybuf "prompts"
  834.     end
  835.  
  836.  
  837. // ───────────────────────────────────────────────────────────────────
  838. //  Prompts and Edit windows
  839. // ───────────────────────────────────────────────────────────────────
  840.  
  841.   object  prompt
  842.  
  843.     // support for cua-style <shift> key marking
  844.     function  smark
  845.       if shiftkey? then
  846.         if _shfx then
  847.           undobegin
  848.           destroymark
  849.           markstream _shfx _shfx _shfy _shfy
  850.           _shfx = ''
  851.           _shfy = ''
  852.         end
  853.         extendmark
  854.       end
  855.     end
  856.  
  857.     // set anchor for shift-key marking
  858.     function  shiftdown
  859.       _shfx = getcol
  860.       _shfy = getrow
  861.       pass
  862.     end
  863.  
  864.     // end shift-key mark
  865.     function  shiftup
  866.       stopmark
  867.       pass
  868.       undoend
  869.     end
  870.  
  871.     // backspace in a prompt
  872.     function  backsp
  873.       if getcol > 1 then
  874.         left
  875.         delchar
  876.       end
  877.     end
  878.  
  879.     // get the word at the cursor
  880.     function  getword (charset column mark)
  881.       if not column then
  882.         column = getcol
  883.       end
  884.       if column <= getlinelen then
  885.         if not charset then
  886.           charset = _CSet
  887.         end
  888.         b = posnot charset (gettext column)
  889.         if b <> 1 then
  890.           b = if? b  column + b - 2  getlinelen
  891.           a = posnot charset (gettext 1 column) 'r'
  892.           a = if? a  a + 1  1
  893.           if mark then
  894.             undobegin
  895.             destroymark
  896.             markchar a b
  897.             undoend
  898.           else
  899.             gettext a  b - a + 1
  900.           end
  901.         end
  902.       end
  903.     end
  904.  
  905.     // mark the word at the cursor using getword
  906.     function  markword (charset)
  907.       getword charset '' 1
  908.     end
  909.  
  910.     // mark to end-of-line
  911.     function  markeol
  912.       undobegin
  913.       destroymark
  914.       if getcol <= getlinelen then
  915.         markchar (getcol) (getlinelen)
  916.       end
  917.       undoend
  918.     end
  919.  
  920.     // delete a block
  921.     function  deleteblock2
  922.       if getmarkbuf == getcurrbuf then
  923.         deleteblock
  924.       else
  925.         if wintype? "edit" then
  926.           if _DelLine == 'y' then
  927.             delline
  928.           end
  929.         end
  930.       end
  931.     end
  932.  
  933.     // prompt to enter character literally
  934.     function  literal
  935.       say "Enter Literal..."
  936.       queue <char> (char getkey & 0ffh)
  937.     end
  938.  
  939.     // ascii chart with character entry
  940.     function  asciilist
  941.       buffer = asciibuf
  942.       // name it so the position can be remembered
  943.       setbufname "_asc"
  944.       character = (popup buffer '' 13) [10]
  945.       destroybuf
  946.       if character then
  947.         queue <char> character
  948.       end
  949.     end
  950.  
  951.     // support for file name completion (open prompts only)
  952.     function  askcomplete
  953.       if gethistname == "_load" then
  954.         filespec = gettext
  955.         if filespec then
  956.           if not pos "*.*" filespec then
  957.             filespec = filespec + (if? (pos '.' filespec) '*' "*.*")
  958.           end
  959.         else
  960.           filespec = "*.*"
  961.         end
  962.         file = picklist (qualify filespec (getbufname (getwinbuf (getprevwin))))
  963.         if file then
  964.           col 1
  965.           delchar (getlinelen)
  966.           writetext file
  967.           return file
  968.         end
  969.       end
  970.     end
  971.  
  972.     // get the first line of text in the default mark
  973.     function  getmarktext
  974.       if mark? then
  975.         buffer = getmarkbuf
  976.         topline = getmarktop
  977.         if getmarktype == 'l' then
  978.           gettext (getlinebeg topline buffer) (getlinelen topline buffer)
  979.                   (getmarktop) buffer
  980.         else
  981.           gettext (getmarkleft) (getmarkcols) topline buffer
  982.         end
  983.       end
  984.     end
  985.  
  986.     // copy or copy-append to the clipboard
  987.     function  copy (options)
  988.  
  989.       if mark? then
  990.         currentbuf = getcurrbuf
  991.  
  992.         clip = _ClipName
  993.         destroymark clip
  994.         copymark (getmarkuse) clip
  995.  
  996.         // copy
  997.         if options and (buffer? clip) then
  998.           if getmarktype <> 'l' then
  999.             insline '' '' (getlines clip) clip
  1000.           end
  1001.           copyblock clip clip 1 (getlines clip)
  1002.           markline 1 (getlines clip) clip clip
  1003.  
  1004.         // copy append
  1005.         else
  1006.           destroybuf clip
  1007.           createbuf clip
  1008.           copyblock clip clip
  1009.           if getmarktype == 'l' then
  1010.             delline 1 1 clip
  1011.           end
  1012.         end
  1013.         currbuf currentbuf
  1014.       end
  1015.     end
  1016.  
  1017.     // cut or cut-append to the clipboard
  1018.     function  cut (options)
  1019.       if mark? then
  1020.         copy options
  1021.         deleteblock
  1022.       end
  1023.     end
  1024.  
  1025.     // enter a character or string into the current prompt
  1026.     function  write (charstring)
  1027.       writetext charstring
  1028.     end
  1029.  
  1030.  
  1031. // ───────────────────────────────────────────────────────────────────
  1032. //  Edit windows
  1033. // ───────────────────────────────────────────────────────────────────
  1034.  
  1035.   object  edit
  1036.  
  1037.     // mark a paragraph
  1038.     function  markpara
  1039.  
  1040.       if getlinelen then
  1041.  
  1042.         undobegin
  1043.         destroymark
  1044.  
  1045.         // find the beginning of the paragraph
  1046.         pushcursor
  1047.         while up and getlinelen end
  1048.         if not getlinelen then
  1049.           down
  1050.         end
  1051.         markline
  1052.         popcursor
  1053.  
  1054.         // find the end of the paragraph
  1055.         pushcursor
  1056.         while down and getlinelen end
  1057.         if not getlinelen then
  1058.           up
  1059.         end
  1060.         markline
  1061.         popcursor
  1062.  
  1063.         undoend
  1064.  
  1065.         return 1
  1066.       end
  1067.     end
  1068.  
  1069.     // setup for insert-above (copy, move, paste - lineblocks only)
  1070.     function  begabove
  1071.       _ba = ''
  1072.       undobegin
  1073.       if _InsAbove == 'y' and getmarktype == 'l' then
  1074.         _ba = 1
  1075.         if not up then
  1076.           insabove
  1077.           _ba = 2
  1078.         end
  1079.       end
  1080.     end
  1081.  
  1082.     // end insert-above
  1083.     function  endabove
  1084.       case _ba
  1085.         when 1 down
  1086.         when 2 delline
  1087.       end
  1088.       undoend
  1089.     end
  1090.  
  1091.     // paste or paste-over from the clipboard
  1092.     function  paste (options)
  1093.       if mark? _ClipName then
  1094.         destroymark
  1095.         copymark _ClipName (getmarkuse)
  1096.         if options then
  1097.           copyblockover
  1098.         else
  1099.           begabove
  1100.           copyblock
  1101.           endabove
  1102.         end
  1103.       else
  1104.         say "Nothing to paste" 'b'
  1105.       end
  1106.     end
  1107.  
  1108.     // clear the clipboard
  1109.     function  clear
  1110.       destroybuf _ClipName
  1111.     end
  1112.  
  1113.     // copy a block
  1114.     function  copyblock2
  1115.       if mark? then
  1116.         begabove
  1117.         if not copyblock then
  1118.           say "Copy failed" 'b'
  1119.         end
  1120.         endabove
  1121.       else
  1122.         if _CopyLine == 'y' then
  1123.           undobegin
  1124.           markline
  1125.           copyblock
  1126.           destroymark
  1127.           undoend
  1128.         end
  1129.       end
  1130.     end
  1131.  
  1132.     // move a block
  1133.     function  moveblock2
  1134.       begabove
  1135.       if getmarktop < getviewtop then
  1136.         y = 1 + getrow - (apparentrow  getviewtop - getrow)
  1137.       end
  1138.       if moveblock then
  1139.         if y then
  1140.           adjustrow y
  1141.         end
  1142.       else
  1143.         say "Move failed" 'b'
  1144.       end
  1145.       endabove
  1146.     end
  1147.  
  1148.     // move a block over text
  1149.     function  moveblockover
  1150.       if mark? then
  1151.         undobegin
  1152.         copy
  1153.         fillblock ' '
  1154.         paste 'o'
  1155.         undoend
  1156.       end
  1157.     end
  1158.  
  1159.     // reformat a block or the current paragraph
  1160.     function  formatblock2 (options)
  1161.       undobegin
  1162.       if not mark? then
  1163.         if markpara "tb" then
  1164.           markcolumn (getcol) _RMargin (getmarktop) (getmarkbot)
  1165.           flag = ON
  1166.         end
  1167.       end
  1168.       // special case for single lines
  1169.       if getmarkrows == 1 and getcol < getlinebeg then
  1170.         delchar getlinebeg - getcol
  1171.       else
  1172.         formatblock _LMargin _RMargin options
  1173.       end
  1174.       if flag then
  1175.         destroymark
  1176.       end
  1177.       undoend
  1178.     end
  1179.  
  1180.     // simple quoting support for a block or paragraph
  1181.     function  quote
  1182.       undobegin
  1183.       if not mark? then
  1184.         tempmark = TRUE
  1185.         markpara
  1186.       end
  1187.       if mark? then
  1188.         shiftblock 1 '' '>'
  1189.         if tempmark then
  1190.           destroymark
  1191.         end
  1192.       else
  1193.         say "Nothing to quote"
  1194.       end
  1195.       undoend
  1196.     end
  1197.  
  1198.     // sort a block
  1199.     function  sortblock2
  1200.       sortblock
  1201.         // scrollock ON=descending    // insert ON=ignore case
  1202.         (if? (shiftkey? 10h) 'd')  +  (if? (insert?) 'i')
  1203.  
  1204.     end
  1205.  
  1206.     // prompt to fill a block with a string
  1207.     function  fillblock2
  1208.       askx "Enter fill string" '' "fillblock"
  1209.     end
  1210.  
  1211.     // prompt to save a block
  1212.     function  saveblock2 (options)
  1213.       var c1
  1214.       var c2
  1215.       if mark? then
  1216.         file = ask "Save block as" "_load"
  1217.         if file then
  1218.           file = qualify file (getbufname)
  1219.           addhistory "_load" file
  1220.           if fileattr? file 'r' then
  1221.             say "Read Only!" 'b'
  1222.           else
  1223.             action = locase (askrac file)
  1224.             if pos action "ra" then
  1225.               send "oncomment" file ref c1 ref c2
  1226.               options = _SaveOpt + options
  1227.               if not saveblock file
  1228.                  (if? (pos 'e' options) 'e' + _TabWidth) + options +
  1229.                  (if? action == 'a' 'a')  ''
  1230.                  '' '' (if? c1 c1 + _FoldSign) c2 then
  1231.                 msgbox "Save Failed!" "Error!" 'b'
  1232.               end
  1233.             end
  1234.           end
  1235.         end
  1236.       else
  1237.         say "No marked block" 'b'
  1238.       end
  1239.     end
  1240.  
  1241.     // left justify, center, or right justify a block
  1242.     function  justblock2 (options)
  1243.       justblock options '' _LMargin _RMargin
  1244.     end
  1245.  
  1246.     // destroy open and closed folds
  1247.     function  destroyfold2
  1248.       undobegin
  1249.       if not fold? then
  1250.         closefold
  1251.       end
  1252.       destroyfold
  1253.       undoend
  1254.     end
  1255.  
  1256.     // do fold operations on entire file
  1257.     function  foldall (options)
  1258.       undobegin
  1259.       usemark 'T'
  1260.       markline 1 (getlines)
  1261.       foldblock options
  1262.       destroymark
  1263.       usemark
  1264.       undoend
  1265.     end
  1266.  
  1267.     // fold a block or the current paragraph
  1268.     function  foldblock2
  1269.       undobegin
  1270.       if mark? then
  1271.         foldblock
  1272.       elseif markpara then
  1273.         foldblock
  1274.         destroymark
  1275.       end
  1276.       undoend
  1277.     end
  1278.  
  1279.     // fold a block and destroy subfolds
  1280.     function  foldflat
  1281.       undobegin
  1282.       foldblock 'ds'
  1283.       foldblock
  1284.       undoend
  1285.     end
  1286.  
  1287.     // fold or unfold a line
  1288.     function  foldline (options)
  1289.       undobegin
  1290.       usemark 'T'
  1291.       markline
  1292.       unfold = pos 'u' options
  1293.       if fold? then
  1294.         foldblock 'd'
  1295.         if not unfold or getmarkrows > 1 then
  1296.           bottom = actualrow (if? unfold -1 1) (getmarkbot)
  1297.           if not (getfold 'o' bottom) then
  1298.             markline (getrow) bottom
  1299.           end
  1300.           foldblock
  1301.         end
  1302.       else
  1303.         if not unfold then
  1304.           foldblock
  1305.         end
  1306.       end
  1307.       destroymark
  1308.       usemark
  1309.       undoend
  1310.     end
  1311.  
  1312.     // detab or entab the current file
  1313.     // (+width=detab, -width=entab)
  1314.     function  tabfile (width)
  1315.       undobegin
  1316.       usemark 'T'
  1317.       markline 1 (getlines)
  1318.       tabblock (if? width width _TabWidth)
  1319.       destroymark
  1320.       usemark
  1321.       undoend
  1322.     end
  1323.  
  1324.     // insert a line after the current line with autoindent
  1325.     function  insline2
  1326.       undobegin
  1327.       insline
  1328.       if setting? 'A' then
  1329.         if getlinelen then
  1330.           col (getlinebeg)
  1331.         else
  1332.           nextline = getrow + 2
  1333.           if getlinelen nextline then
  1334.             col (getlinebeg nextline)
  1335.           end
  1336.         end
  1337.       end
  1338.       down
  1339.       undoend
  1340.     end
  1341.  
  1342.     // swap the current line with the next line
  1343.     function  swapline
  1344.       undobegin
  1345.       usemark 'T'
  1346.       markline
  1347.       stopmark
  1348.       down
  1349.       moveblock
  1350.       destroymark
  1351.       usemark
  1352.       undoend
  1353.     end
  1354.  
  1355.     // center the current line
  1356.     function  centerline
  1357.       undobegin
  1358.       usemark 'T'
  1359.       markline
  1360.       justblock 'c' '' _LMargin _RMargin
  1361.       destroymark
  1362.       usemark
  1363.       undoend
  1364.     end
  1365.  
  1366.     // comment or uncomment a line
  1367.     function  commentline (c1 c2)
  1368.       if not c1 then
  1369.         send "oncomment" (getbufname) ref c1 ref c2
  1370.         if not c1 then
  1371.           c1 = '>'
  1372.         end
  1373.       end
  1374.       undobegin
  1375.       column = getlinebeg
  1376.       if (gettext column (sizeof c1)) == c1 then
  1377.         delchar (sizeof c2) getlinelen - (sizeof c2) + 1
  1378.         delchar (sizeof c1) column
  1379.       elseif getlinelen then
  1380.         instext c1 (getlinebeg)
  1381.         if column then
  1382.           ovltext c2  getlinelen + 1
  1383.         end
  1384.       end
  1385.       down
  1386.       undoend
  1387.     end
  1388.  
  1389.     // find the previous word
  1390.     function  prevword
  1391.       while getcol > 1 and (poschar _CSet (getchar)) do
  1392.         left
  1393.       end
  1394.       find _CSet "[r"
  1395.       while getcol > 1 and (poschar _CSet (getchar getcol - 1)) do
  1396.         left
  1397.       end
  1398.     end
  1399.  
  1400.     // find the next word
  1401.     function  nextword
  1402.       while poschar _CSet (getchar) do
  1403.         right
  1404.       end
  1405.       find _CSet '['
  1406.     end
  1407.  
  1408.     // change the case of the word at the cursor
  1409.     function  caseword (options charset)
  1410.       undobegin
  1411.       usemark 'T'
  1412.       markword charset
  1413.       caseblock options
  1414.       destroymark
  1415.       usemark
  1416.       undoend
  1417.     end
  1418.  
  1419.     // open the filename at the cursor
  1420.     function  openword (charset)
  1421.       file = getword (if? charset charset _CSetB)
  1422.       if file then
  1423.         open file
  1424.       end
  1425.     end
  1426.  
  1427.     // delete the character at the cursor
  1428.     function  delchar2
  1429.       undobegin
  1430.       if getcol > getlinelen and _DelJoin == 'y' then
  1431.         joinline
  1432.       else
  1433.         delchar
  1434.         if setting? 'L' then
  1435.           livewrap
  1436.         end
  1437.       end
  1438.       undoend
  1439.     end
  1440.  
  1441.     // backspace
  1442.     function  backsp
  1443.       undobegin
  1444.       if getcol > 1 then
  1445.         left
  1446.         if not insert? and _BakOvl == 'y' then
  1447.           ovltext ' '
  1448.         else
  1449.           delchar
  1450.           if setting? 'L' then
  1451.             livewrap
  1452.           end
  1453.         end
  1454.       elseif getrow > 1 and _BakJoin == 'y' then
  1455.         up
  1456.         col getlinelen + 1
  1457.         joinline
  1458.       end
  1459.       undoend
  1460.     end
  1461.  
  1462.     // delete right word
  1463.     function  delword (charset)
  1464.       if not charset then
  1465.         charset = _CSet
  1466.       end
  1467.       undobegin
  1468.       if getcol > getlinelen then
  1469.         joinline
  1470.       else
  1471.         p = posnot charset (gettext (getcol))
  1472.         if p > 1 then
  1473.           delchar p - 1
  1474.         end
  1475.         delchar (
  1476.           if p then
  1477.             if getchar == ' ' and
  1478.                  (getcol == 1 or
  1479.                  (posnot charset (getchar getcol - 1))) then
  1480.               (posnot ' ' (gettext (getcol))) - 1
  1481.             else
  1482.               p == 1
  1483.             end
  1484.           else
  1485.             getlinelen
  1486.           end
  1487.         )
  1488.       end
  1489.       if setting? 'L' then
  1490.         livewrap
  1491.       end
  1492.       undoend
  1493.     end
  1494.  
  1495.     // splitline with autoindent
  1496.     function splitline2 (column)
  1497.       undobegin
  1498.       b = getlinebeg
  1499.       if splitline column then
  1500.         if not setting? 'A' then
  1501.           b = _LMargin
  1502.         end
  1503.         if b > 1 then
  1504.           pushcursor
  1505.           down
  1506.           usemark 'T'
  1507.           markline
  1508.           shiftblock (if? getcol > b  b  (getcol)) - 1
  1509.           destroymark
  1510.           usemark
  1511.           popcursor
  1512.         end
  1513.       end
  1514.       undoend
  1515.     end
  1516.  
  1517.     // <enter> key behavior
  1518.     function  enter
  1519.  
  1520.       // terminate a word for text translation
  1521.       lastrow = getrow
  1522.       if getcol == getlinelen + 1 and getlinelen then
  1523.         if setting? 'T' then
  1524.           send <char> ' '
  1525.         end
  1526.       end
  1527.  
  1528.       if getrow == lastrow then
  1529.         case (if? (insert?) _EnterIns _EnterOvl)
  1530.           when 'i'
  1531.             insline2
  1532.           when 's'
  1533.             if fold? then
  1534.               insline2
  1535.             else
  1536.               startcolumn = getlinebeg
  1537.               length = getlinelen
  1538.               splitline2
  1539.               down
  1540.               if setting? 'A' then
  1541.                 if length then
  1542.                   col startcolumn
  1543.                 end
  1544.               else
  1545.                 startcolumn = _LMargin
  1546.                 col (if? startcolumn startcolumn 1)
  1547.               end
  1548.             end
  1549.           otherwise
  1550.             down
  1551.             col (if? (getlinelen) (getlinebeg) _LMargin)
  1552.         end
  1553.       end
  1554.     end
  1555.  
  1556.     // for use by variable tab right
  1557.     function  vtabr
  1558.       i = 1
  1559.       while i <= arg do
  1560.         if (arg i) <= getcol then
  1561.           i = i + 1
  1562.         else
  1563.           return arg i
  1564.         end
  1565.       end
  1566.       return 0
  1567.     end
  1568.  
  1569.     // for use by variable tab left
  1570.     function  vtabl
  1571.       i = arg
  1572.       while i do
  1573.         if (arg i) >= getcol then
  1574.           i = i - 1
  1575.         else
  1576.           return arg i
  1577.         end
  1578.       end
  1579.       return 0
  1580.     end
  1581.  
  1582.     // tab support
  1583.     function  tabfunc (next)
  1584.  
  1585.       oldcolumn = getcol
  1586.  
  1587.       // smart tabs
  1588.       if setting? 'S' then
  1589.         prevline = getrow - 1
  1590.         while prevline and not (getlinelen prevline) do
  1591.           prevline = prevline - 1
  1592.         end
  1593.         if prevline then
  1594.           pushcursor
  1595.           row prevline
  1596.           send (if? next "nextword" "prevword")
  1597.           if prevline == getrow then
  1598.             newcolumn = getcol
  1599.           end
  1600.           popcursor
  1601.         end
  1602.       end
  1603.  
  1604.       // variable tabs
  1605.       if not newcolumn then
  1606.         if setting? 'V' then
  1607.           newcolumn = eval (if? next "vtabr " "vtabl ") + _VarTabs
  1608.         end
  1609.  
  1610.         // standard interval tabs
  1611.         if not newcolumn then
  1612.           width = _TabWidth
  1613.           if not width then
  1614.             width = 8
  1615.           end
  1616.           newcolumn = oldcolumn +
  1617.                         if next then
  1618.                           width - (oldcolumn - 1) mod width
  1619.                         elseif oldcolumn > 1 then
  1620.                           -((oldcolumn - 2) mod width + 1)
  1621.                         end
  1622.         end
  1623.       end
  1624.  
  1625.       // move to tabstop and shift text if needed
  1626.       if newcolumn then
  1627.         if _TabShift == 'y' and insert? then
  1628.           if newcolumn < oldcolumn then
  1629.             delchar  oldcolumn - newcolumn  newcolumn
  1630.           elseif newcolumn > oldcolumn then
  1631.             instext (copystr ' ' newcolumn - oldcolumn)
  1632.           end
  1633.         end
  1634.         col newcolumn
  1635.       end
  1636.     end
  1637.  
  1638.     // tab left and right
  1639.     function  tabright    tabfunc 1  end
  1640.     function  tableft     tabfunc    end
  1641.  
  1642.     // prompt to verify close
  1643.     function  close?
  1644.       if bufchanged? and not getprevcurs then
  1645.         savechanges = popup "ync"  "Save changes to " +
  1646.                                         (getname (getbufname)) + '?'
  1647.         if savechanges == "Yes" then
  1648.           save
  1649.         end
  1650.         icompare savechanges "Yes" "No"
  1651.       else
  1652.         1
  1653.       end
  1654.     end
  1655.  
  1656.     // close an edit window
  1657.     function  close (options)
  1658.       if pos 's' options then
  1659.         if save then
  1660.           pass
  1661.         end
  1662.       elseif close? then
  1663.         pass
  1664.       end
  1665.     end
  1666.  
  1667.     // open and insert prompt
  1668.     function  askinsert
  1669.       file = ask  "File to insert into " + (getname (getbufname)) "_load"
  1670.       if file then
  1671.         // addhistory not needed for open
  1672.         old_size = getlines
  1673.         undobegin
  1674.         open file 'i'
  1675.         // mark the inserted text
  1676.         if getlines > old_size then
  1677.           markline  getrow + 1  getrow + getlines - old_size
  1678.         end
  1679.         undoend
  1680.       end
  1681.     end
  1682.  
  1683.     // prompt to change the current file name
  1684.     function  askname
  1685.       newname = ask  "Rename " + (getname (getbufname)) + " to"  "_load"
  1686.       if newname then
  1687.         case setname newname
  1688.           when -1 say "Failed" 'b'
  1689.           when -2 say "Failed - file already loaded" 'b'
  1690.           otherwise
  1691.             addhistory "_load" (getbufname)
  1692.         end
  1693.       end
  1694.     end
  1695.  
  1696.     // search and replace with messages and highlighting
  1697.     function  search2 (search_str reverse again)
  1698.       var opt
  1699.       var rpl
  1700.       n = search search_str reverse again ref opt ref rpl
  1701.       if n then
  1702.         // replace occurred
  1703.         if rpl then
  1704.           display
  1705.           say (thousands n) + " changes made"
  1706.         // count occurrences
  1707.         elseif pos 'a' opt then
  1708.           display
  1709.           say (thousands n) + " occurrences of '" + search_str + "' found"
  1710.         // search only
  1711.         else
  1712.           onfound n
  1713.         end
  1714.       else
  1715.         display
  1716.         say "'" + search_str + "' not found"  'b'
  1717.       end
  1718.       return n
  1719.     end
  1720.  
  1721.     // find prompt
  1722.     function  askfind (reverse)
  1723.       search_string = if _PromptStyle == 'd' then
  1724.                         finddlg
  1725.                       else
  1726.                         ask "[string/abgirswx] Find"  "_find"
  1727.                       end
  1728.       if search_string then
  1729.         search2 search_string reverse
  1730.         addhistory "_find" search_string
  1731.       end
  1732.     end
  1733.  
  1734.     // replace prompt
  1735.     function  askrepl (reverse)
  1736.       search_string = if _PromptStyle == 'd' then
  1737.                         repldlg
  1738.                       else
  1739.                         ask "[string/replstr/abgirswx] Repl"  "_find"
  1740.                       end
  1741.       if search_string then
  1742.         search2 search_string reverse
  1743.         addhistory "_find" search_string
  1744.       end
  1745.     end
  1746.  
  1747.     // do the last find/replace operation
  1748.     // (reverse=r reverses the search direction)
  1749.     function  findlast (reverse)
  1750.       search2 (gethiststr "_find") reverse TRUE
  1751.     end
  1752.  
  1753.     // incremental search
  1754.     function  isearch
  1755.  
  1756.       var search_string
  1757.  
  1758.       repeat
  1759.  
  1760.         settitle  "I-search for [" + search_string + "] "
  1761.         keycode = getkey
  1762.         options = _SearchOpt
  1763.         new_char = ''
  1764.  
  1765.         case  keycode
  1766.  
  1767.           when <backspace>
  1768.             if search_string then
  1769.               popcursor
  1770.               search_string = if (sizeof search_string) > 1 then
  1771.                                 search_string [1 : (sizeof search_string) - 1]
  1772.                               else
  1773.                                 ''
  1774.                               end
  1775.               if not search_string then
  1776.                 display
  1777.               end
  1778.               options = '*'
  1779.             end
  1780.  
  1781.           when <ctrl p>, <ctrl r>
  1782.             options = 'r'
  1783.  
  1784.           when <ctrl n>, <ctrl l>
  1785.             // do nothing
  1786.  
  1787.           when <ctrl g>, <ctrl b>
  1788.             options = 'g'
  1789.  
  1790.           otherwise
  1791.             keyname = getkeyname keycode
  1792.             if (sizeof keyname) == 3 then
  1793.               pushcursor
  1794.               new_char = keyname [2]
  1795.               options = '*'
  1796.             else
  1797.  
  1798.               // restore window title
  1799.               settitle (getbufname)
  1800.               display
  1801.  
  1802.               // clear all pushed cursors
  1803.               popcursor "ad"
  1804.               addhistory "_find" search_string
  1805.  
  1806.               if keycode <> <enter> and keycode <> <esc> then
  1807.                 queuekey keycode
  1808.               end
  1809.  
  1810.               done = TRUE
  1811.             end
  1812.         end
  1813.  
  1814.         if not done and (search_string or new_char) then
  1815.           str_length = find search_string + new_char  _SearchOpt + options
  1816.           if str_length then
  1817.             onfound str_length
  1818.             search_string = search_string + new_char
  1819.           else
  1820.             say  search_string + new_char + " not found"  'b'
  1821.             if new_char then
  1822.               popcursor
  1823.             end
  1824.             onfound (sizeof search_string)
  1825.           end
  1826.         end
  1827.  
  1828.       until done
  1829.     end
  1830.  
  1831.  
  1832.     // find occurrences search
  1833.     function  findo (string_and_opt)
  1834.  
  1835.       var search_string
  1836.       var options
  1837.       var o
  1838.  
  1839.       n = splitstr '' string_and_opt
  1840.                    ref search_string  ref options  ref o
  1841.  
  1842.       // initialize search options
  1843.       if n >= 2 then
  1844.         if n > 2 then
  1845.           options = o
  1846.         end
  1847.         if pos 'g' options then
  1848.           options = sub 'g' '' options
  1849.         end
  1850.       else
  1851.         options = _SearchOpt
  1852.       end
  1853.       options = options + '*'
  1854.  
  1855.       // do the search
  1856.       buffer = createbuf
  1857.       ovltext "≡≡≡≡≡≡ Select this line to edit occurrences ≡≡≡≡≡≡"
  1858.       gotobuf (getprevbuf)
  1859.       pushcursor
  1860.       gotopos 1 1
  1861.       while find  search_string options  do
  1862.         addline  getrow + ": " + gettext  '' '' buffer
  1863.         col MAX_COL
  1864.       end
  1865.       popcursor
  1866.  
  1867.       // display occurrences
  1868.       if (getlines buffer) > 1 then
  1869.         bname = getbufname
  1870.         line = popup buffer
  1871.                  "Occurrences of '" + search_string + "' in "
  1872.                  + (getname bname) + " - " + ((getlines buffer) - 1) +
  1873.                  " lines"   getvidcols - 11 getvidrows - 8
  1874.         if line then
  1875.           if line [1] == '≡' then
  1876.             delline 1 1 buffer
  1877.             setbufname (qualify "TEMP.TXT" bname) buffer
  1878.             openbuf buffer
  1879.           else
  1880.             destroybuf buffer
  1881.             gotopos 1 line [1 : (pos ':' line) - 1]
  1882.             onfound (find search_string  options + '*')
  1883.           end
  1884.         end
  1885.       else
  1886.         destroybuf buffer
  1887.         display
  1888.         say  "'" + string_and_opt + "' not found"  'b'
  1889.       end
  1890.     end
  1891.  
  1892.     // prompt to find occurrences
  1893.     function  askfindo
  1894.       search_str = ask "[string/birswx] Find occurrences of"  "_find"
  1895.       if search_str then
  1896.         findo search_str
  1897.         addhistory "_find" search_str
  1898.       end
  1899.     end
  1900.  
  1901.     // find all occurrences of last find string
  1902.     function  findlasto
  1903.       findo (gethiststr "_find")
  1904.     end
  1905.  
  1906.     // find matching character (){}[]<>
  1907.     function  gotomatch2
  1908.       if gotomatch "(){}[]<>" then
  1909.         onfound 1
  1910.       else
  1911.         say "Not found" 'b'
  1912.       end
  1913.     end
  1914.  
  1915.     // goto column
  1916.     function  col2 (column)
  1917.       case column [1]
  1918.         when '+'   right  column [2 : TO_END]
  1919.         when '-'   left   column [2 : TO_END]
  1920.         otherwise  col (if? column > MAX_COL MAX_COL column)
  1921.       end
  1922.       onfound
  1923.     end
  1924.  
  1925.     // goto line
  1926.     function  row2 (line)
  1927.       case line [1]
  1928.         when '+'   down line [2 : TO_END]
  1929.         when '-'   up   line [2 : TO_END]
  1930.         otherwise  row (if? line > getlines (getlines) line)
  1931.       end
  1932.       onfound
  1933.     end
  1934.  
  1935.     // goto line prompt
  1936.     function  askrow
  1937.       askx "Line number" "_line" "row2"
  1938.     end
  1939.  
  1940.     // goto column prompt
  1941.     function  askcol
  1942.       askx "Column Number" '' "col2"
  1943.     end
  1944.  
  1945.     // set a quick bookmark
  1946.     function  quickbook
  1947.       _bk = _bk + 1
  1948.       bookmark = "Book" + _bk
  1949.       setbook bookmark
  1950.       display
  1951.       say "Bookmark " + bookmark + " set"
  1952.     end
  1953.  
  1954.     // place a bookmark
  1955.     function  placebook (bookmark)
  1956.       if not bookmark then
  1957.         bookmark = ask "Bookmark Name" "_book"
  1958.       end
  1959.       if bookmark then
  1960.         setbook bookmark
  1961.         display
  1962.         say "Bookmark '" + bookmark + "' set"
  1963.       end
  1964.     end
  1965.  
  1966.  
  1967.     // Go to the compiler error on the current line of a compiler
  1968.     // error output file. This function recognizes compiler errors
  1969.     // of the form:
  1970.     //
  1971.     //   <text>  FILENAME.EXT  <text>  LINENUMBER  <text> : MESSAGE
  1972.     //
  1973.     // (implemented by using regular expression searching confined
  1974.     // to the current line)
  1975.  
  1976.     function  gotoerror
  1977.       pushcursor
  1978.       // filename charclass to use (max closure without the period)
  1979.       fileset = "[a-zA-Z0-9_\-/\\\\@~:^!#$%&`']#"
  1980.       file_ext =  fileset + '\\.' + fileset
  1981.       // find the filename
  1982.       length = find file_ext 'xgl*'
  1983.       if length then
  1984.         filename = gettext (getcol) length
  1985.         right length
  1986.         // find the line number
  1987.         length = find "[0-9]#" 'xl'
  1988.         if length then
  1989.           line = gettext (getcol) length
  1990.           // find the message
  1991.           if find ':' 'l' then
  1992.             message = gettext getcol + 1
  1993.             popcursor
  1994.             // open the file
  1995.             if open filename then
  1996.               row line
  1997.               col (getlinebeg)
  1998.               send "onfound"
  1999.               say  message + '  '
  2000.               return
  2001.             end
  2002.           end
  2003.         end
  2004.       end
  2005.       popcursor
  2006.       display
  2007.       say "Compiler message not recognized."
  2008.     end
  2009.  
  2010.  
  2011.     // backup a file and return the backup filename if sucessful
  2012.     function  backup (file)
  2013.       if locatefile file then
  2014.         dir = _BackupDir
  2015.         if dir then
  2016.           if (sizeof dir) > 3 and  dir [LAST_CHAR] == "\\" then
  2017.             dir = dir [1 : (sizeof dir) - 1]
  2018.           end
  2019.           createdir dir
  2020.           dir = qualify dir
  2021.           backup_file = if pos "*.*" dir then
  2022.                           qualify (getname file) dir
  2023.                         else
  2024.                           msgbox "Unable to create backup file!"
  2025.                                  "Warning!"
  2026.                           return 1
  2027.                         end
  2028.         else
  2029.           backup_file = forceext file _BackupExt
  2030.         end
  2031.  
  2032.         // delete the old backup file
  2033.         deletefile backup_file
  2034.  
  2035.         // attempt a rename
  2036.         if not renamefile file backup_file then
  2037.           // try copy if rename fails
  2038.           if (copyfile file backup_file) <= 0 then
  2039.             msgbox "File backup failed!" "Error"
  2040.             return 0
  2041.           end
  2042.         end
  2043.         return backup_file
  2044.       else
  2045.         return 1
  2046.       end
  2047.     end
  2048.  
  2049.     // save the current file to disk
  2050.     function  save (file options)
  2051.       var c1
  2052.       var c2
  2053.  
  2054.       // check for a truncated file
  2055.       if trunc? and
  2056.          not (icompare (popup "ok" "Truncated file - are you sure?") "Ok") then
  2057.         return
  2058.       end
  2059.  
  2060.       file = if file then
  2061.                qualify file (getbufname)
  2062.              else
  2063.                getbufname
  2064.              end
  2065.       if fileattr? file 'r' then
  2066.         say "Read Only!" 'b'
  2067.       else
  2068.         backup_file = 1
  2069.         if setting? 'B' then
  2070.           backup_file = backup file
  2071.         end
  2072.         if not backup_file then
  2073.           say "Backup failed" 'b'
  2074.         else
  2075.           send "onsave" file
  2076.  
  2077.           // get fold comments for the file (if any)
  2078.           send "oncomment" file ref c1 ref c2
  2079.           options = _SaveOpt + options
  2080.           if not savebuf file
  2081.                    (if? (pos 'e' options) 'e' + _TabWidth) + options  ''
  2082.                    (if not getbinarylen then hex2bin _LineDlm end) ''
  2083.                    (if? c1 c1 + _FoldSign) c2 then
  2084.  
  2085.             // restore the backup after save failure
  2086.             if backup_file <> 1 then
  2087.               if not renamefile backup_file file then
  2088.                 copyfile backup_file file
  2089.               end
  2090.             end
  2091.             msgbox "Save failed!  Check file path / file attributes / disk space"  "Error!" 'b'
  2092.             return 0
  2093.           else
  2094.             1
  2095.           end
  2096.         end
  2097.       end
  2098.     end
  2099.  
  2100.     // save-as prompt
  2101.     function  asksaveas (options)
  2102.       file = ask "Save " + (getname (getbufname)) + " as"  "_load"
  2103.       if file then
  2104.         file = qualify file (getbufname)
  2105.         addhistory "_load" file
  2106.         save file options
  2107.       end
  2108.     end
  2109.  
  2110.     // start, stop, or do autosave
  2111.     function  autosave (seconds)
  2112.       if not seconds then
  2113.         if bufchanged? then
  2114.           save
  2115.         end
  2116.       elseif seconds < 0 then
  2117.         destroytimer "asav"
  2118.       else
  2119.         setrepeat "asav" seconds * 1000  '' "autosave"
  2120.       end
  2121.     end
  2122.  
  2123.     // prompt for autosave interval in seconds
  2124.     function  askasave
  2125.       seconds = ask "Autosave interval in secs (-1=disable)"
  2126.       if seconds then
  2127.         autosave seconds
  2128.       end
  2129.     end
  2130.  
  2131.     // highlight all occurrences of the word at the cursor
  2132.     function hiliteword
  2133.       sobj = send "onsyntax" (getbufname)
  2134.       if not sobj then
  2135.         setting 'X' DEFAULT
  2136.         sobj = "syndef"
  2137.       end
  2138.       if sobj then
  2139.         w = send "getword" "a-zA-Z_0-9?"
  2140.         if w then
  2141.           // create a color selection menu
  2142.           menu "hcolor"
  2143.             item " &None"           -1
  2144.             item " &Default"        -2
  2145.             item "-"
  2146.             item " &Black"          color white on black
  2147.             item " B&lue"           color yellow on blue
  2148.             item " &Green"          color white on green
  2149.             item " &Cyan"           color white on cyan
  2150.             item " &Red"            color white on red
  2151.             item " &Magenta"        color white on magenta
  2152.             item " Br&own"          color white on brown
  2153.             item " Gr&ay"           color white on gray
  2154.             item "-"
  2155.             item " Dar&kgray"       color white on darkgray
  2156.             item " Brightbl&ue"     color white on brightblue
  2157.             item " Brightgr&een"    color black on brightgreen
  2158.             item " Brig&htcyan"     color black on brightcyan
  2159.             item " Br&ightred"      color white on brightred
  2160.             item " Brightmagen&ta"  color white on brightmagenta
  2161.             item " &Yellow"         color black on yellow
  2162.             item " &White"          color black on white
  2163.           end
  2164.           setbufname "colorlist"
  2165.           hcolor = popup "hcolor" "select a color "
  2166.           // destroy the menu
  2167.           destroybuf "hcolor"
  2168.           if hcolor then
  2169.             if hcolor == -1 then
  2170.               unsetx w sobj
  2171.             else
  2172.               setxobj w (if? hcolor == -2 '' hcolor) sobj
  2173.             end
  2174.           end
  2175.           display
  2176.         end
  2177.       end
  2178.     end
  2179.  
  2180.     // live word wrap support
  2181.     function livewrap
  2182.  
  2183.       if fold? then
  2184.         return
  2185.       end
  2186.  
  2187.       startcol = getlinebeg
  2188.       if getrow < getlines and (getlinelen  getrow + 1) then
  2189.         n = getlinebeg  getrow + 1
  2190.         startcol = if? n < startcol  n  startcol
  2191.       elseif not getlinelen then
  2192.         startcol = _LMargin
  2193.       end
  2194.  
  2195.       if getcol < startcol then
  2196.         startcol = getcol
  2197.       end
  2198.  
  2199.       if getlinelen then
  2200.         undobegin
  2201.         saved_char = getchar
  2202.         ovltext '■'
  2203.  
  2204.         // mark to the end of the paragraph
  2205.         pushcursor
  2206.         top = getrow
  2207.         while down and getlinelen do
  2208.         end
  2209.         if not getlinelen then
  2210.           up
  2211.         end
  2212.         bottom = getrow
  2213.         popcursor
  2214.  
  2215.         // reformat
  2216.         usemark 'T'
  2217.         markcolumn startcol _RMargin top bottom
  2218.         formatblock '' '' "kr"
  2219.         destroymark
  2220.         usemark
  2221.  
  2222.         // find the original cursor position
  2223.         col 1
  2224.         find '■' '*'
  2225.         ovltext (if? saved_char saved_char ' ')
  2226.  
  2227.         undoend
  2228.       end
  2229.     end
  2230.  
  2231.     // enter a character or string at the cursor, with support for:
  2232.     //   - match character
  2233.     //   - translate
  2234.     //   - standard word wrap
  2235.     //   - live word wrap
  2236.  
  2237.     function  write (write_str)
  2238.  
  2239.       // group together as one undoable operation
  2240.       undobegin
  2241.  
  2242.       // enter the character or string at the cursor and
  2243.       // advance the cursor
  2244.       writetext write_str
  2245.  
  2246.       // get the current window settings
  2247.       setting_str = getsettings
  2248.  
  2249.       // match character
  2250.       if pos 'M' setting_str then
  2251.         instext ( case write_str
  2252.                     when '"'  '"'
  2253.                     when '('  ')'
  2254.                     when '['  ']'
  2255.                     when '{'  '}'
  2256.                     otherwise ''
  2257.                   end )
  2258.       end
  2259.  
  2260.       // translate
  2261.       if pos 'T' setting_str then
  2262.  
  2263.         // delimited lookup?
  2264.         to_word_end = if? (posnot _TranCSet write_str) 2 1
  2265.  
  2266.         // get the last word typed
  2267.         word_str = getword _TranCSet (getcol - to_word_end)
  2268.         if word_str then
  2269.           lookup_str = word_str + (if? to_word_end == 2 '*')
  2270.  
  2271.           // lookup the word in the translate object
  2272.           value = lookup lookup_str _TranObj
  2273.  
  2274.           if value then
  2275.             // is it a function? ..then evaluate it
  2276.             if function? lookup_str _TranObj then
  2277.               eval value
  2278.  
  2279.             // otherwise replace the word
  2280.             else
  2281.               word_column = getcol - (sizeof word_str) - to_word_end + 1
  2282.               delchar (sizeof word_str) word_column
  2283.               instext value word_column
  2284.               col word_column + (sizeof value) + to_word_end - 1
  2285.             end
  2286.           end
  2287.         end
  2288.       end
  2289.  
  2290.       // check for word wrap or live wrap
  2291.       if getlinelen > _RMargin then
  2292.  
  2293.         // live word wrap
  2294.         if pos 'L' setting_str then
  2295.           livewrap
  2296.  
  2297.         // standard word wrap
  2298.         elseif (pos 'W' setting_str) and (not fold?) then
  2299.           column = getcol
  2300.           limit = _RMargin + 1
  2301.           if column > limit then
  2302.             if write_str <> ' ' then
  2303.               first_col = if? (setting? 'A') (getlinebeg) _LMargin
  2304.               split_col = pos ' ' (gettext 1 limit) 'r'
  2305.               split_col = if? split_col > first_col  split_col + 1  limit
  2306.               splitline split_col
  2307.               down
  2308.               markline '' '' 'T'
  2309.               shiftblock  first_col - 1 'T'
  2310.               destroymark 'T'
  2311.               col  column - split_col + first_col
  2312.             end
  2313.           end
  2314.         end
  2315.       end
  2316.  
  2317.       undoend
  2318.     end
  2319.  
  2320.     // enter a date/time stamp at the cursor
  2321.     function  timestamp
  2322.       write getdate + ' ' + gettime
  2323.     end
  2324.  
  2325.  
  2326. // ───────────────────────────────────────────────────────────────────
  2327. //  File Manager windows
  2328. // ───────────────────────────────────────────────────────────────────
  2329.  
  2330.   object  fmgr
  2331.  
  2332.     // return the file name for fmgr commands
  2333.     function  fname2
  2334.       if fmark? then
  2335.         "MARKED FILES"
  2336.       else
  2337.         getname (getffile)
  2338.       end
  2339.     end
  2340.  
  2341.     // error notification
  2342.     function  ferror (s)
  2343.       msgbox  s + " Failed"  "Error!" 'b'
  2344.     end
  2345.  
  2346.     // fmgr confirmation prompt
  2347.     function  fconfirm (confirm pstring func)
  2348.       if (icompare confirm 'n') or
  2349.          (icompare (popup "ok" pstring + ' ' + fname2 + '?') "ok") then
  2350.         fdomark func
  2351.         reopen
  2352.       end
  2353.     end
  2354.  
  2355.     // internal fopen
  2356.     function  fopn (file options)
  2357.       if file then
  2358.         openf file options
  2359.       else
  2360.         fdomark "fopn" options
  2361.       end
  2362.     end
  2363.  
  2364.     // fmgr open file(s) command
  2365.     function  fopen (options)
  2366.  
  2367.       var searchopt
  2368.  
  2369.       if pos '1' options then
  2370.         if shiftkey? then
  2371.           options = options + 'v'
  2372.         end
  2373.         scanstr = fscanstr
  2374.         openf '' options
  2375.  
  2376.         // find first occurrence for scan windows
  2377.         if scanstr then
  2378.           addhistory "_find" scanstr
  2379.           splitstr '' scanstr '' ref searchopt
  2380.           gotopos 1 (if? (pos 'r' searchopt) (getlines) 1)
  2381.           send "onfound" (search scanstr)
  2382.         end
  2383.  
  2384.       else
  2385.         fopn '' options
  2386.       end
  2387.     end
  2388.  
  2389.     // fmgr change file attributes command
  2390.     function  fattr (file attr)
  2391.       if file then
  2392.         chgfileattr file attr
  2393.       else
  2394.         attr = ask "New attributes [AHSR] for " + fname2
  2395.         if attr then
  2396.           fdomark "fattr" (if? attr <> ' ' attr)
  2397.           reopen
  2398.         end
  2399.       end
  2400.     end
  2401.  
  2402.     // fmgr delete file(s) command
  2403.     function  fdelete (file)
  2404.       if file then
  2405.         if pos "*.*" file then
  2406.           file = getpath file
  2407.         end
  2408.         if not deletefile file 'd' then
  2409.           ferror "Delete"
  2410.         end
  2411.       else
  2412.         fconfirm _ConDel "Delete" "fdelete"
  2413.       end
  2414.     end
  2415.  
  2416.     // fmgr touch file(s) command
  2417.     function  ftouch (file)
  2418.       if file then
  2419.         if not touchfile file then
  2420.           ferror "Touch"
  2421.         end
  2422.       else
  2423.         fconfirm _ConTch "Touch" "ftouch"
  2424.       end
  2425.     end
  2426.  
  2427.     // print a file or directory with the current printer settings
  2428.     function  printfile (file)
  2429.       if loadbuf file '' '' _FmgrOpt _TruncLength then
  2430.         print
  2431.         destroybuf
  2432.       end
  2433.     end
  2434.  
  2435.     // fmgr print file(s) command
  2436.     function  fprint (file)
  2437.       if file then
  2438.         if not printfile file then
  2439.           ferror "Print"
  2440.         end
  2441.       else
  2442.         fconfirm 'y' "Print" "fprint"
  2443.       end
  2444.     end
  2445.  
  2446.     // fmgr run file command
  2447.     function  frun (options)
  2448.       run (getffile) options
  2449.       reopen
  2450.     end
  2451.  
  2452.     // fmgr rename file command
  2453.     function  frename
  2454.       oldname = getffile
  2455.       newname = ask  "Rename " + (getname oldname) + " to"  "_load"
  2456.       if newname then
  2457.         if renamefile oldname (qualify newname (getbufname)) then
  2458.           reopen
  2459.         else
  2460.           ferror "Rename"
  2461.         end
  2462.       end
  2463.     end
  2464.  
  2465.     // fmgr copy (or move) file(s) command
  2466.     function  fcopy (source dest options)
  2467.       if source then
  2468.         if dir? dest then
  2469.           dest = qualify (getname source) dest
  2470.         end
  2471.         action = askrac dest
  2472.         if pos action "ra" 'i' then
  2473.           move? = options == 'm'
  2474.           say (if? move? "Mov" "Copy") + "ing " + source "..."
  2475.           if not move? or (icompare action 'a') or not (renamefile source dest) then
  2476.             if not copyfile source dest (if? (icompare action 'a') 'a') then
  2477.               ferror (if? move? "Move" "Copy")
  2478.               fdobrk
  2479.             else
  2480.               if move? then
  2481.                 deletefile source
  2482.               end
  2483.             end
  2484.           end
  2485.         end
  2486.       else
  2487.         if fmark? then
  2488.           dir_dest = qualify (getffile)
  2489.           if not dir? dir_dest then
  2490.             dir_dest = ''
  2491.           end
  2492.         end
  2493.         dest = ask (if? options == 'm' "Move " "Copy ") + fname2 + " to"
  2494.                    "_load" dir_dest
  2495.         if dest then
  2496.           fdomark "fcopy" (qualify dest (getbufname)) options
  2497.           reopen
  2498.         end
  2499.       end
  2500.     end
  2501.  
  2502.     // fmgr move file(s) command
  2503.     function  fmove
  2504.       fcopy '' '' 'm'
  2505.     end
  2506.  
  2507.     // fmgr create new directory command
  2508.     function  fmkdir
  2509.       dir = ask "New directory name" "_load"
  2510.       if dir then
  2511.         if createdir (qualify dir (getbufname)) then
  2512.           reopen
  2513.         else
  2514.           ferror "Create directory"
  2515.         end
  2516.       end
  2517.     end
  2518.  
  2519.  
  2520. // ───────────────────────────────────────────────────────────────────
  2521. //  On-Event functions called by the editor
  2522. // ───────────────────────────────────────────────────────────────────
  2523.  
  2524.   // edit windows & file manager windows only
  2525.   object  edit_fmgr
  2526.  
  2527.     // called while loading files
  2528.     function  onloading (lines)
  2529.       say (if? lines  "Loading [" + lines + "]..."  getbufname)
  2530.     end
  2531.  
  2532.     // called while saving files
  2533.     function  onsaving (lines)
  2534.       say (if? lines  "Saving [" + lines + "]..."  getbufname)
  2535.     end
  2536.  
  2537.     // called while printing files
  2538.     function  onprinting (lines)
  2539.       say (if? lines  "Printing [" + lines + "]... <ctrl break> to stop "
  2540.            getbufname)
  2541.     end
  2542.  
  2543.     // called while scanning files
  2544.     function  onscanning (file found)
  2545.  
  2546.       // create scan progress window
  2547.       if not window? 'scan' then
  2548.  
  2549.         createwindow 'scan'
  2550.         setwinobj
  2551.         setframe ">b"
  2552.         setcolor  border_color   color white on gray
  2553.         setcolor  text_color     color black on gray
  2554.         settitle "Scanning" 'c'
  2555.         setborder "1i"
  2556.         setshadow 2 1
  2557.  
  2558.         // center the window
  2559.         width = (sizeof (getpath file)) + 24
  2560.         height = 16
  2561.         ox = (getvidcols - width) / 2
  2562.         oy = (getvidrows - height) / 2
  2563.         sizewindow ox oy ox + width oy + height "ad"
  2564.         writestr   file + "..."
  2565.  
  2566.       elseif found then
  2567.         writestr " FOUND" (color brightgreen on gray) (getcoord 'x1') - 7
  2568.  
  2569.       elseif file then
  2570.         writeline
  2571.         writestr   file + "..."
  2572.  
  2573.       else
  2574.         destroywindow
  2575.       end
  2576.  
  2577.       display
  2578.     end
  2579.  
  2580.     // called while compiling files
  2581.     function  oncompiling (file lines)
  2582.       say (if? lines  "Compiling " + file + " [" + lines + "]..."  getbufname)
  2583.     end
  2584.  
  2585.  
  2586.   // edit windows only
  2587.   object  edit
  2588.  
  2589.     // called after a file is opened and before it's displayed
  2590.     function  onopen
  2591.  
  2592.       // set window event object
  2593.       setwinobj "edit"
  2594.  
  2595.       // default window settings (if not remembered by open)
  2596.       if not getsettings then
  2597.         setting _DefaultSet ON
  2598.       end
  2599.  
  2600.       // check for file truncation
  2601.       if trunc? then
  2602.         display
  2603.         say "File Truncated!" 'b'
  2604.       end
  2605.     end
  2606.  
  2607.     // called immediately before a file is saved
  2608.     //function  onsave (file) then
  2609.     //end
  2610.  
  2611.     // called when switching to a file
  2612.     //function  onfocus
  2613.     //end
  2614.  
  2615.     // called when closing a file
  2616.     //function  onclose
  2617.     //end
  2618.  
  2619.     // called after a search to change the window view and
  2620.     // optionally highlight a string
  2621.     function  onfound (stringlength)
  2622.  
  2623.       // check if the cursor is outside the window view
  2624.       if getcol < getviewleft then
  2625.         if getcol < getviewcols then
  2626.           rollcol -getviewleft
  2627.         else
  2628.           adjustcol 3
  2629.         end
  2630.       elseif getcol + stringlength >= getviewright then
  2631.         adjustcol
  2632.       end
  2633.  
  2634.       if getrow > getviewbot then
  2635.         adjustrow 3
  2636.       elseif getrow < getviewtop then
  2637.         adjustrow
  2638.       end
  2639.       display
  2640.  
  2641.       // highlight a string if stringlength is specified
  2642.       if stringlength then
  2643.         hilite stringlength 1 (getpalette (if? (inmark?) 9 8))
  2644.       end
  2645.     end
  2646.  
  2647.  
  2648.   object  fmgr
  2649.  
  2650.     // called after a fmgr window is opened and before it's displayed
  2651.     function  onopen
  2652.  
  2653.       // set the window event object
  2654.       setwinobj "fmgr"
  2655.  
  2656.       // check for include picklist
  2657.       if ftype? 'i' then
  2658.         display
  2659.         say "Select file to insert"
  2660.       end
  2661.     end
  2662.  
  2663.  
  2664.   // all windows
  2665.   object  a
  2666.  
  2667.     // called when sounding an alarm
  2668.     // (allows you to customize the alarm sound)
  2669.     function  onalarm
  2670.       beep 750 70
  2671.     end
  2672.  
  2673.     // get default comments for a filename (c1, c2 passed by reference)
  2674.     // (associates a filename with comment symbols)
  2675.     function  oncomment (file c1 c2)
  2676.       case getext (upcase file)
  2677.         when ".C", ".AML"   c1 = "//"
  2678.         when ".ASM"         c1 = ';'
  2679.         when ".PAS"         c1 = '{'   c2 = '}'
  2680.         otherwise           c1 = '>'
  2681.       end
  2682.     end
  2683.  
  2684.  
  2685.     // called when entering the editor before any windows are open. DOS
  2686.     // command-line filespecs are passed to this function
  2687.     function  onentry
  2688.  
  2689.       // save the DOS entry path
  2690.       _cp = getcurrpath
  2691.  
  2692.       // open prompt and window history
  2693.       if _SaveHistory == 'y' then
  2694.         openhistory (bootpath "history.dat")
  2695.       end
  2696.  
  2697.       // process command-line parameters passed to the editor
  2698.       param_num = 1
  2699.       parameter = arg 1
  2700.  
  2701.       while parameter do
  2702.  
  2703.         // check for command line options
  2704.         if parameter [1:2] == "-e"  then
  2705.           queue parameter [3 : TO_END]
  2706.  
  2707.         // open files/directories
  2708.         else
  2709.           open parameter
  2710.         end
  2711.  
  2712.         // next command line parm
  2713.         param_num = param_num + 1
  2714.         parameter = arg param_num
  2715.       end
  2716.  
  2717.       // still no windows open? then do bootoptions...
  2718.       if not getcurrwin then
  2719.         case _BootOpt
  2720.           when 'd'  restoredesk
  2721.           when 'f'  open '.'
  2722.           when 'n'  opennew
  2723.           otherwise
  2724.             filespec = ask "File or Directory" "_load"
  2725.             if filespec then
  2726.               open filespec
  2727.             else
  2728.               halt
  2729.             end
  2730.         end
  2731.       end
  2732.  
  2733.       // initialize the mouse
  2734.       if _Mouse == 'y' then
  2735.         if openmouse _MouseOpt then
  2736.           mousepos  15999 + getvidcols  15999 + getvidrows
  2737.           y_sens = _MouSenY
  2738.           if (getos 'v') > 9 then
  2739.             mousesense (_MouSenX * 5) / 8  (y_sens * 5) / 8  _MouDST
  2740.           else
  2741.             mousesense _MouSenX y_sens _MouDST
  2742.           end
  2743.         end
  2744.       end
  2745.  
  2746.       // open key macros if configured
  2747.       if _SaveMac == 'y' then
  2748.         openkey (bootpath "a.mac")
  2749.       end
  2750.  
  2751.       // set autosave timer
  2752.       send "autosave" _AutoSave
  2753.     end
  2754.  
  2755.  
  2756.     // called when exiting the editor after all windows are closed
  2757.     function  onexit
  2758.  
  2759.       // open prompt on non-global exit (if configured)
  2760.       if not __G then
  2761.         if _ExitOpen == 'y' then
  2762.           filespec = ask "File or Directory" "_load"
  2763.           if filespec then
  2764.             open filespec
  2765.           end
  2766.         end
  2767.       end
  2768.  
  2769.       // final exit if no windows open
  2770.       if not getcurrwin then
  2771.  
  2772.         // save prompt and window history
  2773.         if _SaveHistory == 'y' then
  2774.           savehistory (bootpath "history.dat")
  2775.         end
  2776.  
  2777.         // save key macros if configured
  2778.         if _SaveMac == 'y' then
  2779.           // check if record occurred
  2780.           if lookup "kd" "mon" then
  2781.             savekey (bootpath "a.mac")
  2782.           end
  2783.         end
  2784.  
  2785.         // restore entry path saved in onentry
  2786.         currpath _cp
  2787.  
  2788.         closemouse
  2789.         halt
  2790.       end
  2791.     end
  2792.  
  2793.