Community
    • Login

    Set coding for .txt files permanently to OEM850

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 3 Posters 8.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • PeteM92P
      PeteM92
      last edited by

      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.

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @PeteM92
        last edited by

        @PeteM92

        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

        1 Reply Last reply Reply Quote 0
        • PeteM92P
          PeteM92
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • MAPJe71M
            MAPJe71
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • PeteM92P
              PeteM92
              last edited by

              @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.

              Claudia FrankC 1 Reply Last reply Reply Quote 0
              • Claudia FrankC
                Claudia Frank @PeteM92
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • PeteM92P
                  PeteM92
                  last edited by

                  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

                  Claudia FrankC 1 Reply Last reply Reply Quote 0
                  • Claudia FrankC
                    Claudia Frank @PeteM92
                    last edited by

                    @PeteM92

                    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

                    1 Reply Last reply Reply Quote 0
                    • PeteM92P
                      PeteM92
                      last edited by

                      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:

                      1. 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.

                      2. 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

                      1 Reply Last reply Reply Quote 0
                      • PeteM92P
                        PeteM92
                        last edited by

                        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

                        Claudia FrankC 1 Reply Last reply Reply Quote 0
                        • Claudia FrankC
                          Claudia Frank @PeteM92
                          last edited by

                          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 callback

                          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)
                          
                          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

                          1 Reply Last reply Reply Quote 0
                          • PeteM92P
                            PeteM92
                            last edited by

                            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 Pete

                            For 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])

                            1 Reply Last reply Reply Quote 0
                            • PeteM92P
                              PeteM92
                              last edited by

                              Claudia,

                              I forgot to mention, that this is also working in the installed version of NPP.
                              So all working absolutely perfect!
                              Thanks again

                              Cheers Pete

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors