Skip to content

Instantly share code, notes, and snippets.

@Antman261
Created February 2, 2025 02:40
Show Gist options
  • Save Antman261/8ed2f0decfddbaa107607853e1748bf6 to your computer and use it in GitHub Desktop.
Save Antman261/8ed2f0decfddbaa107607853e1748bf6 to your computer and use it in GitHub Desktop.
tag: user.code_mode
code.language: typescript
-
# Keywords
export from file: user.insert_between("export * from './", "';")
import from package <user.text>$:
target = user.formatted_text(text or "", 'DASH_SEPARATED')
user.insert_between("import {{ ", " }} from '{target}';")
[import] from package$: user.insert_between("import {{ }} from '", "';")
(funk | function) [<user.text>]$:
name = user.formatted_text(text or "", 'PRIVATE_CAMEL_CASE')
user.insert_between("function {name}(", ") {{}}")
export: "export "
as: " as "
satisfies [<user.text>]:
constraint = user.formatted_text(text or "", 'PUBLIC_CAMEL_CASE')
"satisfies {constraint}"
type$: "type "
const: "const "
const <user.text>$:
name = user.formatted_text(text, 'PRIVATE_CAMEL_CASE')
user.insert_between("const {name} = ", ";")
async: "async "
await: "await "
(return | turned): "return "
extends: "extends "
throw: "throw new "
# Types
(type | tip) void: "void"
(object | odder) type <user.text>$:
"type {user.formatted_text(text, 'PUBLIC_CAMEL_CASE')} = {"
key(enter)
type <user.text>:
txt = text or ""
"type {user.formatted_text(txt, 'PUBLIC_CAMEL_CASE')} = "
type$: user.insert_between("type ", " = ")
(type | tip) (lam | lambda | arrow) void: "() => void"
(type | tip) promise: user.insert_between("Promise<", ">")
# Control Flow
for each [<user.text>] of [<user.text>]:
var = text_1 or ""
obj = text_2 or ""
varf = user.formatted_text(var, 'PRIVATE_CAMEL_CASE')
insert("for (const {varf} of {user.formatted_text(obj, 'PRIVATE_CAMEL_CASE')}) {{}}")
for each [<user.text>] in [<user.text>]:
var = text_1 or ""
obj = text_2 or ""
varf = user.formatted_text(var, 'PRIVATE_CAMEL_CASE')
insert("for (const {varf} in {user.formatted_text(obj, 'PRIVATE_CAMEL_CASE')}) {{}}")
(branch | fork)$: user.insert_between("if (", ") {{")
(branch | fork) that$:
text = edit.selected_text()
user.insert_between("if (", ") {{{text}}}")
try$: user.insert_between("try {{", "}} catch (error) {{}}")
try that$:
text = edit.selected_text()
user.insert_between("try {{{text}}} catch (error) {{", "}}")
while loop: user.insert_between("while (", ") {{")
break: "break;"
case: "\ncase "
# Operators
arrow funk: user.insert_between("(", ") => ")
empty (lam | lambda | arrow): "() => "
adder [<user.number_prose_unprefixed>]$: " += {number_prose_unprefixed or ''};"
plus plus$: "++;"
ander: " && "
order: " || "
# Comments (mints)
(dog | dock) (string | mint):
"/**"
key(enter)
mint: "// "
mint block: user.insert_between("/* ", " */")
# Testing
deno test: user.insert_between("Deno.test('", "', async ({{ step }}) => {{}});")
deno step: user.insert_between("await step('", "', async () => {{}});")
test describe: user.insert_between("describe('", "', () => {{}});")
test case: user.insert_between("it('", "', () => {{}});")
test expect: user.insert_between("expect(", ");")
too equal:
edit.right()
user.insert_between(".toEqual(", ")")
tag(): user.cursorless_use_community_snippets
from talon import Module, Context, actions, app
_name = 'code_mode'
_tag_name = f'user.{_name}'
mod = Module()
mod.tag(_name, desc="Succinct coding commands")
ctx = Context()
def add_to_talon_hud_theme():
try:
theme = actions.user.hud_get_theme()
theme.values["code_mode_colour"] = "#5d1dc4"
except Exception as ex:
print("talon hud not available")
app.register("ready", add_to_talon_hud_theme)
@mod.action_class
class Actions:
def is_code_mode_active()->bool:
"""Indicates if code mode active"""
return _tag_name in ctx.tags
def activate_code_mode():
"""activates code mode"""
ctx.tags = [_tag_name]
def deactivate_code_mode():
"""Deactivates code mode"""
ctx.tags = []
tag: user.code_mode
-
(halt | stop) (coding | code) [mode] | coding (halt | stop): user.deactivate_code_mode()
mode: command
not tag: user.code_mode
-
start coding: user.activate_code_mode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment