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