Community
    • Login

    How to use LuaScript examples

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 3 Posters 1.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Brad MorganB Offline
      Brad Morgan
      last edited by Brad Morgan

      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.

      mpheathM 1 Reply Last reply Reply Quote 0
      • mpheathM Offline
        mpheath @Brad Morgan
        last edited by

        @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.

        1 Reply Last reply Reply Quote 2
        • Its WickI Offline
          Its Wick
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote -1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors