Programmatically saving of field values

I’m still worried about this thing:
the software value of the field is stored as follows:

$ doc.set ($fieldName, $fieldValue)
$ doc.save ()

The document saving process is implicit and is contrary to UX: the user has not confirmed explicitly saving the document by the Save action and this may cause problems with multi-user work on the document.
Also useless temporary versions of the document are created.

Question: how to save the field values ​​programmatically, but only when the user is explicitly acting Save?

Thanks.