Overwrite commands via cli_start

Let’s say I want to change a command slightly while still utilizing a code irrespective of updates. For example, _display. I want to automatically copy the code of _display, and use my own _display instead while still using the _display code.

I tried m _display:“code_block”$$_display

It didn’t work.

Why not just use your own _display within your custom *.gmic while also comparing the code after each update to see if any changes were made. I believe the previous stdlibs are still there on your computer.

As for your issue, it is about the command order. It could be that $$_display is not retrieving anything because either the syntax is wrong or the stdlib _display has not yet been accessed.

The reason is that I’m not the one maintaining _display.

But, I do have a workaround using batch file.

Ok this one is a bit tricky :slight_smile:
Command command (aka m) interprets backslashes in the specified string argument as a way to insert specific codes (e.g. \n is replaced by 10).
The command _display is quite complex and has backslashes in it, and you don’t want to make command m interprets those. The solution is to use the (rarely useful) syntax {/string}, to make sure the backslashes inside the string will be actually backslashed (so a backslash in the original string will be kept when passed to the m command).

The solution is then:

foo : 
  m "my_display : "$$display
  m "_my_display : "{/$$_display}

Thanks, it works. I did this:

cli_start :
  # More Code Here
  m "_display: if ['$$cli_end']!=0 cli_end fi "{/$$_display}
cli_end: blur 100

To solve the github issue I talked about before. Now, I don’t think I need to do the batch file work around.

Now, I can just load a .gmic file instead and automatically execute __main__ command within .gmic files.

So, I inserted this into user.gmic:

cli_start :
  # More Code Here
  m "_display: if ['$$cli_end']!=0 cli_end fi "{/$$_display}
cli_end: if ['$$__main__']!=0 __main__ fi

Maybe to make things more clear, this example shows how a backlashed character (\n) is substituted in the m command.

foo :
  m "bar : x=3\ny=4"

defines a command bar that is valid:

 gmic foo v + bar
[gmic]./ Start G'MIC interpreter (v.3.3.6).
[gmic]./ Increment verbosity level (set to 2).
[gmic]./bar/ Set local variable 'x=3'.
[gmic]./bar/ Set local variable 'y=4'.
[gmic]./ End G'MIC interpreter.

Hmm, my idea does work, but it seems you need a image to load _display and thus the cli_end trick would work in that case. Hmmm, not sure what to do at this point besides suggesting a change into how importing .gmic file work for those cases where you don’t want images before importing gmic. But, I guess I can do this trick with input too, but can’t see how it’s possible.

It would be nice if input_gmic was a command that calls input_gmic.

EDIT: Never mind about modifying input via cli_start which means I’d like a input_gmic command which has a built-in input_gmic.