go
This directory provides comprehensive voice-coding support for the Go (Golang) programming language in Talon. It defines language-specific syntax, common types, keywords, built-in functions, and idiomatic Go constructs (such as error handling patterns).
How It Works
The Go support is split between a Python implementation that registers language-specific behaviors and several Talon files and list configurations that map spoken phrases to Go syntax.
- Behavior and Logic: go.py sets up a Talon context targeted at
code.language: go. It registers operator definitions (such as pointers, channels, bitwise, and math operators), implements custom formatting rules, and establishes dynamic captures for compound type names. - Voice Commands: go.talon activates standard language tags, configures variable/function formatters, and provides commands for idiomatic Go constructs like fast variable declaration, channel operations, and error checking.
- Vocabulary Lists: A series of
.talon-listfiles define spoken mappings for types, keywords, and standard library functions.
Core Components
Python Integration (go.py)
The Python file is the backend for Go support. It performs several key tasks:
- Operator Mapping: Implements the
user.code_get_operatorsaction to provide standard assignments, math, bitwise operations, and pointer symbols (such as&for address-of and*for indirection). - Type Capture Engines: Defines captures for variable-width numeric types:
<user.go_int_type>: Builds integer types (e.g.,uint32,int64) dynamically.<user.go_float_type>: Works with float_type_bit_width.talon-list to resolve float widths (float32,float64).<user.go_complex_type>: Works with complex_type_bit_width.talon-list to resolve complex number widths (complex64,complex128).- These are combined with standard types in a single
user.code_typecapture.
- Language Actions: Implements language-specific logic for functions and null checks (overriding standard actions to output
nilinstead ofnullorNone).
Command Configurations (go.talon)
The main Talon file binds spoken syntax to actions when editing Go files.
- Formatters: Enforces
PRIVATE_CAMEL_CASEfor private functions and variables, andPUBLIC_CAMEL_CASEfor public Go functions (to match Go's capitalization-based visibility rules). - Idiomatic Error Handling: Provides rapid commands for Go's frequent error-checking boilerplate:
if errtriggersif err != nil {and moves to the next line.if not errtriggersif err == nil {.
- Type Casting: Integrates with the dynamic type engine via:
cast to <user.code_type>: Generates a type cast structure (e.g.,int(...)).cast wrap <user.code_type>: Wraps the currently selected text in a type cast.
Language Vocabulary and Lists
Several dedicated list files populate Go's spoken dictionary:
- code_keyword.talon-list: Standard Go control flow structures and keywords (e.g.,
defer,go,select,chan,interface,struct). - code_type.talon-list: Standard primitive types such as
bool,string,rune,byte, anderror. - code_common_function.talon-list: Common built-ins and standard library functions from packages like
fmt(e.g.,fmt.Printf,fmt.Println),strconv(e.g.,strconv.Atoi), and core utilities (e.g.,len,cap,make,append).