@Brad-Morgan luaautoindent.lua example is OnChar() 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. Extract CodeFormat.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 menu Plugins -> 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.