Skip to content

talon

The community/lang/talon directory contains files that extend Talon's functionality for editing and creating Talon code, including .talon and .talon-list files. It also provides utilities for working with Talon's API in Python.

Here's a breakdown of the key files and how they work together:

  • talon.py: This Python file is the core of the Talon language support. It defines several contexts (ctx_talon, ctx_talon_python, and ctx_talon_lists) that provide actions specific to Talon code and Python code used within Talon.
    • It defines tags like user.talon_python and user.talon_populate_lists to enable certain features.
    • It creates lists (user.talon_actions, user.talon_lists, etc.) that can be used in Talon scripts. The user.talon_populate_lists tag must be active for these lists to populate.
    • It registers on_update_decls which automatically updates the talon lists when the Talon registry changes. This allows the lists of actions, captures etc, to be populated from the global talon state.
    • It defines actions like talon_code_insert_action_call, talon_code_enable_tag, and talon_code_enable_setting which can be used to insert code snippets and modify the Talon state when writing Talon code.
    • It defines action classes for the different contexts, providing different behavior for Python and Talon files.
    • It provides common code operators and a generic function insert action for convenience in both Talon and Python contexts.
  • talon_common.talon: This Talon file defines commands that are common to both Talon and Python files. It includes commands for:

    • Setting tags using tag set {user.talon_tags}.
    • Using lists with list {user.talon_lists}: "{{{talon_lists}}}".
    • Using captures with capture {user.talon_captures}: "<{talon_captures}>".
    • Setting settings with setting {user.talon_settings}: user.talon_code_enable_setting(talon_settings).
    • Dictating key combos with key <user.keys> over: "{keys}" and key <user.modifiers> over: "{modifiers}".
    • Inserting actions with action {user.talon_actions}: user.talon_code_insert_action_call(talon_actions, edit.selected_text()).
    • It activates when the user.talon_python tag is enabled or when the code language is set to either talon or python.
  • talon_python_activator.talon: This file activates the user.talon_python tag which enables the Python specific functionality in talon.py and talon_common.talon. By default it is enabled when editing any python file, but it also includes commented out examples to restrict this functionality to only certain python files.

  • talon-list.talon: This file provides a command to insert a list when writing a talon list file. This command is list [require] {user.talon_lists}: "list: {talon_lists}" and it requires that the user.talon_populate_lists tag is active.
  • talon_code_common_function.talon-list: This file defines a list of common functions (e.g. "insert", "key", "print") that are available when writing talon code. This is used by the user.code_functions_common tag enabled in talon.talon.
  • talon_context.talon: This file provides commands for inserting context requirements in .talon and .talon-list files. It enables adding os, win.title, app, mode, tag, and hostname to a context. It requires that the user.talon_python tag is active.
  • talon.talon: This file activates several tags that are useful when writing talon code. It activates the user.code_operators_math, user.code_operators_assignment, user.code_comment_line, and user.code_functions_common tags. It also shows an example of enabling the user.talon_populate_lists tag (which is disabled by default) and it also defines a command setting block: insert("settings():\n\t") that allows users to insert the beginning of a settings block.

In summary, these files work together to provide a comprehensive set of tools for creating and editing Talon code. They provide context-aware actions, auto-completion for Talon constructs, and ways to manage and navigate code. The talon.py file is the core, defining the logic, while the .talon files provide the voice commands and context activation.