home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Editor / DVD!FX17.LHA / FrexxEd / fpl / LaTeXCompile.FPL < prev    next >
Encoding:
Text File  |  1995-05-30  |  5.8 KB  |  183 lines

  1. // $VER: LaTeXCompile.FPL 1.5 (30.05.95) © Jesper Skov
  2.  
  3.  
  4. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeX Preference Interface ««
  5. void export LaTeXPrefs()
  6. {
  7.   PromptInfo(-1,"LaTeX mode preferences",-1,-1,
  8.    "LaTeX_auto_save",
  9.    "LaTeX_compile_dir",
  10.    "LaTeX_style",
  11.    "LaTeX_port_name",
  12.    "LaTeX_log_restart",
  13.    "LaTeX_comment_start_skip",
  14.    "LaTeX_comment_start",
  15.    "LaTeX_comment_end",
  16.    "LaTeX_line_comment_body",
  17.    "LaTeX_line_comment_start",
  18.    "LaTeX_line_comment_end"
  19.    );
  20. }
  21.  
  22. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeXModeInit() ««
  23. // This function should be part of a LaTeX minor mode... Until one is made,
  24. // it remains here.
  25. //»»»»»»»»»»»»»»»»»»»»»»»»»
  26. export void LaTeXModeInit()
  27. {
  28.   // Set comment strings for LaTeX mode
  29.   SetInfo(-1,"comment_start_skip",ReadInfo("LaTeX_comment_start_skip"));
  30.   SetInfo(-1,"comment_start",ReadInfo("LaTeX_comment_start"));
  31.   SetInfo(-1,"comment_end",ReadInfo("LaTeX_comment_end"));
  32.   SetInfo(-1,"line_comment_start",ReadInfo("LaTeX_line_comment_start"));
  33.   SetInfo(-1,"line_comment_body",ReadInfo("LaTeX_line_comment_body"));
  34.   SetInfo(-1,"line_comment_end",ReadInfo("LaTeX_line_comment_end"));
  35. }
  36.  
  37. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» ShowDVI to front ««
  38. void export LaTeXShow()
  39. {
  40.   if (!FindPort("showdvi")){
  41.     Request("ShowDVI not running!", "LaTeX info", "Huh?");
  42.   } else {
  43.     ARexxSend("showdvi", "tofront");
  44.     ARexxSend("showdvi", "activate");
  45.   }
  46. }
  47.  
  48. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeXCompile() ««
  49. void export LaTeXCompile()
  50. {
  51.   string TeXname = joinstr(GetCompileDir(),ReadInfo("file_name"));
  52.  
  53.   if (stricmp("tex",substr(TeXname,strlen(TeXname)-3,3))){ // Check that name ends with ".tex"
  54.     Request("The file name must have a .tex suffix!","LaTeX info","Blast!");
  55.     return(0);
  56.   }
  57.  
  58.   if (!FindPort(ReadInfo("LaTeX_port_name"))){
  59.     Request("Could not find LaTeX port!","LaTeX info","Huh?");
  60.   } else {
  61.     Save(TeXname);
  62.     ARexxSend(ReadInfo("LaTeX_port_name"), joinstr("compile ",ReadInfo("LaTeX_style")," ",TeXname));
  63.  
  64.     if (ReadInfo("LaTeX_auto_save")){        // Also update file to disk
  65.       Save();
  66.     }
  67.   }
  68. }
  69.  
  70.  
  71. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeXFail() ««
  72. void export LaTeXFail(string LogName)
  73. {
  74.   int texID = GetBufferID(joinstr(substr(LogName,0,strlen(LogName)-3),"tex"));
  75.  
  76.   WindowToFront();
  77.  
  78.   if (texID){                                // Only proceed if tex file was found
  79.     int logID = GetBufferID(LogName);
  80.  
  81.     if (!logID){
  82.       logID = New();
  83.     }
  84.  
  85.     logID = CurrentBuffer(logID);            // logID now previous
  86.     Load(joinstr(GetCompileDir(),LogName));
  87.     CurrentBuffer(logID);                     // Re-activate previously active buffer
  88.     LaTeXNextError(texID,1);                 // Search error from line 1
  89.   } else {
  90.     ReturnStatus("Could not find LaTeX buffer!?!");
  91.   }
  92. }
  93.  
  94.  
  95. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeXNextError() ««
  96. void export LaTeXNextError(int texID, int texLine)
  97. {
  98.   string texName = ReadInfo("file_name",texID);
  99.   string logName = joinstr(substr(texName,0,strlen(texName)-3),"log");
  100.   int logID = GetBufferID(logName);
  101.   int errLine = 0;
  102.  
  103.   if (logID){
  104.     CurrentBuffer(logID);
  105.  
  106.     if (ReadInfo("LaTeX_log_restart"))        // goto start of log file if
  107.       GotoLine(1);                            // this flag is set
  108.  
  109.     SearchSet("=f+","\nl.");
  110.     while(!Search("\nl.")){
  111.       CursorRight(3);
  112.       errLine = atoi(GetWord());
  113.       if (errLine > texLine){
  114.         SearchSet("=","\n!");
  115.         if (!Search("\n!")){                 // From this point texName is reused
  116.           CursorRight(2);                     // for speed reasons
  117.           texName = GetLine();
  118.           texName = substr(texName,0,strlen(texName)-1);
  119.         } else {
  120.           texName = "Error description not found!";
  121.         }
  122.  
  123.         CurrentBuffer(texID);
  124.         GotoLine(errLine);
  125.         ReturnStatus(texName);                 // Show error text
  126.         break;
  127.       }
  128.     }
  129.  
  130.     if (errLine <= texLine){                 // If no valid error line found
  131.       CurrentBuffer(texID);
  132.       ReturnStatus("No more errors found!");
  133.     }
  134.   } else {
  135.     ReturnStatus(joinstr("Log file \"",logName,"\" not loaded!"));
  136.   }
  137. }
  138.  
  139.  
  140.  
  141. string GetCompileDir()
  142. {
  143.   string dir = ReadInfo("LaTeX_compile_dir");
  144.   if (strlen(dir)==0)
  145.     dir = ReadInfo("file_path");
  146.   return(dir);
  147. }
  148.  
  149.  
  150. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» Key bindings ««
  151. AssignKey("LaTeXCompile();",    "control c control c","latex_mode");
  152. AssignKey("LaTeXNextError(GetBufferID(),ReadInfo(\"line\",GetBufferID()));","control c '0x2a'","latex_mode");
  153.  
  154. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeX mode preferences ««
  155. ConstructInfo("LaTeX_auto_save","","","GBWH","",0,1,1);
  156. ConstructInfo("LaTeX_log_restart","","","GBWH","",0,1,1);
  157. ConstructInfo("LaTeX_compile_dir","","","GSWH","",0,0,"PrimeTeX:");
  158. ConstructInfo("LaTeX_port_name","","","GSWH","",0,0,"Start_TeX");
  159. ConstructInfo("LaTeX_style","","","GSWH","",0,0,"&latex");
  160.  
  161. ConstructInfo("LaTeX_comment_start_skip","","","WHLS","",0,0,"% *");
  162. ConstructInfo("LaTeX_comment_start","","","WHLS","",0,0,"% ");
  163. ConstructInfo("LaTeX_comment_end","","","WHLS","",0,0,"");
  164. ConstructInfo("LaTeX_line_comment_body","","","WHLS","",0,0,"»");
  165. ConstructInfo("LaTeX_line_comment_end","","","WHLS","",0,0,"««");
  166. ConstructInfo("LaTeX_line_comment_start","","","WHLS","",0,0,"%");
  167.  
  168. ConstructInfo("latex_mode","","","LBH","",0,1,0);
  169. ConstructInfo("latex_mode_ext","","","GSWH","",0,0,"*tex*");
  170. ConstructInfo("latex_mode_exe","","","GSWH","",0,0,"LaTeXModeInit();ME(\"double_mode\");");
  171.  
  172. AddMode(1,"latex_mode", "latex_mode_ext", "latex_mode_exe");
  173.  
  174. //»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»» LaTeX menu ««
  175. MenuAdd("t", "LaTeX");
  176.  MenuAdd("i", "Compile", "LaTeXCompile();");
  177.  MenuAdd("i", "ShowDVI", "LaTeXShow();");
  178.  MenuAdd("i", "---");
  179.  MenuAdd("i", "Next error", "LaTeXNextError(GetBufferID(),ReadInfo(\"line\",GetBufferID()));");
  180.  
  181. MenuAdd("s", "LaTeX...", "LaTeXPrefs();", "", 6,6,-1); // Add to PackageSettings
  182. MenuBuild();
  183.