-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#160 (WIP) Initial VSCode snippet support
- Using captures for simplicity
- Loading branch information
Showing
7 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from talon import Context, actions, ui, Module, app | ||
|
||
ctx = Context() | ||
ctx.matches = r''' | ||
app: Code | ||
app: Code - OSS | ||
app: Code | ||
app: Visual Studio Code | ||
app: Code.exe | ||
mode: user.csharp | ||
mode: command | ||
and code.language: csharp | ||
''' | ||
#short name -> ide clip name | ||
ctx.lists["user.snippets"] = { | ||
#"funky": "def", | ||
#"for": "for", | ||
"for each": "foreach", | ||
"while": "while", | ||
"class": "class", | ||
#"class funky": "def(class method)", | ||
#"class static funky": "def(class static method)", | ||
"if": "if", | ||
"else": "else", | ||
"try except": "try", | ||
"try finally": "tryf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from talon import Context, actions, ui, Module, app | ||
|
||
ctx = Context() | ||
ctx.matches = r''' | ||
app: Code | ||
app: Code - OSS | ||
app: Code | ||
app: Visual Studio Code | ||
app: Code.exe | ||
mode: user.python | ||
mode: command | ||
and code.language: python | ||
''' | ||
#short name -> ide clip name | ||
ctx.lists["user.snippets"] = { | ||
"funky": "def", | ||
"for": "for", | ||
"while": "while", | ||
"class": "class", | ||
"class funky": "def(class method)", | ||
"class static funky": "def(class static method)", | ||
"with": "with", | ||
"if": "if", | ||
"if else": "if/else", | ||
"else if": "elif", | ||
"lambda": "lambda", | ||
"try except": "try/except", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ tag(): tabs | |
tag(): ide | ||
tag(): line_commands | ||
tag(): splits | ||
tag(): snippets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#defines placeholder actions and captures for ide-specific snippet functionality | ||
from talon import Module, actions, app, Context | ||
|
||
mod = Module() | ||
ctx = Context() | ||
mod.tag('snippets', desc='Tag for enabling code snippet-related commands') | ||
mod.list('snippets', desc='List of code snippets') | ||
|
||
@mod.capture | ||
def snippets(m) -> list: | ||
"""Returns a snippet name""" | ||
|
||
@mod.action_class | ||
class Actions: | ||
def snippet_search(text: str): | ||
"""Triggers the program's snippet search""" | ||
|
||
def snippet_insert(text: str): | ||
"""Inserts a snippet""" | ||
|
||
@ctx.capture(rule='{user.snippets}') | ||
def snippets(m): | ||
return m.snippets | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tag: snippets | ||
- | ||
snip <user.snippets>: user.snippet_insert(user.snippets) | ||
hunt snip <user.text>: user.snippet_search(user.text) | ||
hunt snip: user.snippet_search("") |