FileType NEW=.txt **Encoding?**

is it possible to assign file encoding with the FileType NEW=.txt command??

I quickly made a list of files .ahk via dopus's Ctrl + O started moving stuff around and it was all broken...
took me a while to figure out wtf? ha
the file were created with ASNI encoding. the project using special symbols for parsing, 🡱 ¦ ¢ were converted to ?? because I need UTF-8-BOM

thank
x

You could set up a new file template via the registry so that new text files have a UTF-8 BOM at the start (which will affect both Opus and File Explorer, and anything else that shows the Windows "New" menu), but there will be times when you don't want that as well, so I'm not sure it's the way to go.

Another option is creating an Opus button or hotkey which creates (or, easier, copies) a file with just a UTF-8 BOM in the current directory, e.g. using the Copy command.

Normally, new empty text files will be zero bytes in size; completely empty. There's no data in them to encode, and it's usually up to your text editor which encoding it uses when data is added to the file.

IMO the best thing to do is look at the options in your text editor that let you change the default encoding (or switch to a new text editor if yours doesn't have that).

AFAIK FileType NEW creates empty files.
There's no such thing as encoding in empty files ...
The encoding will arrive when a) you add characters, and b) you save the file. On saving, encoding (if any) happens.
It may start on a if you need some special characters.
But all this relies on the text editor you use, not on Opus creating a 0 byte file.

EDIT: This is only true with text empty files in the sense of 0 bytes files.

Maybe you could try to build a new button to create the file with only the UTF-8 BOM as suggested by Leo but directly in the button code. It seems at least possible with powershell (see https://stackoverflow.com/questions/31771793/write-an-empty-file-with-just-the-utf-8-bom) with a call in the likes of:

powershell -c "[io.file]::WriteAllText('.gitignore','',[System.Text.Encoding]::UTF8)"

You'd have to work out the syntax to replace the '.gitignore' with the new filename you want. It's going to be a little heavier if you first want to check against an already existing filename with the same name and rename accordingly. Further down the SO post, there's also a JScript solution, so maybe a full JScript solution to both check for filename clashes and then creating the file and enter inline rename afterwards could be a solution.
This would prevent from doing things in the registry.

You'd still have to use a text editor that recognizes automatically the BOM and acts accordingly (for instance standard Notepad might not be best suited for that)

both options are viable. and yes, I need utf-8 for the program. and utf-16 le bom for its .ini's ha! so yeah. I though of tweaking the shellnew output in the registry but yes. that will bite back too.

that might be the easist and at least now more aware of the coding. my TE, crazy enough I still love notepad++. sucker for punishment? haha, it saves as utf-8-bom for me when saving new at least.

thanks