diff options
Diffstat (limited to '')
| -rw-r--r-- | doc/vim-ai.txt | 5 | ||||
| -rw-r--r-- | py/roles.py | 10 | ||||
| -rw-r--r-- | py/utils.py | 7 |
3 files changed, 22 insertions, 0 deletions
diff --git a/doc/vim-ai.txt b/doc/vim-ai.txt index 5d06fc7..c7aefde 100644 --- a/doc/vim-ai.txt +++ b/doc/vim-ai.txt @@ -177,6 +177,11 @@ Example of a role: > See roles-example.ini for more examples. +The roles in g:vim_ai_roles_config_file are converted to a Vim dictionary whose +labels are the names of the roles. Optionally, roles can be added by setting +g:vim_ai_roles_config_function to the name of a Vimscript function returning a +dictionary of the same format as g:vim_ai_roles_config_file. + KEY BINDINGS Examples how configure key bindings and customize commands: > diff --git a/py/roles.py b/py/roles.py index 7c7cf13..6e0a52e 100644 --- a/py/roles.py +++ b/py/roles.py @@ -3,9 +3,19 @@ import os import configparser roles_config_path = os.path.expanduser(vim.eval("g:vim_ai_roles_config_file")) +if not os.path.exists(roles_config_path): + raise Exception(f"Role config file does not exist: {roles_config_path}") + roles = configparser.ConfigParser() roles.read(roles_config_path) +if vim.eval("exists('g:vim_ai_roles_config_function')") == '1': + roles_config_function = vim.eval("g:vim_ai_roles_config_function") + if not vim.eval("exists('*" + roles_config_function + "')"): + raise Exception(f"Role config function does not exist: {roles_config_function}") + else: + roles.update(vim.eval(roles_config_function + "()")) + role_names = [name for name in roles.sections() if not '.' in name] role_list = [f'"{name}"' for name in role_names] diff --git a/py/utils.py b/py/utils.py index 6bd90a1..471b5c4 100644 --- a/py/utils.py +++ b/py/utils.py @@ -271,6 +271,13 @@ def load_role_config(role): roles = configparser.ConfigParser() roles.read(roles_config_path) + if vim.eval("exists('g:vim_ai_roles_config_function')") == '1': + roles_config_function = vim.eval("g:vim_ai_roles_config_function") + if not vim.eval("exists('*" + roles_config_function + "')"): + raise Exception(f"Role config function does not exist: {roles_config_function}") + else: + roles.update(vim.eval(roles_config_function + "()")) + if not role in roles: raise Exception(f"Role `{role}` not found") |