Menu

Smarter auto-indent

Alex
2008-01-17
2012-11-13
  • Alex

    Alex - 2008-01-17

    Hi,

    It would be nice if auto-indent was smarter, similar to Visual C++.

    For example, if you have the following code:
    if (...)
    {
    ^ and you press Enter after the brace, NP++ won't indent an extra level, when it should.

    Likewise, when you have:
    if (...)
    {
       // something
       } <-- if you press '}' there, it should go back a level, since you are closing the scope, but NP++ stays where it is.

    NP++ is a great editor, but it seems to have only very primitive auto-indenting support.

    I'd suggest you have a look at how Visual Studio's indenting works and pinch a few ideas here and there :)

    Good luck.

     
    • Nobody/Anonymous

      I'd love this in Notepad++. I think it should be fairly simple:

      - Line breaking right after opening a { brace adds one tab to the added line.
      - Starting a line with } removes one tab on that line.

      Also, it's annoying when it this happens:

      - There's a block of indented code.
      - I add a line break, then I remove the automatically added tab.
      - I add another line break and it tabs it again.

       
    • Nobody/Anonymous

      I would suggest that this not be implemented. As a C developer I would write:

          if (...)
          {
              /* something */
          }

      But, I know people that would write:

          if (...) {
              /* something */
          }

      And others still that write:

          if (...)
              {
              /* something */
              }

      Yes, the style "standards" say the first way is the right way, and Microsoft's tools help enforce it, there's no reason to force it on everyone just because.

       
      • qwesp

        qwesp - 2008-01-17

        There is possibility to implement first two scenarios of use. Simply implement the scorp007's feature only if the begining { has only white space before it.
        So
        if(not only whitespace) {
        no use of inteligent indentation or
            justify from beginning + one tab (better)

        if(line below only whitespace)
        {
            justified succesfully
        }

        The third scenario would fall into the second one. That should't be a big problem for

         
      • Nobody/Anonymous

        Sorry ... spacing is buggered there.

        Bob

         
    • qwesp

      qwesp - 2008-01-17

      &nbsp; test

       
    • qwesp

      qwesp - 2008-01-17

      The spacing is ok if you are subscribed to receive emails, you can see it correctly in your email client. But anyway, i dont know how to make it look right here.

       
      • Nobody/Anonymous

        You could use the underscore character _ to represent each single space character, or perhaps another character that even allows simply counting the number of occurrences (~ ?)

         
    • Nobody/Anonymous

      Sorry, but no.

      You can just go to TextFX - Edit - Autoindent C++ code if you want that. Or, use the VB editor!

       
    • Nobody/Anonymous

      "Sorry, but no.

      You can just go to TextFX - Edit - Autoindent C++ code if you want that. Or, use the VB editor!"

      Or you can not be so negative and suggest that someone looks at the source code and see what options are avaliable. If only there was a plugin system in NP++ that this stuff could be written in...oh...hang on...thats right....there is one :P

      Keith

       
    • Alex

      Alex - 2008-01-18

      @"Nobody/Anonymous" who pointed out various indent styles:

      You have a valid point, but note that VS does not mess around with your coding style. It just adapts to it.

      If you want to have your opening brace on the same line as the if() {, so be it, VS will still recognize it and indent accordingly.

      Have a play with the express edition to see what I mean.

       
    • Alex

      Alex - 2008-01-18

      Not to mention, if you don't like auto indent, you can always turn it off...