Merge/Command Feature Request

Is it possible for g’mic scripters not to have to collapse lines into one single line to get merge to work as it should?

Right now, I have to collapse this after expanding for example for the tile project I’m working on. If I collapse it, it’s harder to read and thereby more efforts is needed to work with.

m "out2display : skip ${""1=},${""2=},${""3=},${""4=1},${""5=1},${""6=},${""7=} 
if narg($""1) 
    if $""1 $__bg rv blend alpha fi 
fi xalp 
if narg($""6)||narg($""7) 
    if narg($""2)&&narg($""3)&&narg($""4)&&narg($""5) 
    f. begin(
        xc=$""2;
        yc=$""3;
        tw=$""4;
        th=$""5;
        psx=floor(xc/$__min_tile)*$2;
        psy=floor(yc/$__min_tile)*$2;
        border=2;
        border_left=psx+border-1+narg($""7);
        border_right=psx+tw-border;
        border_up=psy+border-1+narg($""7);
        border_down=psy+th-border;
        boundx=psx+tw;boundy=psy+th;);
        if(narg($""6)
            ,tracker=(x>=psx&&x<boundx)&&(y>=psy&&y<boundy)?((x<=border_left||x>=border_right)||(y<=border_up||y>=border_down)?((i<128?$""6-i:255-i)<128?0:255):i):i;
            ,tracker=i;
        );
        if(narg($""7)
            ,(!(((x%$2)==0||(y%$2)==0)||(x==(w-1)||y==(h-1)))?tracker:(i>128?$""7-i:255-i)),
            tracker;); 
    fi 
fi
"

I see that your fill command has a multiline formula as an argument, and that you didn’t encapsulate it between double quotes. That’s probably your problem.

In G’MIC, a blank character is a command/argument separator, so what you wrote above is not correct (you have CR characters that are considered as blank in your fill argument).
Here, basically, the G’MIC interpreter see “begin(” as the argument of fill, then try to interpret xc=$2 as a new command, and so on.

Honestly, it is not really recommended, when you have long commands like this, to define them with command command. Why not just putting it apart ?
Like this:

```
m "out2display : _outdisplay1 $*"
...

_outdisplay1 :
  if narg($1) 
    if $1 $__bg rv blend alpha fi 
  fi xalp 
  if narg($6)||narg($7) 
    if narg($2)&&narg($3)&&narg($4)&&narg($5) 
    f. "begin(
        const xc=$2;
        const yc=$3;
        const tw=$4;
        const th=$5;
        psx=floor(xc/"$__min_tile")*$2;
        psy=floor(yc/"$__min_tile")*$2;
        const border=2;
        border_left=psx+border-1+narg($7);
        border_right=psx+tw-border;
        border_up=psy+border-1+narg($7);
        border_down=psy+th-border;
        boundx=psx+tw;boundy=psy+th;);
        if(narg($6)
            ,tracker=(x>=psx&&x<boundx)&&(y>=psy&&y<boundy)?((x<=border_left||x>=border_right)||(y<=border_up||y>=border_down)?((i<128?$6-i:255-i)<128?0:255):i):i;
            ,tracker=i;
        );
        if(narg($7)
            ,(!(((x%$2)==0||(y%$2)==0)||(x==(w-1)||y==(h-1)))?tracker:(i>128?$7-i:255-i)),
            tracker;); "
    fi 
  fi

I attempted that, but it didn’t work. However, I found a easy workaround via highlighting and replacing text within KDE Kate editor. For each selected text that is the same within the compressed and expanded, they get replaced, basically. Thanks, anyway.

It should work, I’ve used this syntax in most of the commands needing complex math expressions so far, and it always worked. Workarounds that bypasse the adapted solution are generally not very nice :slight_smile:
I’ve not a lot of free time right now, but I may look at your code some day to see if I can help.