home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / EPMASI.ZIP / MYASSIST.E < prev    next >
Text File  |  1993-03-29  |  12KB  |  303 lines

  1. /**************************************************************************/
  2. /*                 E3/EOS2/EPM Syntax Assistance Version 2.0              */
  3. /*                   Sven Guyet, 03/92  (DSGUYE at DUESVM1)               */
  4. /**************************************************************************/
  5. /* See MYASSIST.DOC for detailed informations.                            */
  6. /*                                                                        */
  7. /* To include MYASSIST into your E configuration copy the following       */
  8. /* 5 lines to your MYKEYS.E (or MYSTUFF.E) file:                          */
  9. /*         compile if defined (WANT_MY_ASSIST)                            */
  10. /*            compile if WANT_MY_ASSIST                                   */
  11. /*               include 'myassist.e'                                     */
  12. /*            compile endif                                               */
  13. /*         compile endif                                                  */
  14. /*                                                                        */
  15. /* Copy the following 2 lines to your MYCNF.E:                            */
  16. /*         const                                                          */
  17. /*            WANT_MY_ASSIST = 1                                          */
  18. /*                                                                        */
  19. /* Now, if you wish to leave out MYASSIST temporarily, you can simply     */
  20. /* set WANT_MY_ASSIST to 0 in your MYCNF.E, and it will be omitted.       */
  21. /*                                                                        */
  22. /* To get syntax assistance, type the abbreviated keyword and press ALT-H.*/
  23. /* The cursor position must be WITHIN or ON ONE OF THE BLANKS AFTER       */
  24. /* the desired keyword prior pressing ALT-H.                              */
  25. /*                                                                        */
  26. /* To change the default syntax assistance filename, type 'sf' or         */
  27. /* 'syntaxfile' followed by the new filename at the command line.         */
  28. /*                                                                        */
  29. /* To get information about the default syntax assistance filename, type  */
  30. /* 'sf' or 'syntaxfile' without any parameters at the command line.       */
  31. /**************************************************************************/
  32.  
  33. ; Code starts here
  34.  
  35. definit
  36.    universal ACTUAL_FILE_NAME,SYNTAX_FILE_NAME,svensinfo,synfile
  37.    svensinfo='SVENs_E_assistant 2.0: '
  38.    ACTUAL_FILE_NAME=''            /* Initialize syntax assistance filename*/
  39.    synfile  =''
  40.    compile if defined(my_syntax_filename)
  41.       SYNTAX_FILE_NAME = upcase(my_syntax_filename)
  42.    compile else
  43.       SYNTAX_FILE_NAME = 'MYSYNTAX.ASI'
  44.    compile endif /* SYNTAX_FILE_NAME */
  45.  
  46. defc sf, syntaxfile =
  47.    universal SYNTAX_FILE_NAME,svensinfo,synfile
  48.    uparg=upcase(arg(1))
  49.    call mysfquit()                /* Quit actual syntax assistance file    */
  50.    if uparg <>'' then             /* Set new default syntax assistance file*/
  51.       SYNTAX_FILE_NAME = uparg
  52.    endif
  53.    sayerror svensinfo'Default syntax file name is »'SYNTAX_FILE_NAME'«'
  54.  
  55. def a_h =                         /* ALT-H is normally not defined in E    */
  56. compile if EVERSION > 5           /* and can easily be remembered as       */
  57.     if .line then                 /* "alternative help"                    */
  58. compile else
  59.     if .line and (not command_state()) then
  60. compile endif
  61.        call myassist()
  62.     endif
  63.  
  64. defproc mysfquit
  65.    universal synfile
  66.    if synfile<>'' then
  67.       GETFILEID curfile
  68.       ACTIVATEFILE synfile; GETFILEID synfile
  69.       if synfile<>curfile then
  70.          'quit'
  71.       endif
  72.       synfile=''
  73.       ACTIVATEFILE curfile
  74.    endif
  75.    return
  76.  
  77. defproc myassist
  78.    universal ACTUAL_FILE_NAME,SYNTAX_FILE_NAME,svensinfo,synfile
  79.    GETFILEID curfile
  80.    if synfile <> '' then
  81.       ACTIVATEFILE synfile; GETFILEID synfile
  82.       if synfile=curfile then
  83.          synfile=''
  84.       endif
  85.       ACTIVATEFILE curfile
  86.    endif
  87.  
  88.    ext = filetype()               /* Get file type (file name extension)   */
  89.    sfile = 'MYAS_'ext'.ASI'       /* Set corresponding syntax file name    */
  90.    if ACTUAL_FILE_NAME <> sfile then
  91.       compile if EVERSION > 4     /* Look for the syntax file              */
  92.          findfile newsynfile, sfile, '','D'
  93.       compile else
  94.          findfile newsynfile, sfile,EPATH
  95.       compile endif
  96.       if rc then                  /* If all that fails, try standard path  */
  97.          findfile newsynfile, sfile, 'PATH'
  98.       endif
  99.       if not rc then              /* New file found: quit current file     */
  100.          call mysfquit()
  101.          ACTUAL_FILE_NAME = sfile
  102.       else                        /* New file not found: set default file  */
  103.          if ACTUAL_FILE_NAME <> SYNTAX_FILE_NAME then
  104.             call mysfquit()
  105.             ACTUAL_FILE_NAME = SYNTAX_FILE_NAME
  106.          endif
  107.       endif
  108.    endif
  109.  
  110.    if synfile = '' then           /* Syntax assistance file not yet active,*/
  111.       compile if EVERSION > 4     /* so load it now                        */
  112.          findfile synfile, ACTUAL_FILE_NAME, '','D'
  113.       compile else
  114.          findfile synfile, ACTUAL_FILE_NAME,EPATH
  115.       compile endif
  116.       if rc then                  /* If all that fails, try standard path  */
  117.          findfile synfile, ACTUAL_FILE_NAME, 'PATH'
  118.          if rc then
  119.             synfile=''
  120.             sayerror svensinfo'ERROR: Syntax file »'ACTUAL_FILE_NAME'« not found'
  121.             return
  122.          endif
  123.       endif
  124. compile if EVERSION < 5           /* Load E syntax assistance file into    */
  125.       'e /h 'synfile              /* the hidden ring (user shouldn't see it*/
  126. compile else                      /* during a normal E session!!!)         */
  127.       'e 'synfile                 /* EPM doesn't have a /H option;         */
  128.       .visible = 0                /* instead, set .visible off             */
  129. compile endif
  130.       if rc then
  131.          synfile=''
  132.          sayerror svensinfo'ERROR: Syntax file can not be loaded; enough memory?'
  133.          return
  134.       endif
  135.       GETFILEID synfile,ACTUAL_FILE_NAME
  136.       ACTIVATEFILE curfile
  137.    endif
  138.  
  139.    if curfile = synfile then
  140.       sayerror svensinfo'ERROR: Syntax assistance denied within E syntax file'
  141.       return
  142.    endif
  143.    call psave_pos(savepos)                   /* Save the cursor position   */
  144.    call pbegin_word()                        /* Get search word            */
  145.    wleft=.col
  146.    call pend_word()
  147.    wright=.col+1
  148.    curline=.line; getline line
  149.    lineleft =substr(line,1,wleft-1)          /* Save first part of line    */
  150.    blanks   =substr(' ',1,wleft-1)
  151.    searchwrd=substr(line,wleft,wright-wleft) /* Save search word           */
  152.    linerest =substr(line,wright)             /* Save rest of the line      */
  153.    if searchwrd  = ' ' then
  154.       sayerror svensinfo'ERROR: No search word encountered'
  155.       call prestore_pos(savepos)             /* Restore the user's mark    */
  156.       return
  157.    endif
  158.  
  159.    sayerror svensinfo'searching ...'
  160.    call psave_mark(savemark)                 /* Save the user's mark       */
  161. compile if EVERSION > 4
  162.    getsearch savesearch /* Save the user's search string, so c_F will work */
  163. compile endif
  164. compile if EVERSION > 5
  165.    display -2                   /* Don't want to see "Not found" messages  */
  166. compile endif
  167.    start      = 1
  168.    hits       = 0
  169.    searchstep = 1
  170.    ACTIVATEFILE synfile; TOP; begin_line
  171.    /* Look for first presence of search word with explanation in the same  */
  172.    /* line (append a blank character to the search word).                  */
  173.    call pset_mark(1,.last,1,length(searchwrd)+1,'BLOCK',synfile)
  174.    'xcom l ■'searchwrd' ■ cm'
  175.    if rc then
  176.       searchstep = 2
  177.       TOP; begin_line
  178.       /* Look for first presence of search word with explanation in a      */
  179.       /* following line.                                                   */
  180.        call pset_mark(1,.last,1,length(searchwrd),'BLOCK',synfile)
  181.       'xcom l ■'searchwrd'■ cm'
  182.    endif
  183.  
  184.    while not rc do
  185.       if searchstep = 2 then
  186.          while not rc do
  187.             getline line,.line,synfile
  188.             if upcase(line) = upcase(searchwrd) then
  189.                leave
  190.             else
  191.                REPEATFIND
  192.             endif
  193.          endwhile
  194.          if rc then
  195.             leave
  196.          endif
  197.       endif
  198.  
  199.       loop
  200.          tab_word                   /* Move to the second word of the line */
  201.          getline line,.line,synfile /* Get the contents of the line        */
  202.          if upcase(line) = upcase(searchwrd) then
  203.             if .line >= .last then
  204. compile if EVERSION > 5
  205.                display 2       /* Restore display of non-critical errors   */
  206. compile endif
  207.                sayerror svensinfo'ERROR: Blank definition line encountered for »'searchwrd'«'
  208.                ACTIVATEFILE curfile
  209. compile if EVERSION > 4                /* Restore the user's search        */
  210.                setsearch savesearch    /* string, so c_F will work         */
  211. compile endif
  212.                call prestore_mark(savemark) /* Restore the user's mark     */
  213.                call prestore_pos(savepos)   /* Restore the cursor position */
  214.                return
  215.             endif
  216.             .line = .line+1
  217.             .col = 1
  218.          else
  219.             leave
  220.          endif
  221.       endloop
  222.  
  223.       hits     = hits+1
  224.       syncol   = .col
  225.       synspace = substr(' ',1,syncol-1) /* Get the indentation             */
  226.       syntax   = substr(line,syncol)    /* Get the description             */
  227.       synline  = .line
  228.       curscol  = 0
  229.       cursrow  = 0
  230.       go_on    = 1
  231.       while go_on do
  232.          go_on = 0; nextsyntax = ''; lineright=linerest
  233.          if synline < .last then
  234.             synline = synline+1   /* Examine whether the next lines belong */
  235.             getline line,synline  /* to the same description               */
  236.             if substr(line,1,syncol-1) = synspace then /* Ok, save the     */
  237.                nextsyntax = substr(line,syncol)        /* description      */
  238.                lineright  = ''
  239.                go_on    = 1
  240.             endif
  241.          endif
  242.          ACTIVATEFILE curfile
  243.          marker = POS('▓',syntax)
  244.          if marker > 0 then
  245.             syntax  = SUBSTR(syntax,1,marker-1) || SUBSTR(syntax,marker+1)
  246.             curscol = LENGTH(blanks)+marker
  247.             cursrow = curline
  248.          endif
  249.          if start then
  250.             replaceline lineleft||syntax||lineright
  251.             start = 0
  252.          else
  253.             insertline blanks||syntax||lineright,curline
  254.          endif
  255.          syntax   = nextsyntax
  256.          curline  = curline+1
  257.          ACTIVATEFILE synfile
  258.       endwhile
  259.  
  260.       lineleft = blanks
  261.       linerest = ''
  262.  
  263.       if hits=1 then lastline=curline-1; endif  /* Save end of first hit   */
  264.       REPEATFIND
  265.       if rc then
  266.          if searchstep = 1 then
  267.             searchstep = 2
  268.             TOP; begin_line
  269.             /* Look for first presence of search word                      */
  270.             call pset_mark(1,.last,1,length(searchwrd),'BLOCK',synfile)
  271.             'xcom l ■'searchwrd'■ cm'
  272.          endif
  273.       endif
  274.    endwhile
  275.  
  276. compile if EVERSION > 4           /* Restore the user's search string,     */
  277.    setsearch savesearch           /* so c_F will work                      */
  278. compile endif
  279.  
  280. compile if EVERSION > 5
  281.    display 2                   /* Restore display of non-critical errors   */
  282. compile endif
  283.    call prestore_mark(savemark)             /* Restore the user's mark     */
  284.  
  285.    ACTIVATEFILE curfile
  286.    if not hits then
  287.       sayerror svensinfo'No syntax definition found for »'searchwrd'«'
  288.       call prestore_pos(savepos)            /* Restore the cursor position */
  289.    else
  290.       sayerror svensinfo'E syntax assistance executed for »'searchwrd'«'
  291.       if curscol > 0 then
  292.          .col  = curscol       /* If marker was found within replacement   */
  293.          .line = cursrow       /* string, position the cursor              */
  294.          if not INSERTSTATE() then
  295.             INSERTTOGGLE
  296.          endif
  297.       else
  298.          .line = lastline; end_line  /* otherwise, position at the end     */
  299.       endif
  300.    endif
  301.  
  302.    return
  303.