Community
    • Login

    Is there any plugin can make NPP realtime-auto-indent?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    16 Posts 5 Posters 1.5k 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.
    • PeterJonesP
      PeterJones
      last edited by

      Isn’t that the default c++ lexer behavior if you have auto-insert and auto-indent from settings checked?

      Yep:

      1 Reply Last reply Reply Quote 2
      • Alan KilbornA
        Alan Kilborn
        last edited by

        It is reasonably possible to get to this point from the above (btw, not sure where the OP’s parentheses are, if he’s talking about C++):

        if ()
        {
        	|
        }
        

        What’s the best method to get the following, aside from some more manual “fussing”?:

        if ()
            {
            |	
            }
        

        I have to add a “:-)” to that, because who would indent C++ that way; except this is actually a real-world use case. :-(

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

          Oops, too much indentation for the caret line in the first code sample. But I think you get the idea. The second one correctly shows the desired caret position.

          1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones
            last edited by

            Based on the OP phrasing of “You’ll get … not …”, I was assuming OP wanted the one that looked closer to the OP animated gif, not the output of the Indent-by-Fold, which “came most closely…, but”.

            1 Reply Last reply Reply Quote 0
            • EkopalypseE
              Ekopalypse
              last edited by

              @Alan-Kilborn said in Is there any plugin can make NPP realtime-auto-indent?:

              What’s the best method to get the following, aside from some more manual “fussing”?:

              I would say depending on the language used, see if there is some
              auto-format utility available which is able to be run from run menu.
              For real-time usage I guess you need to write your own formatter as
              a script or plugin.

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • wjk199511140034W
                wjk199511140034
                last edited by

                Thank you guys, I have tried changing the language
                In C, C ++, JAVA mode, I got what I needed
                But Perl mode doesn’t work, so I have to use plugins
                In fact, this is the first time I use npp to write scripts. Perl is a scripting language, so its make me too lazy to run VS.

                Michael VincentM 1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @Ekopalypse
                  last edited by

                  @Ekopalypse said

                  @Alan-Kilborn said

                  What’s the best method to get the following, aside from some more manual “fussing”?:
                  I would say depending on the language used, see if there is some
                  auto-format utility available which is able to be run from run menu.

                  And that made me vaguely remember @Michael-Vincent does that from an NppExec script; quick search on his posts with “pretty” (*): yep. In this “Python Indent…” thread, Michael lists his NppExec script which launches astyle (c/c++), tidy5 (xml/html), perltidy (Perl), and yapf (Python). SO that’s an example of how to do it on-demand (though not live).

                  (*: my mind associates such things with “pretty print” – fortunately, he happened to use that word; I should try to associate them with “tidy”, which is more likely to pull up perltidy)

                  1 Reply Last reply Reply Quote 1
                  • PeterJonesP
                    PeterJones
                    last edited by

                    @wjk199511140034 said in Is there any plugin can make NPP realtime-auto-indent?:

                    In C, C ++, JAVA mode, I got what I needed
                    But Perl mode doesn’t work, so I have to use plugins

                    You’re right: apparently, each lexer handles auto-indenting differently, and the Perl lexer does not indent when you enter a new level. I thus assume it’s a bug (or design decision) in the Perl lexer module, which is part of the source code inherited from the Scintilla component. To verify, you could download a recent SciTE editor, and see how it auto-indents Perl vs C/C++/Java. If the differences show up there, it’s definitely caused by Scintilla’s codebase; if not, then it might be in the way that Notepad++ calls scinitilla functions for Perl vs C/C++/Java, or it might be still in Scintilla.

                    In fact, this is the first time I use npp to write scripts. Perl is a scripting language, so its make me too lazy to run VS.

                    grumble Perl is a fully featured programming language. Just because a language like C/C++ is compiled and Perl (or Python) are “interpreted” doesn’t mean they aren’t programming languages. In fact, Perl is much more similar to Java in that respect: both are compiled into bytecode (yes, when you run the perl interpreter, it goes through a compile stage to get the initial translation into bytecode), and then those bytecodes are translated into machine code for the particular architecture – in Java by the JVM, in Perl by the perl executable. Because of the intermediate bytecode, Perl is able to easily do some stuff (like on-the-fly program-dependent code generation and nearly-magical levels of code introspection) that other traditional programming languages like C only dream of.

                    wjk199511140034W Michael VincentM 2 Replies Last reply Reply Quote 2
                    • wjk199511140034W
                      wjk199511140034 @PeterJones
                      last edited by

                      @PeterJones said in Is there any plugin can make NPP realtime-auto-indent?:

                      SciTE editor

                      I tried SciTE and when I press Enter between {}, I got

                      {
                          |}
                      

                      C, JAVA, and Perl have the same results, I think maybe I need to change some settings
                      And Perl in NPP, it seems like notepad ++'s bug …

                      PeterJonesP 1 Reply Last reply Reply Quote 0
                      • PeterJonesP
                        PeterJones @wjk199511140034
                        last edited by PeterJones

                        @wjk199511140034 said in Is there any plugin can make NPP realtime-auto-indent?:

                        @PeterJones said in Is there any plugin can make NPP realtime-auto-indent?:

                        SciTE editor

                        I tried SciTE and when I press Enter between {}, I got

                        {
                            |}
                        

                        C, JAVA, and Perl have the same results, I think maybe I need to change some settings

                        I just downloaded SciTE 4.20 (to match our version of the Scintilla component) and ran it: if you type { then ENTER, it moves to the indented; then when you type }, it unindents the }.

                        But you’re right, it doesn’t appear to be solely in the scintilla codebase, because it behaves differently in Notepad++, which means NPP has its own auto-indentation settings.

                        And Perl in NPP, it seems like notepad ++'s bug …

                        It is seeming more that way.

                        Maybe someone else knows more settings to play with in Notepad++; I cannot think of any, but there are some settings I’ve never used, so don’t think of – even though I edited the settings/preferences documentation! :-)

                        If you follow the FAQ to make a bug report / feature request, make sure to include in your report that Perl auto-indent behaves differently than C/C++/Java does, but that SciTE (and thus Scintilla) doesn’t seem to treat Perl separately from those. Be warned, however, that it might have been an intentional design decision, or it may be something that the developers delay for a long time or indefinitely. Also, if you do, please add a link to the issue in this thread.

                        wjk199511140034W 1 Reply Last reply Reply Quote 0
                        • wjk199511140034W
                          wjk199511140034 @PeterJones
                          last edited by

                          @PeterJones
                          Here it is …
                          https://github.com/notepad-plus-plus/notepad-plus-plus/issues/7958
                          Hope it can be fixed soon, I really like npp design UI

                          1 Reply Last reply Reply Quote 0
                          • Michael VincentM
                            Michael Vincent @PeterJones
                            last edited by

                            @PeterJones said in Is there any plugin can make NPP realtime-auto-indent?:

                            But Perl mode doesn’t work, so I have to use plugins

                            You’re right: apparently, each lexer handles auto-indenting differently, and the Perl lexer does not indent when you enter a new level.

                            WHAT?!?! With all the Perl programming I’ve done in N++ in the past I can’t believe I’ve never noticed this. Maybe always using my QuickText plugin which has an if snippet that auto-expands to the proper format:

                            if (  ) {
                                
                                ^[indented to here]
                            }
                            

                            Cheers.

                            1 Reply Last reply Reply Quote 1
                            • Michael VincentM
                              Michael Vincent @wjk199511140034
                              last edited by

                              @PeterJones
                              @wjk199511140034 said in Is there any plugin can make NPP realtime-auto-indent?:

                              But Perl mode doesn’t work, so I have to use plugins

                              What plugin? I couldn’t find one for Perl, only Python Indent, which I use.

                              I shamelessly borrowed the Python Indent code and made “Perl Indent” which does perform how I want ( I think what the OP requested ).

                              if ( some stuff ) {|}
                              

                              I have autocomplete braces on, so when I type “{” I get the closing “}” automatically and the cursor is in between.
                              When I then press “Enter” :

                              if ( some stuff ) {
                                  | 
                              }
                              

                              The plugin creates the indent and moves the closing “}” to the following line.

                              Hopefully it’s only a temporary plugin and this is fixed. There seems to be some movement on the issue you submitted. In fact, someone weighing in (Kered13) who I can’t find on this community seems to be the author of the Python Indent plugin I use (and borrowed for the Perl one).

                              Cheers.

                              Michael VincentM 1 Reply Last reply Reply Quote 2
                              • Michael VincentM
                                Michael Vincent @Michael Vincent
                                last edited by

                                @PeterJones
                                @wjk199511140034
                                @Michael-Vincent said in Is there any plugin can make NPP realtime-auto-indent?:

                                Hopefully it’s only a temporary plugin and this is fixed

                                Looks like the next version fixes this so my Perl Indent plugin won’t be needed.

                                Yay!

                                1 Reply Last reply Reply Quote 3
                                • First post
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors