Beautify your code with LUA
-
Since I received some great help here not so long ago, gonna post this here for who’s interested. I found a cool piece of LUA code online that can easily be reconfigured for any language.
The most important values to change to make basic beautifing possible are:
KeywordReferenceData = { IndentType {"Else",IndentBoth}, IndentType {"ElseIf",IndentBoth}, IndentType {"Native",IndentIgnore}, IndentType {"New",IndentIgnore}, IndentType {"As",IndentIgnore}, IndentType {"Int",IndentIgnore}, IndentType {"Length",IndentIgnore}, IndentType {"Import",IndentIgnore}, IndentType {"None",IndentIgnore}, IndentType {"Parent",IndentIgnore}, IndentType {"Property",IndentIgnore}, IndentType {"String",IndentIgnore}, IndentType {"Hidden",IndentIgnore}, IndentType {"Self",IndentIgnore}, IndentType {"Return",IndentIgnore}, IndentType {"ScriptName",IndentIgnore}, IndentType {"True",IndentIgnore}, IndentType {"Global",IndentIgnore}, IndentType {"Float",IndentIgnore}, IndentType {"Bool",IndentIgnore}, IndentType {"AutoReadOnly",IndentIgnore}, IndentType {"Extends",IndentIgnore}, IndentType {"False",IndentIgnore}, IndentType {"Auto",IndentIgnore}, IndentType {"EndEvent",IndentLeft}, IndentType {"EndFunction",IndentLeft}, IndentType {"EndIf",IndentLeft}, IndentType {"EndProperty",IndentLeft}, IndentType {"EndState",IndentLeft}, IndentType {"EndWhile",IndentLeft}, IndentType {"If",IndentRight}, IndentType {"State",IndentRight}, IndentType {"Event",IndentRight}, IndentType {"Function",IndentRight}, IndentType {"While",IndentRight}, }
And clearing all the keywords in these array’s since those have no value in your language anyway.
ScriptObjects = CaseType {} ApiData = CaseType {} EventData = CaseType {}
I recommend reading through the code below these arrays, its not that hard to understand. There you can adjust the rules for your language, or add some new ones. Or just comment functions that are problematic for your language.
All you need is LUA for windows wich can be downloaded here, and make sure to add it to PATH when installing: https://code.google.com/archive/p/luaforwindows/downloads
Then put the LUA script somewhere in a folder, and open Notepad++, press F5 to open the run box. enter this command and press save to bind it to a shortcut:
lua "[install path]\skyindent.lua" -b "$(FULL_CURRENT_PATH)"
[install path] being the full path to the script. Make sure to save your file before beautifying or lose your changes. When you saved your file first, the script will make a backup of the state of the file before beautifying.
I hope this will help some people.
Source : https://ck.uesp.net/wiki/User:PROXiCiDE/SkyIndent.lua
I had to clear the keyword arrays in the code block below, because my post was too long. Still too long, will reply to my own topic then… I hope that works.
Edit: didn’t work, I guess everyone knows and trusts pastebin: https://pastebin.com/FKqPERmf
-
Does this have anything whatsoever to do with Notepad++?
-
@Alan-Kilborn
Its for people who use notepad++ for programming, since re-indenting or beautifying your written code is supported only in a few languages in Npp.This could potentially be very interesting to people. -
@Khundian-Twitch said in Beautify your code with LUA:
Its for people who use notepad++ for programming
It’s really just a general code beautification thing, nothing to do with Notepad++.
Please try to confine your postings here to Notepad++ specific discussion.
People here probably also like chocolate chip cookies, but nobody is here to read about that. -
@Alan-Kilborn
Whatever man, got better things to do than go back and forth with you over something so trvial as a post on a forum. If the moderators deem my post unsuitable for the forum, they will delete it… right? -
No moderator deletes such posts.
It’s not a big deal, just trying to educate you about forum etiquette.
Cheers. -
@Alan-Kilborn I personally did not have any issues with the post. Some people use Lua. Notepad++ includes support for Lua (but not cookie files) in its list of supported languages. Notepad also includes a Lua lexer as a plugin. Finally, the OP also showed how to link from Notepad++ into the Lua prettifier.
There’s a LuaScript plugin for Notepad++ that works with up to at least npp v8.3 and at least for the v8.3 era was a good example of a plugin that integrates with both Notepad++ and Scintilla.
-
Like I said, it’s not a big deal.
We just try to keep people on the straight-and-narrow here. :-)
If someone wants a code-beautifier, it’s easy to go in search of one elsewhere.
Certainly, if it were an actual Notepad++ plugin code-beautifier being discussed, then 100% on-topic.…OP also showed how to link from Notepad++…
Well … a Run menu item can be created to just about anything, so it doesn’t help the original posting be any more on-topic.
-
@Alan-Kilborn said in Beautify your code with LUA:
Certainly, if it were an actual Notepad++ plugin code-beautifier being discussed, then 100% on-topic.
A great way for OP to bring it back on-topic would be to show how to make that script work in the LuaScript plugin, and then (if possible) show how to automatically run the beautifier through that plugin every time you save a script of the right type. I know that @Michael-Vincent has shown ¹ how to run a linter or beautifier during the file-save event using NppExec, and you ² and I ³ have shown examples of PythonScript that runs either a Python and/or Perl code-checker to verify there are no compiler errors when a .py or .pl file is saved. So seeing another ⁴ example of how to do a similar event-prompted beautification in LuaScript would be hugely beneficial to someone who prefers LuaScript to PythonScript. (That’s actually why I upvoted the original post, though I had intended to come back and essentially add this paragraph as a reply, but Round Tuits™ are sometimes elusive.)
edit: added references; also was reminded about dail’s syntax checker in LuaScript that actually served as the inspiration for Alan’s code and thus mine
-
While I agree that in a perfect world I wouldn’t make a post like this, but actually present a finished solution or product like a plugin… but one has only so much time between work and family.
I’ll take a look at the lua script plugin somewhere in the future, I didn’t even know there was a LUA plugin. I just happen to stumble on this script when doing some research, and figured it could be helpful for other people too. Thats pretty much the only reason I posted it here on the forum.
I currently have my hands full with a project, creating an UDL for notepad++. Beatutifying and auto indenting is on my list and will eventually get around to it, but at the moment I have other priorities. Such as writing calltips for about 3000 entries, and coming through on other promisses made.