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.lua
example isOnChar()
so is not quite suitable for the task to reformat a whole document.You can download
CodeFormat.exe
from
https://github.com/CppCXY/EmmyLuaCodeStyle/releases .
Seems only 64 bit so unsure if 32 bit is available.win32-x64.zip
is what I downloaded and tested with.CodeFormat.exe
can reformat a whole document. ExtractCodeFormat.exe
from 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 Code
in the menuPlugins -> LuaScript
.
filePath
will 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 Code
entry reformats the document to:t = { 'a', 'b', 'c' }
The change is set in the document buffer.
-
This post is deleted!