Menu

New plugin: NppAutoIndent

Harry
2008-08-22
2012-11-14
  • Harry

    Harry - 2008-08-22

    For those poor people who cannot live with block indentation of Notepad++:
    NppAutoIndent plugin has 'smart' indentation for C-style languages, such as C/C++, PHP, Java and such.
    Its the first release so dont expect it to be flawless, and ofcourse it might not be completely to your preferences ;)

    There is NO support for HTML/XML and such, maybe later, tag matching is much more difficult to implement.

    It should be able to coop with Notepad++ auto-indent option, but its probably best to turn it off (even if its just to save a few CPU cycles)

    Get it here:
    http://sourceforge.net/project/showfiles.php?group_id=189927&package_id=288727

    Harry

     
    • Jan Schreiber

      Jan Schreiber - 2008-10-27

      Using 1.2.0 here.
      As far as I see, it only supports K&R style indentation.
      When I type
      if(bla)[CR]
      the next line is indented, although there is no opening brace. Wouldn't it be better if the next line is only indented if there is a { on the line that contains the "if"?
      I think this would support the two most common formatting conventions.

       
      • Harry

        Harry - 2008-10-27

        Could you please download the latest DLL form here:
        http://npp-plugins.cvs.sourceforge.net/viewvc/npp-plugins/NppPlugins/NppAutoIndent/build/
        (click on filename, then the download link of the topmost entry)
        and see if it resolved your trouble? The were some huge bugs with brace matching and locating.

         
        • Jan Schreiber

          Jan Schreiber - 2008-10-28

          Harry, thanks for the quick reaction. The indent plugin works pretty much as I expect it now. On one of the two XP machines I installed it to today it crashed N++ the first time I started it, but then it worked fine.
          However, one little thing: There is an extra indentation after "},[CR]" of which I'm not sure it's intended. Screenshot: http://localhostr.com/files/80a9b0/harry.png

           
          • Harry

            Harry - 2008-10-28

            it happens becauses it sees the , as a line that needs to be continued so to speak, so it indents.
            Its like typing
            if (A || B,
            ____||C || D)
            ____doSomething();

            comma meaning there was more to follow. To me the comma looks syntactically incorrect and therefore I cannot guarantee NppAutoIndent to work correctly. It does the best it can (I hoften have 'work in progress' lines as well) but you can only guess that much ;).

            Can the crash be related to the presence or absence of the NppAutoIndent.inf file?

             
            • Harry

              Harry - 2008-10-28

              Just realising .gm files arent Java, so the syntax might be right, but its not C-style, and thats what the plugin was fore (you probably had to enable the override didnt you? ;))

               
            • Jan Schreiber

              Jan Schreiber - 2008-10-29

              Never mind the comma if it looks right for you, I was just asking. The language I had in mind all the time is GameMonkey: http://www.somedude.net/gamemonkey/ It is very, very similar to JavaScript imo, but then I am definitely not an expert. And yes, I had to enable override of course. :)

              I certainly had no NppAutoIndent.inf file when I installed the plugin. Should I have had?

               
              • Harry

                Harry - 2008-10-29

                Normally speaking no, it is created on startup. But since you experienced the crash on the first start, it could have something to do with that. Maybe there was some corrupt data in it from an older version. If its not happening again, then im not going to give it much priority :)

                 
    • Harry

      Harry - 2008-10-27

      It supports K&R and Allman if I look at
      http://en.wikipedia.org/wiki/Indent_style
      It should automatically put the opening brace at the same level as the opening statement in case of Allman style (brace at a new line).

      The reason it indents the next line is to make single conditional statements clearly visible as such, as is done in VS2003 (which I partially based it off, I sometimes struggle with switch inside switch in VS2003, so I did it a little different, same for classes etc).
      Roughly speaking, it'll indent at a new block with brackets, or if a line with a statement is not closed (with ';'), in which case itll all the following lines by 1 untill the final ';'.

      BSD KNF requires both soft and hard tabulators, but Scintilla doesn't really have support for that which means having to add another tab settings, which I'm not very fond of (and I'm not going to do it).

      There are many settings relating to indenting which I'm not going to support, because it requires loads of changes and a huge user interface, which goes beyond the point of the plugin, which is adding a simple yet smarter indent to Notepad++.
      If NppAutoIndent can do something that kind of looks like what you need but just isn't quite it, you can try working with it and then use an Indenting tool to make it right. I've seen one *but cant remeber the name) that can even regulate location of brackets and whitespacing, as well as comments.

      Indenting HTML is even harder since you have to match the tags, thats why it isnt in there.

      Also, NppAutoIndent has a block indenter which is similar to the one Notepad++ has, but doesnt copy the last indent but rather the last line that actually has text. The other option only copies the previous line, so removing the indent will keep it that way untill you add a new one.

       
    • Jan Schreiber

      Jan Schreiber - 2008-10-27

      Thank you for your response. My description was a little inaccurate. In fact, I end up with the last closing brackets indented one or two levels too far:

      if (test)
      {
          testme();
          if(blah)
          {
              testme(1,2);
              while(test)
              {
                  test = 1;
                  etc = 2;
              }
              }
              }

       
      • Jan Schreiber

        Jan Schreiber - 2008-10-27

        Sorry, the indentation isn't visible. Here's a file: http://localhostr.com/files/c09bb2/new2.c

         
        • Harry

          Harry - 2008-10-27

          Then that is a bug, ill take a look after it :)