> I will see whether I can do something along these lines.
Thank you. I'm just spewing out ideas here, you know the code better and what will and will not work.
> Perhaps changing the order: First try
> to insert the file contents, and if this errs out, a call with
> file-exists-p in order to raise the error. I'll play with this.
Yes, this would be a better way from my point of view. I don't care how slowly (unless it is like 50 times slower) it fails, that is an unlikely case. The most likely one, when the file exists, should be the benchmark.
> Doing it asynchronously would require a second connection to the remote
> host. Performance would rather degrade.
Maybe not really asynchronously, just let it return early, not waiting for the result? I'm not sure how TRAMP receives responses, but can it just keep executing commands sequentially, as now, but give control back to the caller in case of commands where the result doesn't really matter (cleanup, e.g. deleting a temporary file). Of course, this means that if an "important" command is issued right away, it has to wait for the response to the previous inessential command. But when such an inessential command is the last in a batch, this waiting would be effectively merged with Emacs' idling in the normal UI command loop, making things more responsive for the user.
> One thing you could do w/o code change is to change the value of
> remote-file-name-inhibit-cache.
Thank you for the hint, will try.