From 01ced0b7ce47d279789efb2dc70d1cd009ac56ad Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 9 Oct 2021 22:20:41 +0100 Subject: initial commit --- config/vim/plugin/pickachu/main.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 config/vim/plugin/pickachu/main.py (limited to 'config/vim/plugin/pickachu/main.py') diff --git a/config/vim/plugin/pickachu/main.py b/config/vim/plugin/pickachu/main.py new file mode 100644 index 0000000..d9a42b3 --- /dev/null +++ b/config/vim/plugin/pickachu/main.py @@ -0,0 +1,36 @@ +import vim +from . import apps + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# name: main.py +# description: This file evaluates the command arguments +# provided by the user, calls the runApp function, +# and inserts valid output to the user's buffer. +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +DEFAULT_APP = vim.eval('g:pickachu_default_app') + + +def MainFunction(): + # This section is for getting the + # arguments from the user's Vim + # command. + arglength = int(vim.eval('a:0')) + CHOOSEN_APP = DEFAULT_APP + CHOOSEN_FORMAT = None + if arglength > 0: + CHOOSEN_APP = vim.eval('a:1') + if arglength > 1: + CHOOSEN_FORMAT = vim.eval('a:2') + + # We run apps.py's runApp function to get an output. + output = apps.runApp(CHOOSEN_APP, CHOOSEN_FORMAT) + + # Now, if runApp gave us an output, we can use the + # Vim API to print the output to the user's buffer. + if output: + pos_y, pos_x = vim.current.window.cursor + vim.current.line = vim.current.line[:pos_x+1] + output + vim.current.line[pos_x+1:] + vim.current.window.cursor = (pos_y, pos_x + len(output)) + else: + print('Pickachu - Canceled') -- cgit v1.2.1