Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

New python plugin implementation - #99

Closed
zalox wants to merge 100 commits into
cppit:masterfrom
zalox:master
Closed

New python plugin implementation#99
zalox wants to merge 100 commits into
cppit:masterfrom
zalox:master

Conversation

@zalox

@zaloxzalox commented Dec 5, 2015

Copy link
Copy Markdown
Member

Features

  • Write plugins in python using an API-module
  • Configure integration with juCi++ usin JSON configuration
  • Easy expansion of the API using lamba expressions in python_api.cc

libjuci - Python API for juCi++

libjuci.

add_menu_element(str json) // -> (void) Builds a menu configured by 'json'
[
{
"label": "_Edit",
"menu_elements": [
{
"label":"_Snippet",
"menu_elements": [
{
"label":"Insert snippet",
"keybinding":"<primary>m",
"action":"snippet.insert_snippet"
}
]
}
]
}
]
get_juci_home() // -> (str) returns the path of the juci home folder

libjuci.terminal

println(str message) // -> (int) prints 'message' to terminal

libjuci.editor

erase(int, int); // -> (void) removes the text between the given offsetserase_line_range(int, int, int); // -> (void) Removes text on line 'line_number' between 'begin_line_offset' and 'end_line_offset'get_file(); // -> (str) Returns the current open file. If no file is open it returns empty a stringget_highlighted_word(); // -> (str) returns json, empty string on error{'word': 'word','type': '-1'}get_line(); // -> (str) returns the line of text the caret is onget_line_number(); // -> (int) Returns the line which is being edited, -1 if no file is open or no line is selectedget_line_offset(); // -> (int) Returns the number of characters the caret currently is positioned from the previous newline, 0 is the first character -1 if no file is open or no line is selectedget_offset(); // -> (int) Returns the number of characters the caret currently is positioned from start of the file. 0 is the first character. Returns -1 if no lines or files are selected/openget_tab_char_and_size(); // -> (str) Returns a key-value json-object with 'tab_char' and 'size' keysget_text(); // -> (str) returns the text in the open editorget_text_range(int, int); // -> (str) Returns the text between 'begin_offset' and 'end_offset'. Returns emptystring if editor isn't focused on a fileinsert_at(int offset, str text); // -> (void) Inserts text at the given offset, caller is responsible to scroll to the insertioninsert_at_cursor(str); // -> (void) Inserts text at the cursoris_saved(); // -> (bool) Returns true if the current open file is savedscroll_to(int line_number); // -> (void) Scrolls cursor to 'char_offset'

Example plugins

Toolsplugin

  • Open favorite project folder using hotkey
  • Open plugin folder for easy access

Snippet

  • Insert string templates based on keywords
if -hotkey-> if () {
}

Todo

  • Write documentation for the API
  • Test on osx @eidheim
  • Test on arch
  • Test on debian
  • Test on msys
  • Ready for merge

@eidheim

Copy link
Copy Markdown
Member

Great work! Have not looked at it thoroughly yet, but its really nice that we get a python integration that support c++11!

@zalox

zalox commented Apr 4, 2016

Copy link
Copy Markdown
MemberAuthor

@eidheim

This is getting very stable. The last few commits are adding menu elements and accels dynamically. The gtk bindings are working according to the api, and is slightly different from the gtkmm bindings.

I've successfully tested stand-alone python apps as well, so people can write for instance gtk-windows to add gui to their plugins.

The plugins provided are made on the fly, and might need some clean up from someone who knows python better than me.

I'm keeping the old way of adding menu elements, to make sure we support plugins on systems where pygobject introspection isn't supported.

This is my todo:

  • Update documentation to add new dependencies
  • Make sure plugins are installed on startup
  • Write some usage/design spec

@zalox

zalox commented Apr 4, 2016

Copy link
Copy Markdown
MemberAuthor

The latest commit makes this testable.

Python handles packages through pip or the package repo. I used pacman on arch to install pygobject and python 3 and used the site_packages option in config.json to pont to it. The default value migth be sufficent.

@eidheim

Copy link
Copy Markdown
Member

Great! Usually, maybe before documentation etc, one would want to clean up/reconstruct the source code once having a working version. Might be a good idea to spend some time on this, especially after so many changes, and when creating an API. Saying this before I have looked at the source though, but when you are happy with the source after considering cleanup/reconstruct I'll have a look at it:)

@zalox

zalox commented Apr 4, 2016

Copy link
Copy Markdown
MemberAuthor

I think it might be useful to rebase this pull request to get a better overview of the changes. This will also allow me to fine comb all the code to check for refactor needs. I have some time tomorrow to do this. I think most of the commits in this request are overwritten anyways. I think I can make this into more like 10 commits.

@eidheim

Copy link
Copy Markdown
Member

Splendid, just remember to take your time on the refactor, its a great experience, and something that is not at all prioritised in businesses. This is one of the reasons why Open Source is such a success I belive:)

@zalox

zalox commented Apr 4, 2016

Copy link
Copy Markdown
MemberAuthor

Before I start. Are there any features you'd like to see?

I think I might be able to make the bindings available for js, vala, lua and other script languages with some struggle.

@eidheim

Copy link
Copy Markdown
Member

Python is fine for now I think:) Just keep it simple, but flexible and general.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@zalox@eidheim@archshift