On 14 Oct 2019, at 20:11, Martin Wilhelm Leidig wrote:

Why would forbidding to write the file back remove anything?

That is not what I understand by a read-only mode. If a file is opened as read-only, the user should not be allowed to make any edits.

If you are happy with just a warning/dialog during save, you can chmod u-w a file, and TextMate will not allow you to save it without first confirming that you want to make the file writable.

You can make a command that toggles the w flag for the current file and bind it to a hotkey, for example something like:

#!/bin/sh

if test -z "$TM_FILEPATH"; then
  echo "There is no file"
elif test -w "$TM_FILEPATH"; then
  chmod u-w "$TM_FILEPATH" && echo "$TM_DISPLAYNAME is now read-only"
else
  chmod u+w "$TM_FILEPATH" && echo "$TM_DISPLAYNAME is now writeable"
fi

Set the command’s output to show as tool tip, then you get informed about the new state of the current file after toggling ro/rw mode.