Skip to content

lua

The community/lang/lua directory contains files that provide support for the Lua programming language in Talon. It defines a grammar, common functions, and operators.

The file lua.talon defines the core Talon grammar for Lua. It includes:

  • Tags: Assigns tags such as user.code_imperative, user.code_comment_line, user.code_comment_block, etc., which are used in the lua.py file to trigger actions.
  • Settings: Configures formatting settings such as user.code_private_function_formatter to SNAKE_CASE.
  • States: Defines keywords and common code snippets like local, end, return nil, etc., that can be inserted by voice. It also defines how to insert formatted text, including labels.
  • Commands: Provides voice commands for common tasks such as requiring libraries, declaring variables, calling methods, and accessing array indices.

The file stylua.talon provides commands related to the Stylua linter, such as inserting comments to ignore linting for a line, block, or section.

The file lua.py implements the actions defined in lua.talon. It also defines a few settings, captures, lists, and actions:

  • Settings: Defines lua_version, which dictates the usage of bitwise operators based on the Lua version.
  • Tags: Defines the stylua tag, which is used to enable linting commands.
  • Lists: Defines lists of common Lua functions and libraries, such as string.sub, io.write, table, math, etc. These lists are available for use in the lua.talon file to provide voice commands for inserting common functions.
  • Capture: The lua_functions capture is used to identify and return a Lua function that has been dictated.
  • Actions: Implements actions for inserting various code constructs, such as if/else blocks, for/while loops, comments, boolean/null values, private/public functions, libraries, array subscripts, operators, and more. These actions use the user.formatted_text and actions.insert functions to insert code in the correct format and position. Some actions change based on the user.lua_version setting.

These files work together to provide a comprehensive Lua support for Talon. The lua.talon file defines the voice grammar, which uses tags, states, and commands to define the structure of the Lua code. The lua.py file implements the actual actions, lists, and settings used by the voice commands. Together, these files allow users to write Lua code using voice commands in Talon, using the appropriate syntax and formatting.