home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / epmmac2.zip / ASSIST.E < prev    next >
Text File  |  1993-01-21  |  4KB  |  74 lines

  1. /*****************************************************************************/
  2. /*  Assist interface for E3      Ralph Yozzo                                 */
  3. /*                                                                           */
  4. /*  This macro is intended for use with programming language                 */
  5. /*  which have tokens which must be balanced to compile correctly.           */
  6. /*  We shall call these tokens "balanceable tokens" or BalTok for            */
  7. /*  short.                                                                   */
  8. /*                                                                           */
  9. /*  The functions provided include moving from an opening token              */
  10. /*  (e.g., (, {, [ ) to a closing token (e.g., ), }, ] ) and vice versa.     */
  11. /*                                                                           */
  12. /*  KEYS:                                                                    */
  13. /*  Ctrl-[, Ctrl-]  -- move to corresponding BalTok                          */
  14. /*                                                                           */
  15. /*  CONSTANTS:                                                               */
  16. /*  gold -BalTok tokens  are defined in the const gold and additional        */
  17. /*        tokens may be added.                                               */
  18. /*                                                                           */
  19. /*  Example:                                                                 */
  20. /*     if ((c=getch())=='c'                                                  */
  21. /*      &&(d=complicatedisntit(e))){                                         */
  22. /*      lookforbracket();                                                    */
  23. /*     }                                                                     */
  24. /* In the above program segment if one places the cursor on an opening       */
  25. /* parenthesis and presses Ctrl-[ the cursor will move to the corresponding  */
  26. /* closing parenthesis if one exists.  Pressing Ctrl-[ again will reverse    */
  27. /* the process.                                                              */
  28. /*                                                                           */
  29. /* Modified by Larry Margolis to use the GREP option of Locate to search     */
  30. /* for either the opening or closing token, rather than checking a line at   */
  31. /* a time.  I also changed the key from Ctrl-A to Ctrl-[ or -], which are    */
  32. /* newly allowed as definable keys, and deleted the matching of /* and */.   */
  33. /* (The GREP search is much faster than the way Ralph did it, but doesn't    */
  34. /* let you match either of 2 strings.)  Finally, the user's previous search  */
  35. /* arguments are saved and restored, so Ctrl-F (repeatfind) will not be      */
  36. /* affected by this routine.                                                 */
  37. /*****************************************************************************/
  38. const GOLD = '(){}[]<>'  -- Parens, braces, brackets & angle brackets.
  39.  
  40. def c_leftbracket, c_rightbracket = call passist()
  41.  
  42. defproc passist
  43. compile if EVERSION >= '5.50'
  44.    call psave_pos(savepos)
  45. compile endif
  46.    n=1
  47.    c=substr(textline(.line),.col,1)
  48.    GETSEARCH search_command -- Save user's search command.
  49.    k=pos(c,GOLD)            --  '(){}[]<>'
  50.    if not k then sayerror 'Not a balanceable character.'; return; endif
  51.    search = substr(GOLD,(k+1)%2*2-1,2)
  52.    if k//2 then direction='+F'; else direction='-R'; endif
  53.    if search='[]' then search='\[\]'; endif
  54.    'L /['search']/eg'direction
  55.    loop
  56.       repeatfind
  57.       if rc then leave; endif
  58.       if substr(textline(.line), .col, 1) = c then n=n+1; else n=n-1; endif
  59.       if n=0 then leave; endif
  60.    endloop
  61.    if rc=sayerror('String not found') then
  62.       sayerror 'Unbalanced token.'
  63.    else
  64.       sayerror 1
  65.    endif
  66.    SETSEARCH search_command -- Restores user's command so Ctrl-F works.
  67. compile if EVERSION >= '5.50'
  68.    newline = .line; newcol = .col
  69.    call prestore_pos(savepos)
  70.    .col = newcol
  71.    .lineg = newline
  72.    right; left        -- scroll_to_cursor
  73. compile endif
  74.