Skip to content

snippets

This directory contains the central repository of voice-triggerable code snippets for the Talon community configuration. Rather than maintaining separate snippet libraries for every programming language, these files leverage a multi-language format. This design allows a single spoken phrase to contextually insert the syntactically correct code block, formatter, and wrapper behavior based on the file type currently being edited.

How the Snippet Engine Works

Each .snippet file is structured with a YAML-like header followed by one or more language-specific template sections separated by --- delimiters.

A snippet typically declares: * name: The unique identifier for the snippet. * phrase: The spoken voice command trigger (e.g., "for each" or "class"). * insertionScope: The structural context (like statement, class, or branch) indicating where the snippet is valid. * Variable formatters: Custom rules targeting placeholders (e.g., $1.insertionFormatter: PUBLIC_CAMEL_CASE dynamically formats the user's spoken variable name). * Wrapper configurations: Rules defining how existing selected text is encapsulated when the snippet is executed as a "wrap" command (using $0.wrapperPhrase and $0.wrapperScope). * Placeholders: $1, $2, ... represent sequential tab stops, while $0 defines the final cursor position after completing the snippet.


Code Generation & Meta-Snippets

Meta-Snippet Authoring

  • communitySnippets.snippet: A bootstrap snippet suite designed to help authors write new snippets. It includes voice shortcuts to generate headers, variable formatters, language declarations, default variables, and the structural blocks of the snippet format itself.

Control Flow & Loop Snippets

These snippets implement standard logical branching and iteration across dozens of target languages.

Conditional Branching

Pattern Matching & Switches

  • switchStatement.snippet: Maps the voice command "switch" to appropriate patterns like standard switch blocks, Python's modern match statement, or Rust's match.
  • caseStatement.snippet & defaultStatement.snippet: Define standard branching cases within match/switch scopes, supporting arrow syntaxes (e.g., Scala's =>, Kotlin's ->, and Rust's =>).

Iteration & Loops

Loop Controls


Structural & Object-Oriented Declarations

These templates assist in declaring fundamental object-oriented, structural, and procedural code blocks.


Dependency Management & Compilation

Snippets designed to pull in external resources, header files, or manage preprocessor operations.


Exception Handling

  • tryStatement.snippet: Scaffolds standard error-trapping blocks.
  • catchStatement.snippet: Inserts language-specific catch clauses (e.g., standard except Exception as ex: in Python, generic catch (\Throwable \$exception) in PHP, or warning/error handlers in R).
  • tryCatchStatement.snippet: Combines try and catch blocks into a single action with boilerplate error parameters already typed out.
  • finallyStatement.snippet: Appends cleanup logic wrappers.
  • throwException.snippet: Generates error instantiation and propagation statements, such as raise ValueError(f"$0") or throw std::runtime_error("$0").

Language-Specific Modules

Certain snippets cater entirely to the paradigms of specific ecosystems.

Python & Talon Customization

  • python.snippet: Dedicated heavily to Python development with an emphasis on Talon API scripting. It defines boilerplate code for registering Talon Modules, Contexts, action classes, settings, lists, tags, and capture classes. It also implements standard Python structures like dict/set/list comprehensions and generator expressions.

Rust

  • rust.snippet: Sets up structural configurations, testing modules (#[cfg(test)]), trait definitions and implementation blocks (impl), if let destructurings, let else guard statements, and unsafe blocks.

JavaScript & React

  • javascript.snippet: Standardizes local bindings (const and let with CamelCase automatic formatting), arrow functions, self-calling functions, and loops.
  • javascriptreact.snippet: Simplifies modern React hook development, generating React useState (along with capitalized setter naming automation), useRef, and useEffect arrays.

Web & Document Formats

  • html.snippet: Helps construct table architectures, list infrastructures, and standard JSX/HTML attributes.
  • xml.snippet: Creates matching open/close tags with formatted element tags.
  • markdown.snippet: Provides rapid authoring shortcuts for Markdown links, images, bold/italic text styles, blockquotes, and checkbox lists.

Other Languages

  • c.snippet: Focuses on typdef structural layouts and #pragma commands.
  • cpp.snippet: Implements C++ templates, member access specifiers (public:, private:), automatic variable initialization, static casting, and robust header guard wrappers.
  • java.snippet: Introduces JVM synchronized blocks.
  • go.snippet: Scaffolds concurrency-based select statements.
  • lua.snippet: Implements standard table traversal patterns (pairs and ipairs).
  • elixir.snippet: Outlines conditional cond do pattern matches.
  • sql.snippet: Generates DDL schemas (CREATE TABLE).
  • shellscript.snippet: Automatically places a strict shebang header (#!/usr/bin/env bash set -euo pipefail) at the start of scripts.
  • talon.snippet: Rapidly registers custom Talon voice commands that invoke RPC utilities using the clipboard contents.
  • typescript.snippet: Acts as a targeted context hook for TypeScript development.

Utility & Syntactic Helpers

These smaller snippets optimize everyday text manipulation.