Menu

Auto indent replaces spaces with tabs

2007-05-16
2012-11-13
  • Nobody/Anonymous

    I edit some files that do indentation with spaces some files that do indentation with tabs.  I prefer tabs for new files that I create, so I set Notepad++ to use tabs.

    If I'm in a file that uses spaces for indentation, and I hit enter at the end of a line I get a new line that is auto indented.  However, Notepad++ does not respect the indentation style of the previous line.  For example, if the line had an 8 space indentation, then the new line is given a two tab indentation.

    I would prefer for auto indent to work like this:
    1.) User hits enter at the end of a line.
    2.) The indention string (any combination of spaces and tabs) is found on the line.
    3.) A new line is created that starts with the exact indention string from step 2.

    Also if you hit enter on an empty line, then the next line should be empty.  Notepad++ shouldn't search for the previous non-empty line and use that.  That behavior is quite unintuitive.  It should at least be optional.

    Is there an easy way to do this without creating my own personal fork of Notepad++.  I really don't want to do that.

    Thanks,
    Josh

     
    • Rocky

      Rocky - 2007-05-17

      The option whether to use tabs or spaces for the 'tab' symbol is global (Settings>Preferences>MISC>Tab settings>Replace by space).

      For first line identation you can also use 'TextFX>TextFX Edit>Leading space to tabs or tabs to spaces' (this depends on the above option).

      Regards,
      Rocky

       
      • Nobody/Anonymous

        Neither of those options do what I want.

        If I'm editing a file that uses space based indentation, I need to use space based indentation too.  I'm fine with having to use the space bar for this, but I don't want Notepad++ to mess with already established leading spaces.

        For example:
        1.) I'm editing a document that uses space based indentation.
        2.) I hit enter on a line with an 8 space indent.
        3.) Now I'm on a new line with a two tab indent.
        4.) I hit backspace twice and type 8 spaces.
        5.) Now my indent matches the previous line.

        That's 10 keystrokes whenever I hit enter.  It is very annoying.

        On space-based indentation files I often find and replace tabs before saving, but having to do that isn't convenient either.

        I guess I could change the global setting whenever I open a file with different indentation conventions, but that is tedious too.  I can't just change all the files to use the same convention, it isn't under my control.

        Thanks,
        Josh

         
    • MJG

      MJG - 2007-05-20

      I'd also like to have this feature; it not only messes up version control files to change them, but the folks that have their own (different) settings get mad and change it all back.*

      It's hard to keep everyone happy, and I'll bet this is a bit of work to design and code.  While I've had this feature in other editors like Borland's Smart Tab or Codewright's Auto Indent, they had quite a few (paid) programmers working on their projects.  A fork might be worth the effort if you are in a hurry.  --Joel

      *Personally, I'd make it a rule to use tabs, and then everyone could set tab spacing to whatever they wanted.  But I recognize that others have their own very strong opinions on the subject.

       
      • Nobody/Anonymous

        This isn't necessarily a lot of work.  I only care about the auto indent behavior.  If I hit enter on a line with some indentation, then give me a new line with *exactly* the same indentation.

        It would be more difficult it you want to dynamically change the behavior of the tab key.  I don't really care about that.  I'm fine with using the space bar in a file that uses spaces for indentation.  I always have "show white space" on so I know what kind of file I'm working with.

        I know some editors attempt to decide the indentation scheme of the file and mimic it whenever you hit tab.  I'm not asking for that.

        I searched through the code, and it was easy to find where it would be changed.  I just don't want to have to do that.  Is it possible that a plug-in could do this?

        Thanks,
        Josh

         
        • Martin Sherburn

          Martin Sherburn - 2007-08-03

          A plugin sounds look a good idea. I think the best solution is as you say other programs: "attempt to decide the indentation scheme of the file and mimic it whenever you hit tab". This wouldn't be hard to implement, for each line in a file count the number of lines that start with a space and the number that start with a tab. If the space count is higher assume spaces otherwise assume tabs. This accounts for files that may have mixed spacings taking the one that occurs most frequently.

          I will look into how to write plugins for notepad++, if its not too much trouble I'll do it.

           
MongoDB Logo MongoDB