Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7725231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:53:12+00:00 2026-06-01T04:53:12+00:00

I normally write code with tabs but many python libraries use spaces. Is there

  • 0

I normally write code with tabs but many python libraries use spaces. Is there any way for Notepad++ to automatically detect how the file is formatted and have it automatically switch to using spaces when the file is already formatted that way?

BTW, I know there was already an SO question on how to change Notepad++’s tab format. But it would be better if it automatically changed based on the current file’s formatting.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:53:14+00:00Added an answer on June 1, 2026 at 4:53 am

    If you install the “Python Script” plugin for Notepad++, you can write code to automatically switch between tabs and spaces.

    Here’s how:

    1. In the menu: Plugins -> Python Script -> Configuration, and set Initialization to ATSTARTUP. When Notepad++ starts, the startup.py script will run.

    2. Find startup.py and edit it. On my PC its path is c:\Program Files\Notepad++\plugins\PythonScript\scripts\startup.py, add the following code to startup.py.

    The function buffer_active() is called every time when you switch tab, and guess_tab() checks whether the text is using tab indent or not. You can show the Python console to debug the code.

    def guess_tab(text):
        count = 0
        for line in text.split("\n"):
            indents = line[:len(line)-len(line.lstrip())]
            if "\t" in indents:
                count += 1
        if count > 5: 
            return True
        else:
            return False
    
    def buffer_active(arg):
        editor.setBackSpaceUnIndents(True)
        use_tab = guess_tab(editor.getText())
        editor.setUseTabs(use_tab)
        sys.stderr.write( "setUseTabs %s\n" % use_tab )
    
    notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])    
    notepad.callback(buffer_active, [NOTIFICATION.BUFFERACTIVATED])
    

    This is only an example, feel free to make guess_tab() better yourself, maybe use a global dict to cache the result and speedup the callback function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if there is any cleaner way to write the controller code?
I am writing a module to let me write code in python 3, but
Is there any way to use dynamic keys with the node-mongodb-native driver? By this
I wrote this code. The constructor works normally, but in the destructor I get
Please forgive my attempts at necromancy, but I actually need to write some code
I need to write code to download and run a program, e.g. notepad++ (npp.5.9.3.Installer.exe)
The typical process we use is: Write code Checkin changes with a description of
In Python/C++, I normally use _(string) for i18n string text. for Java, I use
We write apps for contract - we have many apps out there, and they
Normally when I want to query large result set using Mysql I write this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.