OK here is a patch that will make the optKeepSpaces behavior
work the way I want it to.
 
This patch will remove spaces including one line-break
BEFORE an Embperl block iff the opening bracket '[' was preceded only
by spaces on its line and optKeepSpaces is set.
 
So if there is nothing on a line except the beginning
of the Embperl block (and preceding spaces) that line will be
removed from the output, but everything AFTER the perl block
is preserved.
 
Here is an example of the behavior
(from some JavaScript code where I want the indentation
to be preserved):
 
Embperl:
 
[- $optKeepSpaces=1; -]
function test() {
   a=0;
   [$ if ($flag) $]
   a += 10;
   [$ else $]
   a += 5;
   [$ endif $]
   b=5;
}
 
Will give:
 
function test() {
   a=0;
   a += 10;
   b=5;
}
 
without creating any empty lines in-between and without
changing the indentation of some lines.
 
As another example:
 
[$ foreach $key (keys %fdat) $]
<B>[+ $key +]</B>: [+ $fdat{$key} +]<BR>
[$ endforeach $]
Will now yield:
 
<B>key1</B>: val1<BR>
<B>key2</B>: val2<BR>
<B>key3</B>: val3<BR>

As supposed to:
 
<B>key1</B>: val1<BR>
 
<B>key2</B>: val2<BR>
 
<B>key3</B>: val3<BR>

I hope this is useful for other people too. Here is the patch
it is created from epmain.c Embperl version 1.3.3
 
Marcus
 
--------------------------------------------
 
1045,1046c1045,1066
<             /* output until next cmd */
<             owrite (r, r -> Buf.pCurrPos, p - r -> Buf.pCurrPos) ;
---
>             /* output until next cmd */
>             /* 6/19/01 M.Doemling: Modified functionality for optKeepSpaces.
>                If the cmd is preceeded by only spaces on the same line
>                remove them including the preceeding \n, \r\n or \r        */
>             char * p0 = p;
>             if (r -> bOptions & optKeepSpaces)
>                 {
>                 if (*p0 == '[')
>                     {
>                     while (p0 > r -> Buf.pCurrPos && isblank(*(--p0)));
>                     if (*p0 == '\n')
>                         {
>                           if (p0 > r -> Buf.pCurrPos && *(p0-1) == '\r') p0--;  /* for DOS */
>                         }
>                     else
>                         {
>                         if (*p0 != '\r') p0 = p;  /* for Mac */
>                         }
>                     }
>                 }
>
>             owrite (r, r -> Buf.pCurrPos, p0 - r -> Buf.pCurrPos) ;
3189,3190c3209,3232
<             /* output until next cmd */
<             owrite (r, r -> Buf.pCurrPos, p - r -> Buf.pCurrPos) ;
---
>             {
>             /* output until next cmd */
>             /* 6/19/01 M.Doemling: Modified functionality for optKeepSpaces.
>                If the cmd is preceeded by only spaces on the same line
>                remove them including the preceeding \n, \r\n or \r        */
>             char * p0 = p;
>             if (r -> bOptions & optKeepSpaces)
>                 {
>                 if (*p0 == '[')
>                     {
>                     while (p0 > r -> Buf.pCurrPos && isblank(*(--p0)));
>                     if (*p0 == '\n')
>                         {
>                           if (p0 > r -> Buf.pCurrPos && *(p0-1) == '\r') p0--;  /* for DOS */
>                         }
>                     else
>                         {
>                         if (*p0 != '\r') p0 = p;  /* for Mac */
>                         }
>                     }
>                 }
>
>             owrite (r, r -> Buf.pCurrPos, p0 - r -> Buf.pCurrPos) ;
>             }
-----------------------------------------------------------------
 

Reply via email to