pkulchenko / ZeroBranePackage

Packages for ZeroBrane Studio (https://studio.zerobrane.com)
MIT License
246 stars 148 forks source link

Add. Code snippet plugin #92

Open moteus opened 3 years ago

moteus commented 3 years ago

This plugin based on scite-tools/snippets plugin. I did not use code snippets yet so I have no experience with it and may be some thing need change. So I really hope to any feedback. I tested this code only under Windows. I have plan to do this on Ubuntu as well, but may be only on a next week.

Possible improvements

Also, I think about add package_require function to ZBS source code. Its really ugly right now, but I really do not put all code in the one file.

Update I think I done with this package for now. I test it on Ubuntu and on Windows.

pkulchenko commented 3 years ago

Thank you for the patches!

I think about add package_require function to ZBS source code. Its really ugly right now, but I really do not put all code in the one file.

I'm thinking about adding the plugin folder to the search path right before loading the plugin itself; I can also add a check to see if the folder is present. Would this help?

Or, I can add "packages" folder itself to the path, so if you're loading package files as require "package.file", then it should just work out of the box.

shell_executes - currently run only real applications - not shell commands (like cd on Windows). I am not sure I need it so for now I have plan to leave it as is.

There is ide:ExecuteCommand that allows getting the output into the Output or Console window if needed.

All those commands that are available from the IDE are in package.lua.

moteus commented 3 years ago

Or, I can add "packages" folder itself to the path, so if you're loading package files as require "package.file", then it should just work out of the box.

I think it will be better (just make sure it is last path and package can not redefice some core module). But there will be still a problem with compatibility with the current ZBS version of plugin in case it will rely on this.

ide:ExecuteCommand seems just almost the same as mine (except async IO). But this function does not allow to diffirintiate stderr vs stdout and there no api to get retcode, so I think it can be used here. I think about another plagin that configures ZBS (current version) and then load plugins from some sub dir.

moteus commented 3 years ago

I just add a new HotKeys module that allows to use chained hot keys

local HotKeys = package_require 'snippets.hot_keys'

local Package = {}

Package.onRegister = function(package)
    HotKeys:add(package, {          'Ctrl-M'}, function() ide:Print('Regular action') end)
    HotKeys:add(package, {'Ctrl-K', 'Ctrl-M'}, function() ide:Print('Chained action') end)
end

Package.onUnRegister = function(package)
    HotKeys:close_package(package) -- remove only shortcuts for this package
end

return Package

I working on plugin that implement multi selection facility from the Sublime text editor. And there exists shortcut Ctrl-K Ctrl-D. So I implement this class and put to this plagin as well. But I think ideally zbs has to has only one instance of this class and all plagins should just use it to add theirs shortcuts.

PS Is there any way to add text to status bar? I want to add there current hotkey chain.