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

New python plugin implementation #99

Closed
wants to merge 100 commits into from
Closed

New python plugin implementation #99

wants to merge 100 commits into from

Conversation

zalox
Copy link
Member

@zalox zalox commented Dec 5, 2015

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 offsets
    erase_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 string
    get_highlighted_word(); // -> (str) returns json, empty string on error{'word': 'word','type': '-1'}
    get_line(); // -> (str) returns the line of text the caret is on
    get_line_number(); // -> (int) Returns the line which is being edited, -1 if no file is open or no line is selected
    get_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 selected
    get_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/open
    get_tab_char_and_size(); // -> (str) Returns a key-value json-object with 'tab_char' and 'size' keys
    get_text(); // -> (str) returns the text in the open editor
    get_text_range(int, int); // -> (str) Returns the text between 'begin_offset' and 'end_offset'. Returns emptystring if editor isn't focused on a file
    insert_at(int offset, str text); // -> (void) Inserts text at the given offset, caller is responsible to scroll to the insertion
    insert_at_cursor(str); // -> (void) Inserts text at the cursor
    is_saved(); // -> (bool) Returns true if the current open file is saved
    scroll_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
Member

eidheim commented Dec 5, 2015

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

@zalox
Copy link
Member Author

zalox commented Apr 4, 2016

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

zalox commented Apr 4, 2016

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
Member

eidheim commented Apr 4, 2016

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

zalox commented Apr 4, 2016

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
Member

eidheim commented Apr 4, 2016

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

zalox commented Apr 4, 2016

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
Member

eidheim commented Apr 4, 2016

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

Sign up for free to 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