python
The community/lang/python
directory contains files that provide support for Python development in Talon. It primarily defines code actions, lists, and grammar to make writing Python code easier and faster using voice commands.
The most important files in this directory are:
-
python.py
: This file defines the core logic for Python support. It includes:- A context that activates when the code language is set to Python.
- Several lists (
ctx.lists
) that provide vocabulary for common Python constructs. These include:user.code_common_function
: Common Python functions likeprint
,len
, andrange
.user.python_docstring_fields
: Fields used in Python docstrings like:param:
,:return:
, and:type:
.user.code_type
: Python data types such asint
,str
,list
, anddict
.user.code_keyword
: Python keywords likeclass
,return
,import
,True
, andFalse
.user.python_exception
: A comprehensive list of Python exceptions.
- An action class (
UserActions
) that implements the following:- Actions to insert code operators (e.g.,
+
,-
,*
,/
,=
,==
,!=
). - Actions to insert code structures such as
if
,elif
,else
,for
,while
, andmatch
/case
. - Actions to insert common keywords like
class
,return
,import
,None
,True
, andFalse
. - Actions to insert function definitions (both public and private).
- Actions to insert type hints for variables and return types.
- Actions to insert
break
andcontinue
statements. - Actions to insert comments and docstrings.
- Actions to insert code operators (e.g.,
-
python.talon
: This file defines the Talon grammar for Python. It includes:- Tags for Python (e.g.,
user.code_imperative
,user.code_object_oriented
,user.code_comment_documentation
). - Settings to control how function names and variable names are formatted.
- Grammar rules that map voice commands to actions defined in
python.py
. For example:state def
insertsdef
.state try
insertstry:\n
.state raise {user.python_exception}
inserts araise
statement with the selected exception.dock string
calls theuser.code_comment_documentation()
action to insert a docstring.dock {user.python_docstring_fields}
inserts a docstring field.dock type {user.code_type}
inserts a type hint in a docstring.dock returns type {user.code_type}
inserts a return type hint in a docstring.import <user.code_libraries>
inserts an import statement for a library and moves the cursor to the end of the line.
- Tags for Python (e.g.,
Together, these files provide a comprehensive set of tools for coding in Python with Talon. The python.py
file defines the logic and available actions, while python.talon
maps voice commands to those actions and sets up the grammar. The lists in python.py
provide the necessary vocabulary for these commands to function.