home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / LASER / FPC35_5.ZIP / FPCSRC.ZIP / SEDWHELP.SEQ < prev    next >
Encoding:
Text File  |  1989-08-25  |  17.1 KB  |  422 lines

  1. \ SEDWHELP.SEQ          Word Help while in Editor       by Tom Zimmer
  2.  
  3. \ WORDHELP was suggested by Phil Friis
  4.  
  5. \ invoked by Alt-H
  6.  
  7. editor definitions
  8.  
  9. handle wordhndl
  10. handle hndlsave
  11. create helpbuf 32 allot
  12.  
  13. 0 value wordline
  14. 0 value listsave
  15. 0 value newbrowse
  16. 0 value browseset
  17. 0 value ?wordhelp
  18. 0 value toggling
  19.  
  20. : 'word@cur     ( --- cfa f1 )
  21.                 @word@cur dup>r 1+ c@ hyperchar =
  22.                                                 \ remove a leading hyper char
  23.                 if      r@ count >r dup 1+ swap r> 1- cmove
  24.                         -1 r@ c+!
  25.                 then
  26.                 r@ count + 2 bl fill            \ append a couple of blanks
  27.                 r@ hfind                        \ try to look it up
  28.                 r> c@ 0> and  ;
  29.  
  30. 0 value wordfnd
  31.  
  32. : findword      ( --- f1 )
  33.                 IBRESET
  34.                 0.0 seek
  35.                 loadline off
  36.                 off> wordfnd
  37.                 8000 1
  38.                 do      lineread c@ 0= ?leave
  39.                         bl outbuf count + 2- c!
  40.                                 \ have at least 1 blank at end of line.
  41.                         helpbuf count outbuf 1+ swap 1+ caps-comp 0=
  42.                         if      i =: loadline
  43.                                 on> wordfnd leave
  44.                         then
  45.                 loop    wordfnd ;
  46.  
  47. : cfa-word-ed/br    ( false cfa --- f1 )
  48.                 savescr
  49.                 cursor-off
  50.                 save> screenchar        \ save current cursor position
  51.                 here helpbuf over c@ 2+ cmove
  52.                 wordhndl save!> seqhandle
  53.                 >viewfile       ( --- offset a1 )
  54.                 ?wordhelp
  55.                 if      " HLP" ">$ over $>ext
  56.                 then
  57.                 $file 0=
  58.                 if      =: listsave
  59.                         on> leavesave  \ setup to leave EDIT
  60.                         seqhandle hndlsave $>handle
  61.                         off> ?warnexit
  62.                         browseset  =: newbrowse
  63.                         screenline =: linesave
  64.                         ?wordhelp
  65.                         if      findword
  66.                                 if      loadline @ =: listsave
  67.                                 else    off> listsave
  68.                                 then
  69.                         then
  70.                         leavesave newfl and
  71.                         if      on> changed     \ write newfile to disk
  72.                         then
  73.                 else    drop true
  74.                         " \4 FILE is not available " ?softerror
  75.                 then
  76.                 restore> seqhandle
  77.                 restore> screenchar             \ restore cursor position
  78.                 restscr
  79.                 cursor-on showcur
  80.                 leavesave
  81.                 if      sesc
  82.                 then    ;
  83.  
  84.                                         \ n1 = line number in file if found
  85. : check-ndx     ( --- n1 f1 )           \ f1 = true if found index
  86.                                         \ searched for word must be at HERE.
  87.                 here c@ 0= if 0 false exit then
  88.                 save> screenchar
  89.                 wordhndl save!> seqhandle
  90.                 here helpbuf over c@ 2+ cmove
  91.                 " HYPER.NDX" ">$ $file 0=
  92.                 if      IBRESET
  93.                         0.0 seek
  94.                         loadline off
  95.                         off> wordfnd
  96.                         0 10000 1
  97.                         do      lineread c@ 0= ?leave
  98.                                 outbuf 1+ c@ 249 ( ∙ ) =
  99.                             if          outbuf count 3 - swap c!
  100.                                         outbuf 1+ hndlsave $>handle
  101.                             else
  102.                                 bl outbuf count + 2- c!
  103.                                       \ have at least 1 blank at end of line.
  104.                                 helpbuf count outbuf 1+ swap 1+ caps-comp 0=
  105.                                 if      drop
  106.                                         outbuf count bl scan 1 -1 d+
  107.                                         2dup bl scan nip -
  108.                                         dup here c! here 1+ swap cmove
  109.                                         here number? 2drop
  110.                                         on> wordfnd leave
  111.                                 then
  112.                             then
  113.                         loop    wordhndl hclose drop
  114.                         wordfnd
  115.                 else    0 false
  116.                 then
  117.                 restore> seqhandle
  118.                 restore> screenchar ;
  119.  
  120. : line-ed/br    ( false line --- f1 )
  121.                 =: listsave
  122.                 save> screenchar        \ save because $FILE below resets it
  123.                 wordhndl save!> seqhandle
  124.                 hndlsave $file 0=
  125.                 restore> seqhandle
  126.                 if      wordhndl hclose drop
  127.                         wordhndl hndlsave $>handle
  128.                         on> leavesave  \ setup to leave EDIT
  129.                         off> ?warnexit
  130.                         browseset  =: newbrowse
  131.                         screenline =: linesave
  132.                         newfl
  133.                         if      on> changed     \ write newfile to disk
  134.                         then
  135.                         sesc
  136.                 else    true " \4 FILE is not available " ?softerror
  137.                         scrshow
  138.                 then    restore> screenchar ;
  139.  
  140. : word-ed/br    ( false --- f1 )
  141.                 'word@cur
  142.                 if      cfa-word-ed/br
  143.                 else    drop
  144.                         check-ndx
  145.                         if      line-ed/br
  146.                         else    drop
  147.                                 true " \4 No LINKAGE for this word "
  148.                                 ?softerror
  149.                                 scrshow
  150.                         then
  151.                 then    ;
  152.  
  153. : wordedit      ( --- )
  154.                 off> browseset
  155.                 off> ?wordhelp
  156.                 word-ed/br ;
  157.  
  158. \ 146 fnset wordedit      \ function value for Alt-E
  159.  
  160. : worddefer     ( false --- f1 )
  161.                 on> browseset
  162.                 off> ?wordhelp
  163.                 'word@cur
  164.                 if      dup @rel>abs
  165.                         ['] bgstuff @rel>abs =
  166.                         if      >body @ cfa-word-ed/br
  167.                         else    dup @rel>abs
  168.                                 ['] emit @rel>abs =
  169.                                 if      >is @ cfa-word-ed/br
  170.                                 else    drop
  171.                                         true
  172.                                         " \4 Not a DEFERED word " ?softerror
  173.                                         scrshow
  174.                                 then
  175.                         then
  176.                 else    drop
  177.                         true " \4 No LINKAGE for this word " ?softerror
  178.                         scrshow
  179.                 then    ;
  180.  
  181. ' worddefer alias worddef
  182.  
  183. \ 240 fnset worddefer     \ function for Alt-F9
  184.  
  185. : wordbrowse    ( --- )
  186.                 on> browseset
  187.                 off> ?wordhelp
  188.                 word-ed/br ;
  189.  
  190. \ 176 fnset wordbrowse    \ function value for Alt-B
  191. \ 195 fnset wordbrowse    \ function value for F9
  192.  
  193. : browse-nln    ( --- )                 \ browse is Enter
  194.                 ?browse
  195.                 if      wordbrowse
  196.                 else    nln
  197.                 then    ;
  198.  
  199. \ control M ctlset browse-nln     \ install into Enter function
  200.  
  201. : wordhelp      ( --- )
  202.                 on> browseset
  203.                 on> ?wordhelp
  204.                 word-ed/br ;
  205.  
  206. \ 163 fnset wordhelp      \ function value for Alt-H
  207.  
  208. : sescALL       ( --- )         \ pop off all extra nest levels
  209.                 on> leavenow
  210.                 sesc
  211.                 off> leavenow
  212.                 on> pop-extra ;
  213.  
  214. \ 221 fnset sescALL       \ function value for Shift-F10
  215.  
  216. defer browbutton        ' noop is browbutton
  217.  
  218. : browsetgl     ( --- )
  219.                 ?browse 0=                              \ if browse is OFF
  220.                 if      changed updated or              \ have things changed
  221.                         if      ['] browbutton save!> dobutton
  222.                                 cursor-off
  223.                                 16 8 64 12 box&fill     \ ask for verification
  224.                                 ."  You have made changes to this file," bcr
  225.                                 ."  do you want to SAVE your changes? "
  226.                                 ." \r Yes \0 \1 No " bcr
  227.                                 ." \s10\1 ESC = Cancel "
  228.                                 begin   key
  229.                                         dup         13 =          \ Enter
  230.                                         over        27 = or       \ ESC
  231.                                         over bl or 'y' = or       \ YES
  232.                                         over bl or 'n' = or 0=    \ NO
  233.                                 while   drop beep
  234.                                 repeat  cursor-on
  235.                             dup 27 <>
  236.                             if  bl or 'n' <>
  237.                                 if      updt            \ then save changes
  238.                                         recover.$$$ ?ferr 0=
  239.                                         if      off> updated
  240.                                                 off> changed
  241.                                                 ?browse 0= =: ?browse
  242.                                         then
  243.                                 else    discard.$$$     \ or don't
  244.                                         off> updated
  245.                                         off> changed
  246.                                         ?browse 0= =: ?browse
  247.                                 then    ['] hypertypeL is typeL
  248.                             else drop                   \ or cancel operation
  249.                             then
  250.                                 restore> dobutton
  251.                                 scrshow
  252.                         else    ?browse 0= =: ?browse
  253.                                 ['] hypertypeL is typeL
  254.                         then
  255.                 else    ?dosio
  256.                         if      ['] (typeL)       is typeL
  257.                         else    (lit) defers typeL is typeL
  258.                         then
  259.                         ?browse 0= =: ?browse
  260.                 then
  261.                 scrshow on> ?border showstat ;
  262.  
  263. \ 220 fnset browsetgl     \ function value for Shift-F9
  264.  
  265. : %sednew       ( --- )
  266.                 off> browseset          \ enter in EDIT mode
  267.                 ['] noop save!> dobutton
  268.                 savescr
  269.                 begin   ?shiftkey
  270.                         if      @word@cur count pad c!
  271.                                 pad count cmove
  272.                         else    pad off
  273.                         then
  274.                         8 8 72 13 box&fill bcr
  275.                         ."  \r Filename to OPEN or CREATE "
  276.                         #out @ 1+ #line @ ( --- x y )
  277.                         bcr bcr
  278.                         ."  Press Enter alone to pick from a list of files "
  279.                         >attrib1
  280.         ( x y --- )     pad 30 lineeditor
  281.                         >norm
  282.                         if      pad c@ 0=
  283.                                 if      getfile ( --- <a1> f1 )
  284.                                         if      pad over c@ 1+ cmove
  285.                                                 true true
  286.                                         else    false
  287.                                         then
  288.                                 else    true true
  289.                                 then
  290.                         else    false true
  291.                         then
  292.                 until
  293.                 if      hndlsave save!> seqhandle
  294.                         pad $file 0=
  295.                         if      hndlsave hclose drop
  296.                                 -1 =: leavesave  \ setup to leave EDIT
  297.                                 off> ?warnexit
  298.                                 browseset =: newbrowse
  299.                                 screenline =: linesave
  300.                                 off> listsave
  301.                         else    cursor-off
  302.                                 20 11 58 14 box&fill
  303.                                 ."  \2  File does not exist, CREATE it?  "
  304.                                 bcr
  305.                                 ." \s07\r Yes \0 No    ESC=Cancel"
  306.                                 0
  307.                                 begin   drop key
  308.                                         dup  27 ( ESC )  =      \ ESC=No
  309.                                         over 13 ( Enter) = or   \ Enter=Yes
  310.                                         over upc 'Y'     = or   \ Y=Yes
  311.                                         over upc 'N'     = or   \ N=No
  312.                                 until   dup 13 =                \ Enter
  313.                                         swap upc 'Y'     = or   \ or Yes
  314.                             if  seqhandle hcreate
  315.                                 20 4 61 6 box&fill space
  316.                                 if
  317.                                    ." \2 Could NOT CREATE the requested file "
  318.                                         beep 1 seconds beep
  319.                                 else
  320.                                    ." \1   CREATING the requested NEW file   "
  321.                                         2573 sp@ 2 seqhandle hwrite 2drop
  322.                                         seqhandle hclose drop
  323.                                         -1 =: leavesave  \ setup to leave EDIT
  324.                                         off> ?warnexit
  325.                                         browseset =: newbrowse
  326.                                         screenline =: linesave
  327.                                         off> listsave
  328.                                 then    >norm 1 seconds
  329.                             then
  330.                         then
  331.                         restore> seqhandle
  332.                         leavesave newfl and
  333.                         if      on> changed     \ write newfile to disk
  334.                         then
  335.                 then    restscr
  336.                 restore> dobutton
  337.                 cursor-on showcur ;
  338.  
  339. ' %sednew is try_to_open
  340.  
  341. : sednew        ( --- )
  342.                 %sednew
  343.                 leavesave
  344.                 if      sesc
  345.                 then    ;
  346.  
  347. \ control O ctlset sednew
  348.  
  349. : togglefiles   ( --- )         \ rotate through open files
  350.                 ?shiftkey >r    \ with SHIFT to rotate backwards.
  351.                 savescr
  352.                 hseg 0= dup
  353.                 " \4 No handle stack segment allocated "      ?softerror
  354.                 hdepth maxh 1- >= dup  " \4 Nest stack FULL " ?softerror
  355.                 or 0=
  356.                 restscr
  357.         if      screenline =: linesave
  358.                 off> leavesave
  359.                 off> ?warnexit
  360.                 sesc            \ leave this edit
  361.                 ed1>hstack      \ push this edit on stack
  362.                 r@
  363.                 if      hdepth 1- 0MAX 0
  364.                         ?do     hrotate
  365.                         loop
  366.                 else    hrotate \ rotate bottom of file stack to top
  367.                 then
  368.                 on> toggling
  369.         then    r>drop ;
  370.  
  371. \ 232 fnset togglefiles           \ Alt-F1
  372.  
  373. 0 value fliptop
  374. 0 value flipbot
  375.  
  376. : flipfiles     ( --- )
  377.                 ['] noop save!> dobutton
  378.                 savescr
  379.                 hseg 0= dup
  380.                 " \4 No handle stack segment allocated "     ?softerror
  381.                 hdepth maxh 1- >= dup " \4 Nest stack FULL " ?softerror
  382.                 or 0=
  383.                 restscr
  384.         if      cursor-off
  385.                 10 11 hdepth 2+ 2/ - dup 1+ =: fliptop
  386.                 70 14 hdepth 1+ 2/ + dup    =: flipbot box&fill
  387.         ." \r  \1 Press a letter for the file you want to select. \2 Line "
  388.                 bcr
  389.                 ."  A - " ed1hndl count type 64 #out @ - spaces
  390.                 curline 1+ 4 .r bcr
  391.                 hdepth 0
  392.                 ?do     space i 'B' + femit ."  - "
  393.                         hseg b/hstk hdepth i 1+ - * 2dup 2dup c@L
  394.                         swap 1+ swap typeL 64 #out @ - spaces
  395.                         b/hcb + @L 4 .r bcr
  396.                 loop    ." \s20\r ESC = Cancel "
  397.                 begin   key     dup  'A' hdepth 'A' + between
  398.                                 over 'a' hdepth 'a' + between or
  399.                                 over 27 ( ESC ) = or 0=
  400.                 while   drop beep
  401.                 repeat  dup 27 <>
  402.                 cursor-on
  403.                 if      bl or 'a' - 0MAX hdepth swap - 1+ >r
  404.                         screenline =: linesave
  405.                         off> leavesave
  406.                         off> ?warnexit
  407.                         sesc            \ leave this edit
  408.                         ed1>hstack      \ push this edit on stack
  409.                         r> 0
  410.                         ?do     hrotate \ rotate bottom of file stack to top
  411.                         loop
  412.                 else    drop scrshow
  413.                 then
  414.         then    restore> dobutton ;
  415.  
  416. \ 212 fnset flipfiles             \ Shift-F1
  417.  
  418. : nxtbrowse     beep ;          \ Alt-N
  419.  
  420. forth definitions
  421.  
  422.