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

Add wrapper snippets #1305

Closed
wants to merge 11 commits into from
21 changes: 21 additions & 0 deletions core/snippets/snippets_insert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from typing import Any

from talon import Module, actions

Expand Down Expand Up @@ -47,3 +48,23 @@ def insert_snippet_by_name_with_phrase(name: str, phrase: str):
)

actions.user.insert_snippet_by_name(name, substitutions)

def wrap_with_snippet(
body: str,
target: Any,
knausj85 marked this conversation as resolved.
Show resolved Hide resolved
variable_name: str,
scope: str = None,
):
"""Wrap the target with snippet"""

def wrap_with_snippet_by_name(name: str, target: Any):
"""Wrap the target with snippet <name>"""
index = name.rindex(".")
snippet_name = name[:index]
variable_name = name[index + 1]
snippet: Snippet = actions.user.get_snippet(snippet_name)
variable = snippet.get_variable_strict(variable_name)

actions.user.wrap_with_snippet(
snippet.body, target, variable.name, variable.wrapper_scope
)
1 change: 1 addition & 0 deletions core/snippets/snippets_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def create_snippet(
name=document.name or default_context.name,
languages=document.languages or default_context.languages,
phrases=document.phrases or default_context.phrases,
insertion_scopes=document.insertionScopes or default_context.insertionScopes,
variables=combine_variables(default_context.variables, document.variables),
body=normalize_snippet_body_tabs(document.body),
)
Expand Down