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

Sublime snippets first part #775

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
5993d68
Merge pull request #1 from dictation-toolbox/master
mpourmpoulis Mar 14, 2020
4bdcfce
Create Function_like_utilities.py
mpourmpoulis Mar 20, 2020
9fa5f7d
Create sublime_snippets.py
mpourmpoulis Mar 20, 2020
bd6d3f9
Interface with sublime and primitive sublime command action
mpourmpoulis Mar 20, 2020
0475b74
global snippet controll grammar WIP
mpourmpoulis Mar 20, 2020
b4492ee
Update sublime_snippet_control.py
mpourmpoulis Mar 20, 2020
ed39c8d
Update test_rule_modules.py
mpourmpoulis Mar 20, 2020
d0d5de7
Update test_rule_modules.py
mpourmpoulis Mar 20, 2020
17523bb
ADD comment pylint: disable=deprecated-method when getting signature…
mpourmpoulis Mar 20, 2020
7eec1b9
Add in the correct place # pylint: disable=deprecated-method
mpourmpoulis Mar 20, 2020
8151bc2
Update Function_like_utilities.py
mpourmpoulis Mar 21, 2020
114f9ee
Update Function_like_utilities.py
mpourmpoulis Mar 21, 2020
df30426
Early proof of concept
mpourmpoulis Mar 23, 2020
93ecae0
Working proof of concept, activating only meaningful variants, much w…
mpourmpoulis Mar 23, 2020
4b778d8
Forgot test For self modifying snippet variance control
mpourmpoulis Mar 24, 2020
d3ccffa
Remove old display variance function
mpourmpoulis Mar 24, 2020
ddc6ab4
Bug fix in display variants, the loop should stop if one of the attem…
mpourmpoulis Mar 24, 2020
bb53223
Failed attempt to address the problem of registering a call back mult…
mpourmpoulis Mar 24, 2020
01bd4fe
Restructuring into sublime rules first part
mpourmpoulis Mar 24, 2020
c134f93
Update tests with the restructure directory
mpourmpoulis Mar 24, 2020
17e9d5e
More stuff on restructuring, major problem found with conditional imp…
mpourmpoulis Mar 25, 2020
ece6d04
Control grammar is no longer CCR and is now bound to sublime applicat…
mpourmpoulis Apr 3, 2020
8e78dc7
Removed by commenting out The basic control grammar
mpourmpoulis Apr 3, 2020
b6c11ee
Move the main sublime grammar Under sublime rules folder
mpourmpoulis Apr 3, 2020
1fcf707
Remove old supplementary support file
mpourmpoulis Apr 3, 2020
7609bc8
Fix previous mistake
mpourmpoulis Apr 3, 2020
ee8f096
Upgrade decorator to support renaming parameters
mpourmpoulis Apr 11, 2020
56c5d2e
Adopt the control grammar to Fit with a new decorator
mpourmpoulis Apr 11, 2020
13543a3
add remap_data to snippet_state
mpourmpoulis Apr 12, 2020
24f4f4e
Preliminary support for commands of form display <choice> variant
mpourmpoulis Apr 12, 2020
d7ecf64
switch to recognition observer class and solve reregistering problem
mpourmpoulis Apr 12, 2020
c88a328
Update sublime_snippets.py
mpourmpoulis Jul 17, 2020
fd95bcc
filter_snippet_text Most likely redundant
mpourmpoulis Jul 25, 2020
83427be
Conflict handling first attempt with supplementary text engine
mpourmpoulis Jul 25, 2020
098eb62
Variant support for all types of snippets and proper display variants…
mpourmpoulis Jul 25, 2020
4df08ed
Resolving conflicts 1
mpourmpoulis Jul 25, 2020
5b24e87
Delete sublime.py
mpourmpoulis Jul 25, 2020
6e47f2f
Make controll grammar work With CCR and self modifying rules
mpourmpoulis Jul 29, 2020
5b5d093
Only one controll rule: move SublimeSnippetAdditionalControllRule to …
mpourmpoulis Jul 30, 2020
8f1ac4c
Additional reload guards for Last keys and so on
mpourmpoulis Jul 30, 2020
a890051
Allow for TomlConfig without configuration path
mpourmpoulis Jul 30, 2020
aa11866
Update sublime_snippets.py
mpourmpoulis Aug 1, 2020
bf0b34d
first_attempt SublimeCommand
mpourmpoulis Aug 4, 2020
7db1ddd
Create sublime_communication_support
mpourmpoulis Aug 4, 2020
4e16da1
Transition into independent sublime_communication_support
mpourmpoulis Aug 6, 2020
d6ed6cd
Docstring,checks,rework send_sublime
mpourmpoulis Aug 6, 2020
2472478
Docstring,checks,rework send_quick_panel
mpourmpoulis Aug 6, 2020
114e675
bugfix: fix a small mess with references to dictionaries
mpourmpoulis Aug 6, 2020
35cfd05
Restructuring the approach for choosing when to refresh
mpourmpoulis Aug 6, 2020
16b6be1
Docstring,checks,rework send_snippet
mpourmpoulis Aug 6, 2020
9d28331
Restructure into snippet_generation_support
mpourmpoulis Aug 7, 2020
a0f0a49
Remove decorator mark_snippet_grammar
mpourmpoulis Aug 7, 2020
802e761
fix: forgot to stop importing the removed grammars_with_snippets in t…
mpourmpoulis Aug 7, 2020
11ae839
Extend the SublimeCommand class to support %(extraname)s syntax in a …
mpourmpoulis Aug 7, 2020
a1f0ffd
checks and Minority factoring apply_single_transformation
mpourmpoulis Aug 8, 2020
bb037b3
minor change to be corrected later
mpourmpoulis Sep 15, 2020
2152f14
Initial documentation attempt
mpourmpoulis Sep 15, 2020
46e4300
TomlConfig missing __init__ in super
mpourmpoulis Sep 28, 2020
c09522c
Remove sublime_snippet_additional_control from tests
mpourmpoulis Sep 28, 2020
dcf83e5
Create snippet_utilities
mpourmpoulis Sep 29, 2020
45dc7a4
minor error message change
mpourmpoulis Sep 29, 2020
19a32d0
docs string improvements snippet_generation_support
mpourmpoulis Sep 29, 2020
62445fe
temporary change
mpourmpoulis Sep 29, 2020
813bd8c
snippet_utilities: add function for creating regular expressions
mpourmpoulis Sep 29, 2020
98a7784
create sublime_support
mpourmpoulis Sep 29, 2020
ef1e194
snippet_utilities: add decorator load_snippets
mpourmpoulis Sep 29, 2020
b7bf6c0
sublime_snippets: more condition checking and documentation
mpourmpoulis Sep 29, 2020
c4caaa2
make regular snippet_utility more user-friendly
mpourmpoulis Oct 1, 2020
d7b46a4
get_signature_arguments add docstring
mpourmpoulis Oct 1, 2020
e798d1f
upgrades snippet utilities: regular and documentation
mpourmpoulis Oct 1, 2020
156f463
voice dev command placeholder
mpourmpoulis Oct 1, 2020
0e4b250
voice dev: snippet, sublime command and snippets transform
mpourmpoulis Oct 1, 2020
be0cf13
Update snippet_utilities.py
mpourmpoulis Oct 2, 2020
f254594
snippet_utilities: change signature of regular for compatibility wit…
mpourmpoulis Oct 2, 2020
a38b298
load_snippets: add checks for already existing extras
mpourmpoulis Oct 2, 2020
a447b8d
SublimeCommand: documentation skeleton
mpourmpoulis Oct 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion castervoice/lib/config/config_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
class TomlConfig(BaseConfig):

def __init__(self, config_path):
super(TomlConfig, self)
super(TomlConfig, self).__init__()
self._config_path = config_path

def save(self):
if not self._config_path:
return
utilities.save_toml_file(self._config, self._config_path)

def load(self):
if not self._config_path:
return {}
self._config = utilities.load_toml_file(self._config_path)
54 changes: 45 additions & 9 deletions castervoice/rules/apps/editor/sublime.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class SublimeRule(MappingRule):
"(select | sell) all":
R(Key("c-a")),
"(select | sell) scope [<n2>]":
R(Key("cs-space")),
R(Key("cs-space")*Repeat(extra="n2")),
"(select | sell) brackets [<n2>]":
R(Key("cs-m")),
R(Key("cs-m")*Repeat(extra="n2")),
"(select | sell) indent":
R(Key("cs-j")),
#
Expand All @@ -49,15 +49,21 @@ class SublimeRule(MappingRule):
R(Key("a-enter")),
"replace":
R(Key("c-h")),
"replace all":
R(Key("ca-enter")),
"paste from history":
R(Key("c-k,c-v")),
"edit lines":
R(Key("cs-l")),
"edit next [<n3>]":
R(Key("c-d/10"))*Repeat(extra="n3"),
"edit only next [<n3>]":
R(Key("c-k,c-d/10"))*Repeat(extra="n3"),
"edit up [<n3>]":
R(Key("ac-up"))*Repeat(extra="n3"),
"edit down [<n3>]":
R(Key("ac-down"))*Repeat(extra="n3"),
"edit all":
"edit all":
R(Key("a-f3")),
#
"transform upper":
Expand All @@ -69,10 +75,18 @@ class SublimeRule(MappingRule):
R(Key("c-g/10") + Text("%(ln1)s") + Key("enter")),
"<action> [line] <ln1> [by <ln2>]":
R(Function(navigation.action_lines)),
"[move] line down [<n3>]":
R(Key("cs-down") * Repeat(extra='n3')),
"[move] line up [<n3>]":
R(Key("cs-up") * Repeat(extra='n3')),
#
"go to file":
R(Key("c-p")),
"go to <dict> [<filetype>]":
R(Key("c-p") + Text("%(dict)s" + "%(filetype)s") + Key("enter")),
"file back [<n2>]":
R(Key("c-p") + Key("down")*Repeat(extra="n2") + Key("enter")),
#
"go to word":
R(Key("c-semicolon")),
"go to symbol":
Expand All @@ -88,6 +102,13 @@ class SublimeRule(MappingRule):
"command pallette":
R(Key("cs-p")),
#
"go back [<n2>]":
R(Key("a-minus")*Repeat(extra="n2")),
"go forward [<n2>]":
R(Key("a-plus")*Repeat(extra="n2")),
"next modification":R(Key("c-dot")),
"previous modification":R(Key("c-comma")),
#
"fold":
R(Key("cs-lbracket")),
"unfold":
Expand All @@ -103,10 +124,12 @@ class SublimeRule(MappingRule):
R(Key("c-k, c-b")),
"show key bindings":
R(Key("f10, p, right, k")),
"show at center":
R(Key("c-k,c-c")),
"zoom in [<n2>]":
R(Key("c-equal")),
R(Key("c-equal")*Repeat(extra="n2")),
"zoom out [<n2>]":
R(Key("c-minus")),
R(Key("c-minus")*Repeat(extra="n2")),
#
"(set | add) bookmark":
R(Key("c-f2")),
Expand All @@ -117,8 +140,15 @@ class SublimeRule(MappingRule):
"clear bookmarks":
R(Key("cs-f2")),
#
"build it":
R(Key("c-b")),
"set mark": R(Key("c-k,c-space")),
"select mark": R(Key("c-k,c-a")),
"swap with mark": R(Key("c-k,c-x")),
"delete mark":R(Key("c-k,c-w")),
#
"build it": R(Key("c-b")),
"build with": R(Key("cs-b")),
"build <nth>":R(Key("c-s,a-%(nth)s,c-b")),
"build [<nth>] last":R(Key("c-s,a-1") + Key("c-pageup")*Repeat(extra="nth") + Key("c-b")),
#
"record macro":
R(Key("c-q")),
Expand All @@ -135,15 +165,20 @@ class SublimeRule(MappingRule):
R(Key("c-pgup")),
"<nth> tab":
R(Key("a-%(nth)s")),
"[<nth>] last tab":
R(Key("a-1") + Key("c-pageup")*Repeat(extra="nth")),

"column <cols>":
R(Key("as-%(cols)s")),
"focus <panel>":
R(Key("c-%(panel)s")),
"move <panel>":
R(Key("cs-%(panel)s")),
#
"open terminal":
"open terminal":
R(Key("cs-t")),
"open console":
R(Key("c-`")),
}
extras = [
Dictation("dict"),
Expand Down Expand Up @@ -188,8 +223,9 @@ class SublimeRule(MappingRule):
"n2": 1,
"n3": 1,
"file type": "",
"nth":"1",
}


def get_rule():
return SublimeRule, RuleDetails(name="sublime", executable="sublime_text", title="Sublime Text")
return SublimeRule, RuleDetails(name="sublime", executable="sublime_text", title="Sublime Text")
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import inspect

import six

############################## UTILITIES TO WRAP FUNCTION CALLS ##############################
#
# these functions are based on the dragonfly implementation for Function action, which does not
# support returning the return value of the function called
#
##############################################################################################


def get_signature_arguments(function):
"""Utility to extract the name of the arguments of the function signature

Args:
function (Callable): the function in question

Returns:
Tuple[Set[str],bool]: tuple consistent of
- the names of the arguments
- boolean indicating the function does NOT accept **kwargs
"""
# pylint: disable=no-member
if six.PY2:
# pylint: disable=deprecated-method
argspec = inspect.getargspec(function)
else:
argspec = inspect.getfullargspec(function)
args, varkw = argspec[0], argspec[2]
filter_keywords = not varkw
valid_keywords = set(args)
return valid_keywords, filter_keywords


def get_only_proper_arguments(function,data):
valid_keywords, filter_keywords = get_signature_arguments(function)
arguments = data.copy()
if filter_keywords:
invalid_keywords = set(arguments.keys()) - valid_keywords
for key in invalid_keywords:
del arguments[key]
return arguments

def rename_data(data,remap_data):
if isinstance(data, dict):
renamed = data.copy()
else:
raise TypeError("evaluate_function received instead of a dictionary " + type(data) + " in data")

# Remap specified names.
for old_name, new_name in remap_data.items():
if old_name in data:
renamed[new_name] = renamed.pop(old_name)
return renamed


def evaluate_function(function,data = {},remap_data = {}):
renamed = rename_data(data,remap_data)
arguments = get_only_proper_arguments(function,renamed)
try:
return function(**arguments)
except Exception as e:
raise


Empty file.
Loading