How to format the code in ZeroBrane Studio

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

How to format the code in ZeroBrane Studio

Post by darkfrei »

Hi all!

Here is a small tool to keep your code clean!

1. Open the ZBS/cfg/user.lua

2. Place the code:

Code: Select all

package {
	onEditorKeyDown = function(self, editor, event)
		local keyCode = event:GetKeyCode()
		if keyCode == 347 then -- F8
			ide:GetMainFrame():ProcessEvent(wx.wxCommandEvent(
					wx.wxEVT_COMMAND_MENU_SELECTED, ID.REINDENT))
			local doc = ide:GetDocument(editor)
--			ide:Print(doc:GetFilePath(), self:GetFileName(), "onEditorKeyDown", keyCode)
			ide:Print("Done, the code was fixed:", doc:GetFilePath())
		end
	end,
}
3. Save the file.

4. Close the ZeroBrane Studio and open it again.

5. Press F8 in any file to make your code good formatted again.

Update:
Or just press the Ctrl+I :x
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: How to format the code in ZeroBrane Studio

Post by GVovkiv »

What does exactly happens here?
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to format the code in ZeroBrane Studio

Post by darkfrei »

GVovkiv wrote: Wed Jun 21, 2023 8:08 am What does exactly happens here?
It converts this

Code: Select all

end
end
end
end
to this:

Code: Select all

			end
		end
	end
end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: How to format the code in ZeroBrane Studio

Post by GVovkiv »

darkfrei wrote: Wed Jun 21, 2023 9:07 am ...
Huh, zerobrane really need graphical options menu, instead of big old wiki and lua config files. So many features missed, because i'm too lazy to search wiki.
User avatar
Bobble68
Party member
Posts: 162
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: How to format the code in ZeroBrane Studio

Post by Bobble68 »

Yoink
Dragon
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to format the code in ZeroBrane Studio

Post by darkfrei »

GVovkiv wrote: Wed Jun 21, 2023 12:20 pm
darkfrei wrote: Wed Jun 21, 2023 9:07 am ...
Huh, zerobrane really need graphical options menu, instead of big old wiki and lua config files. So many features missed, because i'm too lazy to search wiki.
I still have no idea how to use the Watch window and why it removes all data on the program restarting.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: How to format the code in ZeroBrane Studio

Post by GVovkiv »

I don't know why it removes data, but:
1. Open watch window
2. Add some line in file to watch list (Right click on line -> Add Watch Expression)
3. Done
Tho, you can actually select anything, including several lines or blocks or whatever
And it will be added to watch list.
Or you could add own watch expression...
And then...
uh...
I don't know.
I used it once, window closed on me several times (probably crashed) and then i ditched it.
Based on some googling, you need to use that thing in debugging with breakpoints.
https://api.cuberite.org/SettingUpZeroBrane.html

I think, it's better to not use this function at all, lol. Or use VSCode or VSCodium instead
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: How to format the code in ZeroBrane Studio

Post by paulclinger »

>> I still have no idea how to use the Watch window and why it removes all data on the program restarting.
> Tho, you can actually select anything, including several lines or blocks or whatever

It's all valid points, but the explanation is simple: I've thought about storing the watchlist configuration, but then it would only make sense to store it per-project and in most cases it's related to a specific debugging session one may be doing, so it rarely makes sense to preserve between launches (and as GVovkiv suggested, I tried to make the process to be fairly simple and quick).

Also, the API is quite flexible, so you can actually write a plugin that captures the watches before exiting and then restores them when the IDE is restarted. In fact, there is a real-time watch plugin that dynamically generates watches based on a script output (https://notebook.kulchenko.com/zerobran ... ane-studio), so all this functionality is available. I'm not against adding more features, but in this case I deemed it to not be worth it.

> zerobrane really need graphical options menu, instead of big old wiki and lua config files. So many features missed, because i'm too lazy to search wiki.

Also fair, but I frequently change configurations and it's a pain to do it through a GUI interface. Also, the discoverability is still an issue and I tried to keep the documentation concise and up-to-date (https://studio.zerobrane.com/doc-general-preferences) to help with that. The config file is also a regular Lua file that allows to have conditions and simple plugins, which is going to be difficult to reproduce with a GUI approach (other than providing a code window where everything would go). I've been debating for a long time about a better interface for it, but so far nothing really stands out, so a text file with Lua code it is (at least for now).
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: How to format the code in ZeroBrane Studio

Post by GVovkiv »

> The config file is also a regular Lua file that allows to have conditions

Honestly, if there would be options window where i counld see all keybindings, true/false for functionality, etc - that would be already 10 times better.
Or at least built-in cheatsheet or something like that.
And while wiki contains everything that user need to know, it's still not perfect way to discover and even sometimes search information.
For example, opening google with "zerobrane watch window" doesn't really bring wiki page for that watch list, only to Q&A page on wiki where "watch window" mentioned something like 4 times and random reddit post where someone asks what this watch window do.
It's especially important for newbies, because zerobrane often being recommend for then on love forums, for simple interface, built-in support for love and lua (include up-to-date love syntax highlighting), and easy to setup (compare to other ides). And often, this newbies new not only to lua and love, but to programming and IDEs in general.
paulclinger
Party member
Posts: 227
Joined: Thu Jun 28, 2012 8:46 pm

Re: How to format the code in ZeroBrane Studio

Post by paulclinger »

There are a couple of files that have all the options listed: https://github.com/pkulchenko/ZeroBrane ... keymap.lua has all the key bindings and https://github.com/pkulchenko/ZeroBrane ... config.lua has all the configuration values and their defaults. I thought about including them in the default config as comments, but as you can see, keymap has 100+ values and the config has 380 (of which ~150 are extension mappings and exclude lists).

> It's especially important for newbies, because zerobrane often being recommend for then on love forums, for simple interface, built-in support for love and lua (include up-to-date love syntax highlighting), and easy to setup (compare to other ides). And often, this newbies new not only to lua and love, but to programming and IDEs in general.

I agree with all this and that's the primary reason why I think sensible defaults are important. You should feel free to come up with your own list of options, as it can be loaded with a simple `include "myoptions"` statement in the config.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests