Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add. Code snippet plugin #92

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Add. Code snippet plugin #92

wants to merge 18 commits into from

Conversation

moteus
Copy link

@moteus moteus commented Sep 8, 2021

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

  • regex transformation - currently uses original implementation based on ruby script. It is slow and does not support features like upper case. But I did not find better way. (Perl can do this but I prefer to use some Lua library)
  • 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.
  • Improve scope detection - Personally I use only few lexers (mostly Lua and Perl) and there all seems work as expected.
  • Support loading snippets from file. I have no huge snippets (yet?), so do not need it right now.
  • Full autocomplete for snippets. Currently its possible only select one elements

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.

@moteus moteus changed the title [WIP] Add. Code snippet plugin Add. Code snippet plugin Sep 10, 2021
@pkulchenko
Copy link
Owner

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
Copy link
Author

moteus commented Sep 11, 2021

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.

Change. Use WordStartPosition to detect last word
@moteus
Copy link
Author

moteus commented Sep 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants