Skip to content

Commit

Permalink
Experiments with cursorless snippet sources
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Jun 3, 2024
1 parent 5bef000 commit cbb1c3e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/vscode/vscode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from os.path import expanduser
from pathlib import Path
from typing import Any

from talon import Context, Module, actions, app, clip

Expand Down Expand Up @@ -283,6 +284,15 @@ def vscode_add_missing_imports():
{"kind": "source.addMissingImports", "apply": "first"},
)

def insert_snippet_with_cursorless_target(
name: str, variable_name: str, target: Any
):
"""Insert snippet <name> with cursorless target <target>"""
actions.user.insert_snippet_by_name(
name,
{variable_name: actions.user.cursorless_get_text(target)},
)


@mac_ctx.action_class("user")
class MacUserActions:
Expand Down
3 changes: 3 additions & 0 deletions apps/vscode/vscode.talon
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ replace <user.cursorless_target>:
user.replace("")
key(cmd-alt-l)

none check <user.cursorless_target>:
user.insert_snippet_with_cursorless_target("nullCheck", "1", cursorless_target)

full screen: user.vscode("workbench.action.toggleFullScreen")

curse undo: user.vscode("cursorUndo")
Expand Down
22 changes: 22 additions & 0 deletions core/snippets/snippets/nullCheck.snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: nullCheck
phrase: none check
insertionScope: statement

$1.wrapperPhrase: none check cond
$1.wrapperScope: statement
$0.wrapperPhrase: none check
$0.wrapperScope: statement
---

language: javascript
-
if ($1 != null) {
$0
}
---

language: python
-
if $1 is not None:
$0
---

0 comments on commit cbb1c3e

Please sign in to comment.