Set coding for .txt files permanently to OEM850
-
When I open an existing .txt file, I always have to change coding to Western European OEM850 in order to get German characters äöß displayed correctly.
How can I change Notepad++ settings so that this coding is set as default?Note: this is not a problem, when I create a *.txt file with notepad++. Then everything is ok.
But when I create a file from within a command prompt in Windows e.g., the display is not correct.Example:
DOS prompt: cmd /? > text.txt
This command creates a file text.txt, which contains äöü (Windows is set to German language). Opening this file in Notepad++ gives odd characters unless coding is changed to Western European OEM850. -
but this could affect other files that are encoded in different format,
so may I advise another solution, why not creating a batch file which sets the encoding of the cmd to utf-8?
Something like@echo off rem change encoding to UTF-8 chcp 65001 cls
Then create a link to call
cmd.exe /k NAME_OF_THE_BATCH_FILE
Within this shell you can run your commands which will produce utf-8 output.
Cheers
Claudia -
Thank you, Claudia.
Your solution works - of course, however I´d prefer a sloution, which changes default behaviour of NP++.
The reason is simple - now in about 95% of my .txt files I have to change codepage, only the rest would be affected negativly by a change in NP++.
So if there is a chance for a different solution, please give me a hint.
Thanks again, Pete
-
An option to automatically set the character-set was requested for the EditorConfig Notepad++ plugin. Not sure though if it’s in the latest release (v0.3.1.0). It might be a solution for you.
-
@MAPJe71
Thank you for your hint - but I´m afraid, setting up EditorConfig Notepad++ plugin is far beyond my skills of operating a text editor. -
Pete,
as there is no builtin function the only other way I see is to use a script like below.
def callback_FILEOPENED(args): bufferid = args['bufferID'] _file = notepad.getBufferFilename(args['bufferID']) if _file[-4:] == '.txt': notepad.activateBufferID(bufferid) notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850) notepad.clearCallbacks([NOTIFICATION.FILEOPENED]) notepad.callback(callback_FILEOPENED, [NOTIFICATION.FILEOPENED])
To make this run it would require to install python script plugin (preferable the msi package, not via Plugin manager),
and add the lines to the end of the autostart.py.This script would check on load of a file if the extension is .txt and if so, set the oem850 charset.
Cheers
Claudia -
Thank you Claudia.
I got a partial sucess.Following your instructions I added the text above to a file startup.py (I didn´t get a file autostart.py).
Double clicking a *.txt file works for the 1st file in Multi-Instance mode, but not for the 2nd or further files.
But I´m quite happy with that solution
Cheers
Pete -
omg - seems yesterday wasn’t my day.
You are absolutely right, it has to be startup.py, there is no autostart.py.
And in addition I forgot to tell you that you need to change the configuration
from LAZY to ATSTARTUP. (Plugins->Python Script->Configuration->Initialisation:)
Sorry for being so imprecise.I just tested
- double click on single *.txt file ->oem850
- selected multiple *.txt, right click edit with notepad++ ->every file has been set to oem850
- started 2nd npp and double click on txt file -> oem850
used 2nd npp and open file using file dialog -> oem850
Hopefully it will work for you as well.
Cheers
Claudia -
Claudia,
thanks again for your very fast reply.
This ATSTARTUP issue was not really a problem for me.I´m sorry too - I was also very imprecise.
Things are much more complicated, than it seemed to be during this discussion.A couple of more things have influence on the behaviour of NPP with my files:
-
Our ways of operationg NPP seem to be different, this influences the behaviour of NPP. I always start NPP by double-clicking a *.txt file (this is, how you tested this too). I have set NPP to Multi-Instance mode, so double clicking a 2nd and 3rd *.txt file starts a second and third instance of NPP. This works as I like it, but this is a bit different to your way of operating NPP.
-
and this has big influence: I use NPP Portable in a PortableApps environment. With this I have 2 *.exe files, which I can set as a Standard to open .txt files on doubleclick in my Windows10 x64 operating system:
-
list item1st file is D:\PortableApps\Notepad++Portable\Notepad++Portable.exe
-
list item2nd file is D:\PortableApps\Notepad++Portable\App\Notepad++\notepad++.exe
When I set the 2nd file as standard in Windows, the first .txt file opens with OEM850 codepage set correctly. Doubleclicking the next and further .txt files open NPP in seperate instances, but OEM850 does not work. Additionally I get a very strange behaviour of NPP when I modify any NPP settings (such as show line numbers or bookmark display), so I think I shouldn´t use this 2nd file as a standard in Windows.
When I set above 1st file as Standard in Windows, NPP works correctly regarding change of settings - however the Python script does not work at doubleclick on .txt files (not even for the first file). The PY script is active, because when I drag a second file into a NPP window (opend by doubleclick on 1st .txt file), this 2nd file is opened (in a second tab of course) with codepade changed to OEM850.
Claudia, you see, this is very complicated. I doubt, that there is a simply solution. I think, it would be best for me to try the whole thing again with an installed version of NPP (though I like that PortableApps applications very much).
Thanks again for your help, which I appreciated very much.
Cheers Pete -
-
Claudia,
an addidtional remark:
in the meantime I downloaded NPP.msi and installed it in a Win10 virtual machine (in the way, programs are installed normally in Windows), added Python script and edited sartup.py.Result:
Drag´drop a .txt file to an open NPP window works (I get OEM830 codepage).
Doubleclicking that .txt file does not work (no OEM850 settings)I have no idea, why doubleclick does not work, though you tested this.
Cheers Pete
-
Pete,
you are right - strange behavior.
I installed portableapps and notepad++ and discovered the same thing.
It looks like the file has been already loaded before python script plugin
receives the ready callback.
To overcome this I have added the ready callbackdef callback_FILEOPENED(args): bufferid = args['bufferID'] _file = notepad.getBufferFilename(args['bufferID']) if _file[-4:] == '.txt': notepad.activateBufferID(bufferid) notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850) def callback_READY(args): _file = notepad.getCurrentFilename() if _file[-4:] == '.txt': notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850) notepad.clearCallbacks([NOTIFICATION.FILEOPENED]) notepad.clearCallbacks([NOTIFICATION.READY]) notepad.callback(callback_FILEOPENED, [NOTIFICATION.FILEOPENED]) notepad.callback(callback_READY, [NOTIFICATION.READY])
It looks like it works as long as you open only one file at a time.
Whenever you select multiple files then something even weird happens, the configuration
changes from ATSTARTUP to LAZY and nothing get executed at all. ???As you said, your way to work is to double click on files it should do it for you - even with portable apps.
Fyi - I installed windows 10 as guest in virtualbox and did the same test with an installed npp and it was working for me.
But hopefully you can live with the other solution otherwise let me know.Cheers
Claudia -
Claudia, that´s perfect!
I added some code, so it´s working now also for .ini and .log files. I portable version of NPP I now can open as many files as I want, they show up correctly.
Many thanks! I´m happy now.
Cheers PeteFor those, who want to mak same modifications: here is my extension of STARTUP.PY
def callback_FILEOPENED(args):
bufferid = args[‘bufferID’]
_file = notepad.getBufferFilename(args[‘bufferID’])
if _file[-4:] == ‘.txt’:
notepad.activateBufferID(bufferid)
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)
elif _file[-4:] == ‘.ini’:
notepad.activateBufferID(bufferid)
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)
elif _file[-4:] == ‘.log’:
notepad.activateBufferID(bufferid)
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)def callback_READY(args):
_file = notepad.getCurrentFilename()
if _file[-4:] == ‘.txt’:
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)
elif _file[-4:] == ‘.ini’:
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)
elif _file[-4:] == ‘.log’:
notepad.menuCommand(MENUCOMMAND.FORMAT_DOS_850)notepad.clearCallbacks([NOTIFICATION.FILEOPENED])
notepad.clearCallbacks([NOTIFICATION.READY])
notepad.callback(callback_FILEOPENED, [NOTIFICATION.FILEOPENED])
notepad.callback(callback_READY, [NOTIFICATION.READY]) -
Claudia,
I forgot to mention, that this is also working in the installed version of NPP.
So all working absolutely perfect!
Thanks againCheers Pete