Skip to content

kotlin

The community/lang/kotlin directory contains files that provide support for the Kotlin programming language within the Talon voice control system.

The kotlin.talon file (kotlin.talon) declares the language as Kotlin and assigns various tags related to code structure, comments, data types, functions, libraries, and operators. These tags enable language-specific features in Talon. It also sets formatting rules for different function and variable access modifiers (private, protected, and public) by setting corresponding settings to use the "PRIVATE_CAMEL_CASE" formatter.

The kotlin.py file (kotlin.py) defines the core functionality for Kotlin within Talon. It establishes a context that activates when the code language is Kotlin. It defines a list of user.code_keyword that are common Kotlin keywords. It then defines a class UserActions with many methods. Most of these methods define actions for inserting specific code elements, such as operators, keywords, comments, and code structures. Here is a summary of the most interesting methods:

  • code_comment_line_prefix(): Inserts a line comment prefix (//).
  • code_operator_lambda(): Inserts the lambda operator (->).
  • code_operator_subscript(): Inserts square brackets [] for array access, placing the cursor in between them.
  • code_operator_*(): There are many methods for inserting various operators such as assignment (=), math (+, -, *, /, %), comparison (==, !=, >, <, >=, <=), logical (&&, ||), and bitwise (&, |, ^, <<, >>) operators. Each also has a corresponding assignment operator.
  • code_self(): Inserts the this keyword.
  • code_insert_null(), code_insert_is_null(), and code_insert_is_not_null(): Inserts null, == null, and != null respectively.
  • code_state_*(): These methods insert code blocks for control flow statements, such as if, else if, else, when, for, and while, placing the cursor in the correct position. The when state is used because Kotlin uses when instead of switch.
  • code_define_class(): Inserts the class keyword.
  • code_state_return(): Inserts the return keyword.
  • code_insert_function(text, selection): This inserts a function call with the specified text and selection.
  • code_default_function(text), code_public_function(text), code_private_function(text): These methods insert function definitions with the specified text, applying formatting based on visibility (private, protected, or public) and inserting the cursor in the correct location. They use the formatters defined in kotlin.talon.