Community
    • Login

    Adding the Extension of PRG in the Tab Settings list

    Scheduled Pinned Locked Moved General Discussion
    24 Posts 4 Posters 5.9k 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.
    • Alan KilbornA
      Alan Kilborn @Lycan Thrope
      last edited by

      @lycan-thrope said in Adding the Extension of PRG in the Tab Settings list:

      I was bit again by that indentation bug, even in PythonScript, obviously it does it, too.

      I’m a bit disturbed by this.
      There is no indentation bug, just indentation rules to follow.
      And PythonScript is just a plugin version of an embedded Python interpreter, so any files created for use with it must also follow Python’s indentation rules.
      I wish I could help further, but I really don’t know how to.

      1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Alan Kilborn
        last edited by

        @Lycan-Thrope ,

        There is no indentation problem with what @Alan-Kilborn originall posted. I just created a fresh Notepad++ with PythonScript, copy/pasted exactly what he had into TabSettingsOverrideByExtension.py, and ran that. When I opened a example.prg file, it properly used 3 spaces when I typed a tab in the example.prg file.

        My PythonScript console looks like:

        Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]
        Initialisation took 15ms
        Ready.
        setting up for files with extension prg
        

        if I switch to a different tab, then back to example.prg, I see another setting up for files with extension prg in the console.

        Similarly, if I exit out and come back in, then open up example.prg without running the script first, it properly uses the default TAB character with a width of 4 characters.

        If I create a user startup.py with the exact contents:

        # -*- coding: utf-8 -*-
        from Npp import *
        import os
        
        import TabSettingsOverrideByExtension
        tsobe = TabSettingsOverrideByExtension.TSOBE()
        

        when I restart Notepad++, I get no errors in the PythonScript console, and if I open example.prg, it does 3-space when I hit the TAB key.

        So Alan’s example script works exactly as described. You do not need to edit anything after you paste in the exact contents from the black box and save. It just works right, with correct indentation.

        Alan KilbornA 1 Reply Last reply Reply Quote 3
        • Alan KilbornA
          Alan Kilborn @PeterJones
          last edited by

          @peterjones said in Adding the Extension of PRG in the Tab Settings list:

          if I switch to a different tab, then back to example.prg, I see another setting up for files with extension prg in the console.

          Oops, I guess I didn’t mean to leave the print statement in there… But perhaps it was helpful here.

          So the reason it “sets it up” everytime you switch tabs is that upon the tab change, Notepad++ itself will reset the tab settings…so the script code has to override that and set it up the way it wants it. (Just some background info).

          BTW, the script isn’t “perfect”. If you rename a file that has a non .prg extension so that it has that extension, it will probably take a tab switch away and a return to get it to take effect. Also, once tab characters are “in” a file, this script won’t remove them, even if the configuration is set to use-spaces. These limitations could be worked around, with more code.

          1 Reply Last reply Reply Quote 3
          • Lycan ThropeL
            Lycan Thrope
            last edited by Lycan Thrope

            Yes, I get it, it’s not an indentation bug, I must have done something wrong. :-)

            So I’ll have to mess with it to see what I did wrong. I will try creating a user startup.py and put it where ever it goes (reading the instructions on file locations I have here somewhere), and remove it from the machine startup.py. This is kind of the thing, I know I’ve screwed it up somehow and I don’t understand the indentation rules for Python…I’m am only learning and dabbling at the moment, and indentation was never a critical part of any programming I’ve ever done, so it’s new to me. I’ll get it. Thanks for the pointers and the tests.

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