jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

L4J: Cleaning up of composing


Hi,

I don't understood why composing was splitted in three functions. I would
like to suggest another way:

#v+
--- /home/joerg/.jed/latex.sl.orig	2003-05-22 00:00:41.000000000 +0200
+++ /home/joerg/.jed/latex.sl	2003-06-02 23:29:47.000000000 +0200
@@ -83,9 +83,9 @@
 static variable devnull      = " >NUL";
 #endif
 static variable LaTeX_Compose_Cmd = "latex" +
-  " -interaction=nonstopmode";
+  " --file-line-error-style --interaction=nonstopmode";
 static variable LaTeX_Compose_Pdf_Cmd = "pdflatex" +
-  " -interaction=nonstopmode";
+  " --file-line-error-style -interaction=nonstopmode";
 static variable LaTeX_Dvips_Cmd = "dvips";
 static variable LaTeX_Eps_Options = " -i -E"; % every page a file, eps output
 static variable LaTeX_Dvipdf_Cmd = "dvipdf";
@@ -93,6 +93,7 @@
 static variable LaTeX_Makeindex_Cmd = "makeindex";
 static variable LaTeX_Buffer;
 
+static variable dvi_with_source_specials = 1;
 % -----
 
@@ -199,130 +243,50 @@
   LaTeX_Xpdf_Buffer =      "*xpdf log*",
   LaTeX_Gv_Buffer =        "*gv log*",
   LaTeX_Tree_Buffer =      "*LaTeX Tree*",
+  % we need this variable as buffer for the line mark.
+  % if the line mark isn't associated with a variable it isn't shown
   line_mark;
 
 static define update_log_hook ()
 {
-  line_mark = create_line_mark (color_number ("menu_selection"));
+   line_mark = create_line_mark( color_number("region") );
 }
 
-define find_next_error ()
+define find_next_error()
 {
-  variable found;
-  found = fsearch ("! ");
-  if (NOTFOUND == found)
-    found = fsearch ("l.");
-  if (NOTFOUND != found) {
-    eol (); % move over
-    % fix "file not found"
-    found = fsearch ("not found on input");
-  }
+   if ( orelse {down(1) != 1} {re_fsearch("^[^ ]+:[0-9]+:") == 0} )
+     flush("No errors left");
+   % What's that?
+   % found = fsearch ("not found on input");
 }
 
-define goto_error_line ()
+define find_prev_error()
 {
-  variable line, tmp = get_word_chars ();
-  % extract the line number
-  bol ();
-  define_word ("0-9");
-  skip_word ();
-  push_mark ();
-  bskip_word ();
-  line = integer (bufsubstr ());
-  sw2buf (LaTeX_Buffer);
-  bob ();
-  () = down (line - 1);
-  define_word (tmp);
+   if ( re_bsearch("^[^ ]+:[0-9]+:") == 0 )
+     flush("No errors left");
 }
 
-define close_latex_parse_errors ()
-{
-  set_buffer_modified_flag (0);
-  set_readonly (1);
-  delbuf (whatbuf());
-}
-
-define latex_parse_errors ()
-{
-  variable row = window_info ('r'),
-    key = _Reserved_Key_Prefix + "'",
-    ch = '*',
-    err_mode = "LaTeX-Log";
-  !if (keymap_p (err_mode))
-    make_keymap (err_mode);
-  use_keymap (err_mode);
-  definekey ("find_next_error ()", key, err_mode);
-  definekey ("close_latex_parse_errors ()", "q", err_mode);
-  definekey ("goto_error_line ()", "g", err_mode);
-  flush ("Error(s) found! Press 'L' to switch to the log.");
-  ch = toupper (getkey ());
-  flush ("");
-  if ('L' == ch) {
-    pop2buf (LaTeX_Compile_Buffer);
-    set_buffer_hook ("update_hook", &update_log_hook);
-    set_readonly (1);
-    % move to the first error
-    bob ();
-    find_next_error ();
-    flush (key + ": next error; 'g': go to error line; 'q': quit");
-  }
-  else % back to the LaTeX buffer
-    sw2buf (LaTeX_Buffer);
-}
-
-% -----
-
-define latex_compile_and_parse (cmd)
+define goto_error_line ()
 {
-  variable key, exitcode = TRUE, exit_status;
-  LaTeX_Buffer = whatbuf ();
-  sw2buf (LaTeX_Compile_Buffer);
-  set_readonly (0);
-  erase_buffer ();
-  exit_status = run_shell_cmd (cmd);
-  
-  if (FALSE == exit_status) {
-    % handle warnings
-    bob ();
-    if (0 != fsearch ("Font Warning")) {
-      flush ("Font Warning.");
-      beep ();
-      usleep (1000);
-      exitcode = WARNING;
-    }
-    % else
-    if (0 != fsearch ("Rerun to get")) {
-      flush ("Rerun to get cross-references right.");
-      beep ();
-      usleep (1000);
-      exitcode = RERUN;
-    }
-    % else
-    % after "Rerun to get" = no hope
-    if (0 != fsearch ("There were undefined")) {
-      flush ("There were undefined references.");
-      beep ();
-      exitcode = WARNING;
-    }
-    % treat the 'File not found' case
-    % any other?
-    % else
-    if (WARNING != exitcode)
-      flush ("Success!");
-    
-    sw2buf (LaTeX_Buffer);
-    return exitcode;
-  }
-  else { % latex returned != 0
-    latex_parse_errors ();
-    return FALSE;
-  }
+   variable cwd;
+   (,cwd,,) = getbuf_info();
+   
+   bol();
+   push_mark();
+   if (ffind_char(':') == 0) error("No error in this line found");
+   variable file = dircat(cwd, bufsubstr());
+   
+   () = right(1);
+   push_mark();
+   if (ffind_char(':') == 0) error("No error in this line found");
+   variable line = integer( bufsubstr() );
+
+   % What returns find_file()
+   call("delete_window");
+   () = find_file(file);
+   goto_line(line);
 }
 
-% -----
-
-% composing
-
 public define latex_select_output ()
 {
   variable default = LaTeX_Default_Output;
@@ -332,101 +296,138 @@
                           default, "", 's');
 }
 
-% -----
-
 variable latex_file, latex_file_dir;
 
-public define latex_compose ()
-{
-  variable tmp, bat, dvi, cmd, cmd2, status;
-  !if (USE_MASTER)
-    (latex_file, latex_file_dir,,) = getbuf_info ();
-  dvi = path_sans_extname (dircat (latex_file_dir, latex_file)) + ".dvi";
-  bat = path_sans_extname (dircat (latex_file_dir, latex_file)) + ".bat";
-  
-  % TODO: FIX THE WINDOZE CASE!!!
-  
-  switch (LaTeX_Default_Output)
-    { case "dvi":
-      cmd = LaTeX_Compose_Cmd;
-      cmd2 = "";
-    }
-    { case "ps":
-      cmd = LaTeX_Compose_Cmd;
-      cmd2 = LaTeX_Dvips_Cmd;
-    }
-    { case "eps":
-      cmd = LaTeX_Compose_Cmd;
-      cmd2 = LaTeX_Dvips_Cmd + LaTeX_Eps_Options;
-    }
-    { case "dvipdf":
-      cmd = LaTeX_Compose_Cmd;
-      cmd2 = LaTeX_Dvipdf_Cmd;
-    }
-    { case "pdf": 
-      cmd = LaTeX_Compose_Pdf_Cmd;
-      cmd2 = "";
-    }
+public define latex_compose() {
+   % (file, dir) = get_compile_file()
+   !if (USE_MASTER)
+     (latex_file, latex_file_dir,,) = getbuf_info ();
+
+   if ( prefix_argument (-1) == -1 )
+     LaTeX_Default_Output;
+   else
+     read_with_completion ("dvi,ps,eps,pdf,dvipdf",
+			   "LaTeX output: dvi,ps,eps,pdf,dvipdf",
+			   LaTeX_Default_Output, "", 's');
+
+   variable cmd1, cmd2 = NULL;
+   switch ( () )
+     { case "dvi":
+	cmd1 = LaTeX_Compose_Cmd;
+	if ( dvi_with_source_specials )
+	  cmd1 += " --src-specials";
+     }
+     { case "ps":
+	cmd1 = LaTeX_Compose_Cmd;
+	cmd2 = LaTeX_Dvips_Cmd + " " + path_sans_extname(latex_file) + ".dvi";
+     }
+     { case "eps":
+	cmd1 = LaTeX_Compose_Cmd;
+	cmd2 = LaTeX_Dvips_Cmd + LaTeX_Eps_Options + " " +
+	  path_sans_extname(latex_file) + ".dvi";
+     }
+     { case "dvipdf":
+	cmd1 = LaTeX_Compose_Cmd;
+	cmd2 = LaTeX_Dvipdf_Cmd + " " + path_sans_extname(latex_file) + ".dvi";
+     }
+     { case "pdf": 
+	cmd1 = LaTeX_Compose_Pdf_Cmd;
+	if ( dvi_with_source_specials )
+	  cmd1 += " --src-specials";
+     }
+     {
+	error("Unknow output format.");
+     }
 
-  % run latex or whatever
-  save_buffers ();
-  flush ("Composing... (output profile: " + LaTeX_Default_Output + ")");
-  % cd to the right directory
-  tmp = "cd " + latex_file_dir + "; " + cmd + " " +
-    dircat (latex_file_dir, latex_file);
-#ifdef UNIX
-  !if (strcmp ("y", LaTeX_Rerun)) {
-    do {
-      status = latex_compile_and_parse (tmp);
-      flush ("Rerunning...");
-    } while (RERUN == status);
-    flush ("All runs done.");
-  }
-  else
-    status = latex_compile_and_parse (tmp);
-#elifdef WIN32
-  % build a .bat file, then run it
-  if (TRUE == file_status (bat))
-    delete_file (bat);
-  write_string_to_file ("cd " + latex_file_dir + "\n", bat);
-  append_string_to_file (cmd + " " + 
-			 dircat (latex_file_dir, latex_file) + "\n", bat);
-  !if (strcmp ("y", LaTeX_Rerun)) {
-    do {
-      status = latex_compile_and_parse (bat);
-      flush ("Rerunning...");
-    } while (RERUN == status);
-    flush ("All runs done.");
-  }
-  else
-    status = latex_compile_and_parse (bat);
-  % the .bat file will be deleted later
-#endif
-  
-  if (FALSE == status)
-    return;
-  
-  % if cmd2 isn't void, run dvips or whatever
-  if (strlen(cmd2)) {
-    flush ("Running: " + cmd2 + " " + dircat (latex_file_dir, dvi));
-    sw2buf (LaTeX_Dvips_Buffer);
-    set_readonly (0);
-    erase_buffer ();
-#ifdef UNIX
-    % cd to the source directory, so that included files can be found
-    if (0 != run_shell_cmd ("cd " + latex_file_dir + "; " +
-                            cmd2 + " " + dvi + " 2>&1"))
-#elifdef WIN32
-    delete_file (bat);
-    write_string_to_file  ("cd " + latex_file_dir + "\n", bat);
-    append_string_to_file (cmd2 + " " + dvi + "\n", bat);
-    if (0 != run_shell_cmd (bat))
-#endif
-      error ("Could not run " + cmd2+ " " + 
-             dircat (latex_file_dir, latex_file));
-    flush ("Done.");
-    sw2buf (LaTeX_Buffer);
-  }
+   cmd1 +=  " " + latex_file;
+   
+   save_buffer();
+   
+   bufferp(LaTeX_Compile_Buffer);  % leaves its return code on stack
+   pop2buf(LaTeX_Compile_Buffer);
+   
+   otherwindow();
+   loop( window_info('r') - 6 ) enlargewin();
+   otherwindow();
+
+   if ( () ) {
+      % buffer already exists
+      set_readonly(0);
+      erase_buffer();
+   } else {
+      % buffer is new
+      variable err_mode = "LaTeX-Log";
+      
+      !if (keymap_p (err_mode)) {
+	 make_keymap (err_mode);
+     
+	 definekey ("find_next_error()", _Reserved_Key_Prefix + "'", err_mode);
+	 definekey ("find_next_error()", "n", err_mode);
+	 definekey ("find_prev_error()", "p", err_mode);
+
+	 definekey ("goto_error_line()", "g", err_mode);
+	 definekey ("goto_error_line()", "", err_mode);
+	 
+	 definekey ("delbuf(whatbuf());call(\"delete_window\")",
+		    "q", err_mode);
+      }
+      use_keymap (err_mode);
+      set_buffer_hook("update_hook", &update_log_hook);
+   }
+	 
+   flush ("Running " + cmd1 + "...");
+
+   variable exitcode;
+   if (change_default_dir(latex_file_dir) != 0)
+     error("Could not change to "+latex_file_dir);
+   
+   forever {
+      exitcode = run_shell_cmd(cmd1);
+      
+      if ( orelse {exitcode != 0} {strcmp ("y", LaTeX_Rerun) == 0} )
+	break;
+      
+      bob();
+      if ( 0 == fsearch("Rerun to get") )
+	break;
+	
+      flush ("Rerun to get cross-references right.");
+      beep ();
+      usleep (1000);
+   }
+   set_readonly(1);
+   set_buffer_modified_flag(0);
+
+   if ( exitcode == 0 ) {
+      % handle warnings
+      bob ();
+      if (0 != fsearch ("Font Warning")) {
+	 flush("Font Warning.");
+	 beep();
+	 usleep(1000);
+      } else if (0 != fsearch ("There were undefined")) {
+	 flush("There were undefined references.");
+	 beep();
+      } else 
+	flush ("Success!");
+      
+      % if cmd2 isn't void, run dvips or whatever
+      if (cmd2 != NULL) {
+	 flush("Running: " + cmd2);
+	 sw2buf(LaTeX_Dvips_Buffer);
+	 set_readonly(0);
+	 erase_buffer();
+	 
+	 if ( 0 != run_shell_cmd (cmd2 + " 2>&1") )
+	   error ("Could not run " + cmd2);
+	 flush("Done.");
+	 sw2buf(LaTeX_Compile_Buffer);
+      }
+   } else {
+      bob();
+      find_next_error();
+   }
+   flush ("n/p: next/previous error; g,Enter: go to error line; q: quit");
 }
 
 % customising, viewing, printing, etc.
#v-

Bye, Jörg.

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]