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

csv overrides #63

Merged
merged 55 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
10d52c3
Create missing settings
AndreasArvidsson Aug 17, 2021
2c69b9c
Added watch
AndreasArvidsson Aug 17, 2021
8f58ab3
Added timestamp and notification
AndreasArvidsson Aug 17, 2021
e8650e1
Implemented override
AndreasArvidsson Aug 18, 2021
6732889
Added more actions
AndreasArvidsson Aug 18, 2021
1811b0c
cleanup
AndreasArvidsson Aug 18, 2021
c2ab557
Updated cheat sheet
AndreasArvidsson Aug 18, 2021
c2d7fc5
Allow dictionary or list of dictionaries
AndreasArvidsson Aug 18, 2021
47a6c19
Clean up
AndreasArvidsson Aug 18, 2021
263b3f9
Clean up
AndreasArvidsson Aug 18, 2021
6e829f4
upper case action list names
AndreasArvidsson Aug 18, 2021
5fb96b9
Tweak csv file
pokey Aug 18, 2021
da867fb
fixes
pokey Aug 18, 2021
78dcfdd
Update src/csv_overrides.py
AndreasArvidsson Aug 18, 2021
c58a295
Update src/csv_overrides.py
AndreasArvidsson Aug 18, 2021
dc793af
Update src/csv_overrides.py
AndreasArvidsson Aug 18, 2021
3920b7c
Update src/csv_overrides.py
AndreasArvidsson Aug 18, 2021
eb956f0
Merge branch 'overrides' into pokey-csv-settings-fixes
pokey Aug 18, 2021
dccfeb7
Error message tweaks
pokey Aug 18, 2021
9a03aae
Improve error message
pokey Aug 18, 2021
7c306eb
Fixes
pokey Aug 18, 2021
f48f1a5
Improve logging
pokey Aug 20, 2021
a0ca9e9
Add "cell" selection type; merge scope lists
pokey Aug 20, 2021
7a37615
Many improvements
pokey Aug 21, 2021
409c9bc
tweak
pokey Aug 21, 2021
645be1c
tweaks
pokey Aug 21, 2021
e508fca
tweaks
pokey Aug 21, 2021
aacb7d3
again
pokey Aug 21, 2021
9c9d42d
Remove unused contexts
pokey Aug 21, 2021
f5cad4f
Support customizing range specifiers
pokey Aug 21, 2021
5cf7be6
Clean up cheatsheet
pokey Aug 21, 2021
4c31bff
Tweaks
pokey Aug 21, 2021
0aa51fc
More clean up
pokey Aug 21, 2021
f44e18a
Make list specifier configurable
pokey Aug 21, 2021
67a1fca
Ad comment
pokey Aug 21, 2021
c7b8de7
Tweaks
pokey Aug 21, 2021
32a7eaf
"specifier" => "connective"
pokey Aug 23, 2021
db0561c
Change box to square
pokey Aug 23, 2021
2149f24
Makes csv directory configurable
pokey Aug 23, 2021
0056d67
Use range connectives for subtoken ranges
pokey Aug 23, 2021
9a3ca31
Makes sub token scope type names configurable
pokey Aug 23, 2021
9a35200
Use proper csv headers
pokey Aug 23, 2021
0fc81b9
Fix removal; remove "skip past"
pokey Aug 24, 2021
84dc499
Change compound names
pokey Aug 24, 2021
7d8a206
Disable "gray" by default
pokey Aug 24, 2021
df4ddcf
Changes from discord session
pokey Aug 24, 2021
9d2bc29
Fix swap connective
pokey Aug 24, 2021
608c9b7
Use connective overrides in cheatsheet
pokey Aug 24, 2021
808fed2
Add shapes
pokey Aug 27, 2021
13551bd
Fixes
pokey Aug 30, 2021
ce9e2de
fix
pokey Aug 30, 2021
9eea68b
Change shape names
pokey Aug 31, 2021
47d4512
Remove hats from csvs
pokey Aug 31, 2021
23955ea
Disabled delimiters
pokey Aug 31, 2021
b8b8ffb
Remove shapes
pokey Aug 31, 2021
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
59 changes: 39 additions & 20 deletions src/actions/actions.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
from talon import Context, Module, actions
from talon import Module, actions, app
from dataclasses import dataclass
from ..csv_overrides import init_csv_and_watch_changes
from .homophones import run_homophones_action
from .find import run_find_action
from .call import run_call_action

mod = Module()

ctx = Context()
ctx.matches = r"""
tag: user.cursorless
"""
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved


@dataclass
class MakeshiftAction:
term: str
identifier: str
vscode_command_id: str
pre_command_sleep: float = 0
post_command_sleep: float = 0


makeshift_actions = [
MakeshiftAction("drink cell", "jupyter.insertCellAbove"),
MakeshiftAction("define", "editor.action.revealDefinition"),
MakeshiftAction("hover", "editor.action.showHover"),
MakeshiftAction("inspect", "editor.debug.action.showDebugHover"),
MakeshiftAction("pour cell", "jupyter.insertCellBelow"),
MakeshiftAction("quick fix", "editor.action.quickFix", pre_command_sleep=0.3),
MakeshiftAction("reference", "references-view.find"),
MakeshiftAction("rename", "editor.action.rename", post_command_sleep=0.1),
MakeshiftAction("drink cell", "editNewCellAbove", "jupyter.insertCellAbove"),
MakeshiftAction("define", "revealDefinition", "editor.action.revealDefinition"),
MakeshiftAction("hover", "showHover", "editor.action.showHover"),
MakeshiftAction("inspect", "showDebugHover", "editor.debug.action.showDebugHover"),
MakeshiftAction("pour cell", "editNewCellBelow", "jupyter.insertCellBelow"),
MakeshiftAction(
"quick fix", "quickFix", "editor.action.quickFix", pre_command_sleep=0.3
),
MakeshiftAction("reference", "showReferences", "references-view.find"),
MakeshiftAction("rename", "rename", "editor.action.rename", post_command_sleep=0.1),
]

makeshift_action_map = {action.term: action for action in makeshift_actions}
makeshift_action_map = {action.identifier: action for action in makeshift_actions}


@dataclass
class CallbackAction:
term: str
action: str
identifier: str
callback: callable


Expand All @@ -47,11 +46,13 @@ class CallbackAction:
CallbackAction("phones", "nextHomophone", run_homophones_action),
]

callbacks_map = {callback.action: callback.callback for callback in callbacks}
callbacks_map = {callback.identifier: callback.callback for callback in callbacks}


mod.list("cursorless_simple_action", desc="Supported actions for cursorless navigation")
pokey marked this conversation as resolved.
Show resolved Hide resolved
ctx.lists["self.cursorless_simple_action"] = {


simple_actions = {
"bottom": "scrollToBottom",
"breakpoint": "setBreakpoint",
"carve": "cut",
Expand Down Expand Up @@ -80,8 +81,8 @@ class CallbackAction:
"sort": "sort",
"take": "setSelection",
"unfold": "unfold",
**{action.term: action.term for action in makeshift_actions},
**{callback.term: callback.action for callback in callbacks},
**{action.term: action.identifier for action in makeshift_actions},
**{callback.term: callback.identifier for callback in callbacks},
}


Expand All @@ -104,3 +105,21 @@ def run_makeshift_action(action: str, targets: dict):
actions.sleep(makeshift_action.pre_command_sleep)
actions.user.vscode(makeshift_action.vscode_command_id)
actions.sleep(makeshift_action.post_command_sleep)


default_values = {
"simple_action": simple_actions,
"swap_action": {"swap": "swap"},
"move_bring_action": {"bring": "bring", "move": "move"},
"wrap_action": {"wrap": "wrap"},
"reformat_action": {"format": "reformat"},
}

ACTION_LIST_NAMES = [f"user.cursorless_{key}" for key in default_values]


def on_ready():
init_csv_and_watch_changes("actions", default_values)


app.register("ready", on_ready)
8 changes: 1 addition & 7 deletions src/actions/move_bring.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from talon import Module
from ..primitive_target import STRICT_HERE
from talon import Context, Module

mod = Module()

ctx = Context()
ctx.matches = r"""
tag: user.cursorless
"""


mod.list("cursorless_move_bring_action", desc="Cursorless move or bring actions")
ctx.lists["self.cursorless_move_bring_action"] = {"bring", "move"}


@mod.capture(rule=("<user.cursorless_target> [to <user.cursorless_target>]"))
Expand Down
11 changes: 5 additions & 6 deletions src/actions/reformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

mod = Module()

mod.list("cursorless_reformat_action", desc="Cursorless reformat action")


@mod.action_class
class Actions:
def cursorless_reformat(targets: dict, formatters: str):
"""Reformat targets with formatter"""
texts = get_text(targets, show_decorations=False)
updated_texts = list(map(
lambda text: actions.user.reformat_text(text, formatters),
texts
))
actions.user.cursorless_replace(
targets, updated_texts
updated_texts = list(
map(lambda text: actions.user.reformat_text(text, formatters), texts)
)
actions.user.cursorless_replace(targets, updated_texts)
8 changes: 5 additions & 3 deletions src/actions/swap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from ..primitive_target import BASE_TARGET
from talon import Module
from ..primitive_target import BASE_TARGET

mod = Module()

mod.list("cursorless_swap_action", desc="Cursorless swap action")


@mod.capture(rule=("swap [<user.cursorless_target>] with <user.cursorless_target>"))
def cursorless_swap(m) -> str:
@mod.capture(rule=("[<user.cursorless_target>] with <user.cursorless_target>"))
def cursorless_swap_targets(m) -> str:
target_list = m.cursorless_target_list

if len(target_list) == 1:
Expand Down
2 changes: 2 additions & 0 deletions src/actions/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod = Module()
ctx = Context()


wrappers = {
"square": ["[", "]"],
"round": ["(", ")"],
Expand All @@ -16,6 +17,7 @@
"space": [" ", " "],
}

mod.list("cursorless_wrap_action", desc="Cursorless wrap action")
mod.list("cursorless_wrapper", desc="Supported wrappers for cursorless wrap action")
ctx.lists["self.cursorless_wrapper"] = wrappers.keys()

Expand Down
80 changes: 43 additions & 37 deletions src/cheat_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
import webbrowser
import math
from .actions.actions import ACTION_LIST_NAMES

mod = Module()
mod.mode("cursorless_cheat_sheet", "Mode for showing cursorless cheat sheet gui")
Expand Down Expand Up @@ -93,33 +94,27 @@ def draw(self, canvas):
self.y = get_y(canvas)
self.w = 0

simple_actions = get_list(
"simple_action",
all_actions = {}
for name in ACTION_LIST_NAMES:
all_actions.update(get_raw_list(name))

keys = dict_remove_values(all_actions, "bring", "move", "swap", "reformat")
pokey marked this conversation as resolved.
Show resolved Hide resolved
make_dict_readable(
all_actions,
{
"call": "Call T on S",
"define": "Reveal definition",
"drink cell": "Edit new cell above",
"pour cell": "Edit new cell below",
"reference": "Show references",
"wrap": '"round" wrap T',
},
)

move_bring = {}
for action, desc in get_list("move_bring_action").items():
if desc == "Bring":
move_bring[f"{action} T1 to T2"] = "Replace T2 with T1"
move_bring[f"{action} T"] = "Replace S with T"
if desc == "Move":
move_bring[f"{action} T1 to T2"] = "Move T1 to T2"
move_bring[f"{action} T"] = "Move T to S"

all_actions = {
**simple_actions,
**move_bring,
"swap T1 with T2": "Swap T1 with T2",
"swap with T": "Swap S with T",
"wrap": '"round" wrap T',
"format * at T": "Reformat T as *",
**all_actions,
"{0} T1 to T2".format(keys["bring"]): "Replace T2 with T1",
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
"{0} T".format(keys["bring"]): "Replace S with T",
"{0} T1 to T2".format(keys["move"]): "Move T1 to T2",
"{0} T".format(keys["move"]): "Move T to S",
"{0} T1 to T2".format(keys["swap"]): "Swap T1 with T2",
"{0} T".format(keys["swap"]): "Swap S with T",
"{0} * at T".format(keys["reformat"]): "Reformat T as *",
}

actions_limit = round(len(all_actions) / 2)
Expand All @@ -134,24 +129,21 @@ def draw(self, canvas):
self.draw_items(canvas, actions_2)
self.next_column(canvas)

all_scopes = get_list("scope_type")
scopes_limit = round(len(all_scopes) - 3)
pokey marked this conversation as resolved.
Show resolved Hide resolved
scopes_1 = slice_dict(all_scopes, 0, scopes_limit)
scopes_2 = slice_dict(all_scopes, scopes_limit)

self.draw_header(canvas, "Scopes")
self.draw_items(
canvas,
get_list(
"scope_type",
{
"arg": "Argument",
"funk": "Function",
"state": "Statement",
"map": "Map / Dict",
"pair": "Key-val pair",
},
),
)
self.draw_items(canvas, scopes_1)

self.next_column(canvas)

self.draw_header(canvas, "More scopes")
self.draw_items(canvas, scopes_2)

self.next_row()
self.draw_header(canvas, "Selection types")
self.draw_items(canvas, get_list("selection_type"))

self.next_row()
Expand Down Expand Up @@ -346,12 +338,16 @@ def cursorless_open_instructions():


def get_list(name, descriptions={}):
items = registry.lists[f"user.cursorless_{name}"][0].copy()
items = get_raw_list(f"user.cursorless_{name}")
if isinstance(items, dict):
make_dict_readable(items, descriptions)
return items


def get_raw_list(name):
return registry.lists[name][0].copy()


def get_y(canvas):
return canvas.y + outer_padding

Expand All @@ -360,7 +356,7 @@ def draw_text(canvas, text, x, y):
canvas.draw_text(text, x, y + text_size + padding / 2)


def make_dict_readable(dict, descriptions):
def make_dict_readable(dict, descriptions={}):
pokey marked this conversation as resolved.
Show resolved Hide resolved
for k in dict:
desc = dict[k]
if desc in descriptions:
Expand Down Expand Up @@ -401,3 +397,13 @@ def is_in_rect(canvas, mouse_pos, rect):
def slice_dict(dict: dict, start: int, end: int = None):
keys = sorted(dict)[start:end]
return {key: dict[key] for key in keys}


def dict_remove_values(dict: dict, *values: list):
pokey marked this conversation as resolved.
Show resolved Hide resolved
keys = {}
for key, value in dict.copy().items():
if value in values:
del dict[key]
keys[value] = key
assert len(values) == len(keys)
return keys
4 changes: 0 additions & 4 deletions src/compound_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
mod = Module()
ctx = Context()

ctx.matches = r"""
AndreasArvidsson marked this conversation as resolved.
Show resolved Hide resolved
tag: user.cursorless
"""

range_specifier = {
"past",
"until",
Expand Down
Loading