jed-users mailing list

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

Re: L4J: nested environment closing...


begin  Romano Giannetti <romano@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Jun 03, 2003 at 09:50:26PM +0000, Joerg Sommer wrote:
> 
>> but this patch isn't correct. It doesn't work with nested environments in
>> all cases. Here is a new one:
> 
> Thanks! I just started again to write LaTeX things, and discover that the
> J4L did not manage to "close" (with ctrl-c ]) nested environment. So that I
> had changed the original Guido's latex_close_env () with this: (is almost
> all Jörg code): 

I'm sorry, but you are one day to late. :) I rewrote this function
yesterday. Here is a new one and a correction of the rename_environment,
too, that has the same bug. Hope you can test it.

And I have written a new function for newlines. I bound it at me to \e\n.
I firstly implemented \item in environments. So hit \e\n and so get a new
line with an indented \item. It would be nice, if someone can send me any
suggestions, how to handle newline and indention, because in a
description, there are three different newlines: one that only inserts a
\n and indents the new line, one that inserts \\ and indents the newline
and one thats inserts a new line with a new \item.

#v+
private define boenv ()
{
   variable spot = create_user_mark();

   % Idea: increase for every \end we found and decrease for ever \begin
   %       we found. If we have 0, the founded \begin is for our \end.
   variable ends=1;
   do {
      push_mark();
      !if ( bsearch("\\begin{") ) {
         pop_mark(0);

         goto_user_mark(spot);
         return 0;
      }
      --ends;
      
      % see if there are any \ends between our \end and the found \begin
      narrow_to_region();
      while ( fsearch("\\end{") ) { ++ends; () = right(1); }
      bob();
      widen_region();
   } while (ends);

   return 1;
}

private define env_name()
{
   variable stay_there = 0;
   if (_NARGS) stay_there = ();
   
   variable spot = create_user_mark();
   
   EXIT_BLOCK {
      goto_user_mark(spot);
   }
   
   if ( boenv() ) {
      if (stay_there)
        spot = create_user_mark();
      
      () = right(7);             % go over \begin{
      % cut out the environment name
      push_mark();
      !if ( ffind_char('}') ) {
         pop_mark(1);
         error("malformed \\begin{}");
      }
      bufsubstr();
   } else
     NULL;
   
   return ();
}

private define env_name_indent()
{
   push_spot();
   env_name(1);
   what_column()-1;
   pop_spot();
}

define latex_close_env ()
{
   variable spot = create_user_mark();
   bskip_white();
   
   if ( what_column() == 1 ) {
      trim();
      variable name, indent;
      (name, indent) = env_name_indent();
      whitespace(indent);
      insert("\\end{" + name + "}");
   } else {
      goto_user_mark(spot);
      insert("\\end{" + env_name() + "}");
   }
}

define latex_rename_environment ()
{
   variable spot = create_user_mark();
   
   EXIT_BLOCK {
      goto_user_mark(spot);
   }
   
   variable old_name = env_name(1);
   
   if ( old_name == NULL )
     error("You aren't within an environment");
   
   variable new_name =
     read_with_completion(std_env, "Which environment (TAB to list)?",
			  old_name, "", 's');
   
   if ( new_name == old_name )
     return;
   
   () = right(7);
   delete_word();
   insert(new_name);
   
   goto_user_mark(spot);
   
   variable begins=1,
     end_mark = "\\end{" + old_name + "}",
     begin_mark = "\\begin{" + old_name + "}";
   do {
      push_mark();
      !if ( fsearch(end_mark) ) {
	 pop_mark(0);
	 error("No "+end_mark+" found");
      }
      --begins;
      
      % see if there are any \ends between our \end and the found \begin
      narrow_to_region();
      bob();
      while ( fsearch(begin_mark) ) { ++begins; () = right(1); }
      eob();
      widen_region();
      () = right(1);              % this is, because we could stay on a \end
                                  % and the next fsearch() will find this
   } while (begins);

   () = right(4);                 % go over end{ - \ is skipped inside while
   delete_word();
   insert(new_name);
}

public define latex_newline()
{
   variable indent = env_name_indent();
   switch ( () )
     { case "description":
        call("newline");
        whitespace( indent+1 );
        insert("\\item[]");
        () = left(1);
     }
     { case "itemize" or case "enumerate":
        call("newline");
        whitespace( indent+1 );
        insert("\\item ");
     }
     {
        call("newline_and_indent");
        insert("\\\\");
     }
}
#v-

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]