home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmtfe30.zip / source.zip / source / texfek.e (.txt) < prev   
LaTeX Document  |  2000-04-19  |  8KB  |  204 lines

  1.  What's it called: TeX Front End key definitions (texfek.e), v3.0
  2.  What does it do:  Defines the TeX keysets and syntax assist procedures.
  3.  Who and When:     Jo Koenen 7/94
  4.                    Jon Hacker 8/95
  5.                    Walter Schmidt  04/2000
  6. compile if not defined(ENTER_ACTION)
  7.    const ENTER_ACTION = 'ADDLINE'
  8. compile endif
  9. compile if not defined(ENHANCED_ENTER_KEYS)
  10.    const ENHANCED_ENTER_KEYS = 1 -- ???
  11. compile endif
  12. compile if not defined(LATEX_SYNTAX_INDENT)
  13.    const LATEX_SYNTAX_INDENT = 2 -- changed v2.2
  14. compile endif   
  15.   Tex keysets are loaded during defselect                                   
  16.   We put the keys statement in the defselect so that we can check           
  17.   to make sure it is a TeX file before we load the keyset.                  
  18. defproc setTeXKeySets
  19.     universal app_hini
  20.     if tex_is_file() then  -- if TeX doc/style loaded
  21.         if queryprofile( app_hini, TEX_APP, 'TEX_KEYS') then
  22.             if translate(.keyset) <> 'TEXKEYSA' then keys TEXKEYSA endif
  23.         else
  24.             if translate(.keyset) <> 'TEXKEYSN' then keys TEXKEYSN endif
  25.         endif -- TEX_KEYS
  26.     endif  -- TeX doc/style loaded
  27.   Define the TeX syntax assist key set combo                                
  28. defkeys TEXKEYSA   -- quick keys + syntax expansion + EPMTeX accelerator keys 
  29. define TEXACCEL = 1
  30. define TEXCOMPL = 1
  31. include 'texfed.e'
  32. defkeys TEXKEYSN   -- quick keys + syntax expansion
  33. define TEXACCEL = 0
  34. define TEXCOMPL = 1
  35. include 'texfed.e'
  36.  TeX syntax assist procedure definitions.                                   
  37.                                                                             
  38.  What does it do:  The enter and space bar keys have been defined to have   
  39.                    specific TeX editing features in this keyset.            
  40.                                                                             
  41.   defproc tex_first_expansion
  42.     retc=1   -- default return code
  43.   compile if EVERSION >= 5
  44.     if .line then  -- current line number
  45.   compile else
  46.     if .line and (not command_state()) then
  47.   compile endif
  48.       getline line
  49.       line=strip(line,'T') -- remove trailing spaces
  50.       line_l=substr(line,1,.col-1) -- split line into two parts at cursor
  51.       line_r=substr(line,.col)
  52.       linelen=length(line_l)
  53.       if linelen > 2 then
  54.         wrd=substr(line_l,.col-3,3)
  55.       else
  56.         wrd=line_l
  57.       endif
  58. -- expand \begin
  59.       if wrd='\be' then
  60.         replaceline line_l'gin{}'line_r
  61.         if not insert_state() then insert_toggle
  62.         compile if EVERSION >= '5.50'
  63.           call fixup_cursor()
  64.         compile endif
  65.         endif
  66.         .col=.col+4
  67. -- expand \cite
  68.       elseif wrd='\ci' then
  69.         replaceline line_l'te{}'line_r
  70.         if not insert_state() then insert_toggle
  71.         compile if EVERSION >= '5.50'
  72.           call fixup_cursor()
  73.         compile endif
  74.         endif
  75.         .col=.col+3  -- reposition cursor
  76. -- expand \label
  77.       elseif wrd='\la' then
  78.         replaceline line_l'bel{}'line_r
  79.         if not insert_state() then insert_toggle
  80.         compile if EVERSION >= '5.50'
  81.           call fixup_cursor()
  82.         compile endif
  83.         endif
  84.         .col=.col+4  -- reposition cursor
  85. -- expand \ref
  86.       elseif wrd='\re' then
  87.         replaceline line_l'f{}'line_r
  88.         if not insert_state() then insert_toggle
  89.         compile if EVERSION >= '5.50'
  90.           call fixup_cursor()
  91.         compile endif
  92.         endif
  93.         .col=.col+2  -- reposition cursor
  94. -- expand \fraction
  95.       elseif wrd='\fr' then
  96.         replaceline line_l'ac{}{}'line_r
  97.         if not insert_state() then insert_toggle
  98.         compile if EVERSION >= '5.50'
  99.           call fixup_cursor()
  100.         compile endif
  101.         endif
  102.         .col=.col+3  -- reposition cursor
  103. -- expand equation
  104.       elseif wrd='equ' then
  105.         replaceline line_l'ation'line_r
  106.         if not insert_state() then insert_toggle
  107.         compile if EVERSION >= '5.50'
  108.           call fixup_cursor()
  109.         compile endif
  110.         endif
  111.         .col=.col+6  -- reposition cursor
  112. -- expand eqnarray
  113.       elseif wrd='eqn' then
  114.         replaceline line_l'array'line_r
  115.         if not insert_state() then insert_toggle
  116.         compile if EVERSION >= '5.50'
  117.           call fixup_cursor()
  118.         compile endif
  119.         endif
  120.         .col=.col+6  -- reposition cursor
  121. -- expand footnote
  122.       elseif wrd='\fo' then
  123.         replaceline line_l'otnote{}'line_r
  124.         if not insert_state() then insert_toggle
  125.         compile if EVERSION >= '5.50'
  126.           call fixup_cursor()
  127.         compile endif
  128.         endif
  129.         .col=.col+7  -- reposition cursor
  130. -- expand pageref
  131.       elseif wrd='\pa' then
  132.         replaceline line_l'geref{}'line_r
  133.         if not insert_state() then insert_toggle
  134.         compile if EVERSION >= '5.50'
  135.           call fixup_cursor()
  136.         compile endif
  137.         endif
  138.         .col=.col+6  -- reposition cursor
  139. -- expand \(
  140.       elseif rightstr(wrd,2)='\(' then
  141.         replaceline line_l' \)'line_r
  142.         if not insert_state() then insert_toggle
  143.         compile if EVERSION >= '5.50'
  144.           call fixup_cursor()
  145.         compile endif
  146.         endif
  147.         .col=.col+1  -- reposition cursor
  148. -- future expansions added here
  149.       else  -- wrd =
  150.         retc=0  -- didn't match wrd, no expansion performed
  151.       endif
  152.     else   -- .line  at top of file, abort expansion
  153.       retc=0
  154.     endif  -- .line = 0
  155.   return retc
  156.   Define second TeX syntax expansion procedure for spacebar and enter       
  157.     -- returns 1 if expansion performed                                     
  158.   defproc tex_second_expansion
  159.     retc=1  -- default return value
  160.     if .line then
  161.       getline lin
  162.       parse value lin with '\begin{'texword'}'args
  163.       c=max(1,verify(lin,' '))-1 -- number of spaces before first word
  164.       -- environment recognized?
  165.       if texword <> '' then
  166. ;        c=max(1,verify(lin,' '))-1 -- number of spaces before first word
  167.         if texword='tabular' and args = '' then 
  168.           -- stay compatible with previous behaviour:
  169.           line_l=substr(lin,1,.col)
  170.           line_r=substr(lin,.col+1)
  171.           replaceline line_l'{|c|}'line_r
  172.           insertline substr('',1,c)'\end{'texword'}',.line+1
  173.         elseif texword='macrocode' then
  174.           replaceline '%    \begin{macrocode}'
  175.           insertline '%    \end{macrocode}',.line+1
  176.         else
  177.           insertline substr('',1,c)'\end{'texword'}',.line+1
  178.         endif
  179.         call einsert_line()  -- position cursor on a new line following \begin
  180. compile if (LATEX_SYNTAX_INDENT > 0)
  181.         if (texword = 'verbatim') or 
  182.            (texword = 'verbatim*') or 
  183.            (texword = 'macrocode') then
  184.            .col = 1
  185.         elseif (texword <> 'document') then
  186.            .col = .col + LATEX_SYNTAX_INDENT
  187.         endif
  188. compile endif        
  189.       elseif rightstr(strip(lin, 'T'), 2)='\[' then
  190. ;        c=max(1,verify(lin,' '))-1 -- number of spaces before first word
  191.         insertline  substr('',1,c)'\]',.line+1
  192.         call einsert_line()
  193. compile if (LATEX_SYNTAX_INDENT > 0)
  194.         .col = .col + LATEX_SYNTAX_INDENT
  195. compile endif        
  196.       else
  197.         retc=0
  198.       endif -- environment
  199.     else
  200.       retc=0
  201.     endif -- .line
  202.   return retc
  203. -- finis
  204.