Is there any plugin can make NPP realtime-auto-indent?
-
Isn’t that the default c++ lexer behavior if you have auto-insert
and auto-indent from settings checked? -
Isn’t that the default c++ lexer behavior if you have auto-insert and auto-indent from settings checked?
Yep:
-
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. :-(
-
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.
-
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”.
-
@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. -
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. -
@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), andyapf
(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
) -
@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 pluginsYou’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.
-
@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 … -
@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.
-
@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 -
@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.
-
@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.
-
@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!