How to use LuaScript examples
-
I have installed LuaScript 0.12 on NotePad++ 8.6.9 and I’ve found the documentation with a list of examples.
What I’m missing is how to use the examples. In particular, luaautoindent.lua.
I am a World of Warcraft addon developer and a recent Blizzard “enhancement” is to remove all the indentation from their saved variables files which are Lua tables. While getting rid of all that white space may be good for speeding up loading of addons, it sucks when debugging an addon.
I want to load the file into NPP and then do “something” to reformat it. Very rarely I’ll change something and save it but mostly I just want a better visualization of the multiple tables in the file.
-
@Brad-Morgan
luaautoindent.luaexample isOnChar()so is not quite suitable for the task to reformat a whole document.You can download
CodeFormat.exefrom
https://github.com/CppCXY/EmmyLuaCodeStyle/releases .
Seems only 64 bit so unsure if 32 bit is available.win32-x64.zipis what I downloaded and tested with.CodeFormat.execan reformat a whole document. ExtractCodeFormat.exefrom the zip to the plugins config directory which if installed Notepad++ is%AppData%\Notepad++\plugins\Config.You can add this code to LuaScript’s
Edit Startup Script:npp.AddShortcut('Reformat Lua Code', '', function() local configDir = npp:GetPluginsConfigDir() local codeFormatPath = configDir .. '\\CodeFormat.exe' local filePath = npp:GetFullCurrentPath() local command = '""' .. codeFormatPath .. '" ' .. 'format -f "' .. filePath .. '" -d"' local file = io.popen(command) if file then local text = file:read('*a') file:close() if text and text ~= '' then editor:SetText(text) end end end)Need to restart Notepad++ to see the entry named
Reformat Lua Codein the menuPlugins -> LuaScript.
filePathwill contain the path to the lua file.New1,New2… temporary files are not expected to work.A test file:
t = {'a', 'b', 'c'}Click the
Reformat Lua Codeentry reformats the document to:t = { 'a', 'b', 'c' }The change is set in the document buffer.
-
This post is deleted!