I want some files to be read-only when I open them. Maybe using some kind of header would work?
Parsing the extension would work too but I want to apply to, for example, some ".txt" files so is not very good to apply this rule to all "txt" files.
I want some files to be read-only when I open them. Maybe using some kind of header would work?
Parsing the extension would work too but I want to apply to, for example, some ".txt" files so is not very good to apply this rule to all "txt" files.
If you can add a header to your files, the following should work (it should be the first line in the file):
-*- buffer-read-only: t -*-
If there is a comment convention (e.g. '# ' for a shell script), you should put it in a comment:
# -*- buffer-read-only: t -*-
For shell scripts that must have a hash-bang line as the first line, you can put the header above on line 2: that's the only exception to the rule AFAIK.
For more details, see File Variables which also describes a method to specify file local variables at the end of a file.