Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
3 changes: 2 additions & 1 deletion cursorless-talon/src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from .bring_move import BringMoveTargets
from .execute_command import cursorless_execute_command_action
from .generate_snippet import cursorless_generate_snippet_action
from .homophones import cursorless_homophones_action
from .replace import cursorless_replace_action

Expand Down Expand Up @@ -50,12 +51,12 @@
]

callback_actions: dict[str, Callable[[CursorlessExplicitTarget], None]] = {
"generateSnippet": cursorless_generate_snippet_action,
"nextHomophone": cursorless_homophones_action,
}

# Don't wait for these actions to finish, usually because they hang on some kind of user interaction
no_wait_actions = [
"generateSnippet",
"rename",
]

Expand Down
50 changes: 50 additions & 0 deletions cursorless-talon/src/actions/generate_snippet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import glob
from pathlib import Path

from talon import actions, settings

from ..targets.target_types import CursorlessExplicitTarget


def cursorless_generate_snippet_action(target: CursorlessExplicitTarget):
actions.user.private_cursorless_command_no_wait(
{
"name": "generateSnippet",
"target": target,
"dirPath": get_dir_path(),
}
)


def get_dir_path() -> str:
settings_dir = get_setting_dir()
if settings_dir is not None:
return settings_dir
return get_community_snippets_dir()


def get_community_snippets_dir() -> str:
files = glob.iglob(
f"{actions.path.talon_user()}/**/snippets/snippets/*.snippet",
recursive=True,
)
for file in files:
return str(Path(file).parent)
raise ValueError("Could not find community snippets directory")


def get_setting_dir() -> str | None:
try:
setting_dir = settings.get("user.snippets_dir")
if not setting_dir:
return None

dir = Path(setting_dir)

if not dir.is_absolute():
user_dir = Path(actions.path.talon_user())
dir = user_dir / dir

return str(dir.resolve())
except Exception:
return None
1 change: 1 addition & 0 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface PasteActionDescriptor {

export interface GenerateSnippetActionDescriptor {
name: "generateSnippet";
dirPath?: string;
snippetName?: string;
target: PartialTargetDescriptor;
}
Expand Down
1 change: 1 addition & 0 deletions packages/cursorless-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"lodash-es": "^4.17.21",
"moo": "0.5.2",
"nearley": "2.20.1",
"talon-snippets": "1.1.0",
"uuid": "^10.0.0",
"zod": "3.23.8"
},
Expand Down
Loading
Loading