home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmtfe30.zip / source.zip / source / texfek.e < prev   
Encoding:
Text File  |  2000-04-19  |  8.0 KB  |  239 lines

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