# defines placeholder actions and captures for ide-specific snippet functionality from talon import Module, actions, app, Context, imgui, registry mod = Module() mod.tag("snippets", desc="Tag for enabling code snippet-related commands") mod.list("snippets", desc="List of code snippets") @imgui.open(software=app.platform == "linux") def gui(gui: imgui.GUI): gui.text("snippets") gui.line() if "user.snippets" in registry.lists: function_list = sorted(registry.lists["user.snippets"][0].keys()) # print(str(registry.lists["user.snippets"])) # print(str(registry.lists["user.code_functions"])) if function_list: for i, entry in enumerate(function_list): gui.text("{}".format(entry, function_list)) @mod.action_class class Actions: def snippet_search(text: str): """Triggers the program's snippet search""" def snippet_insert(text: str): """Inserts a snippet"""
mod.list("code_functions", desc="List of functions for active language") mod.list("code_types", desc="List of types for active language") mod.list("code_libraries", desc="List of libraries for active language") setting_private_function_formatter = mod.setting("code_private_function_formatter", str) setting_protected_function_formatter = mod.setting( "code_protected_function_formatter", str ) setting_public_function_formatter = mod.setting("code_public_function_formatter", str) setting_private_variable_formatter = mod.setting("code_private_variable_formatter", str) setting_protected_variable_formatter = mod.setting( "code_protected_variable_formatter", str ) setting_public_variable_formatter = mod.setting("code_public_variable_formatter", str) mod.tag("code_comment", desc="Tag for enabling generic comment commands") mod.tag("code_block_comment", desc="Tag for enabling generic block comment commands") mod.tag("code_operators", desc="Tag for enabling generic operator commands") mod.tag( "code_generic", desc="Tag for enabling other basic programming commands (loops, functions, etc)", ) key = actions.key function_list = [] library_list = [] extension_lang_map = { "asm": "assembly", "bat": "batch", "c": "c", "cmake": "cmake",
from talon import Module, actions # --- Tag definition --- mod = Module() mod.tag("pages", desc="Anything with page navigation") # --- Define actions --- @mod.action_class class Actions: def page_current() -> int: """Return current page number""" def page_next(): """Go to next page""" actions.user.page_jump(actions.user.page_current() + 1) def page_previous(): """Go to previous page""" actions.user.page_jump(actions.user.page_current() - 1) def page_jump(number: int): """Go to page number""" def page_final(): """Go to final page"""
from typing import Union import math, time import typing mod = Module() narrow_expansion = mod.setting( "grid_narrow_expansion", type=int, default=0, desc= """After narrowing, grow the new region by this many pixels in every direction, to make things immediately on edges easier to hit, and when the grid is at its smallest, it allows you to still nudge it around""", ) mod.tag("mouse_grid_showing", desc="Tag indicates whether the mouse grid is showing") mod.tag("mouse_grid_enabled", desc="Tag enables the mouse grid commands.") ctx = Context() class MouseSnapNine: def __init__(self): self.screen = None self.rect = None self.history = [] self.img = None self.mcanvas = None self.active = False self.count = 0 self.was_control_mouse_active = False self.was_zoom_mouse_active = False
from talon import Context, Module mod = Module() tagList = ["firefox", "gdb", "tmux", "tabs"] modes = { "gdb": "a way to force gdb commands to be loaded", } for entry in tagList: mod.tag(entry, f"tag to load {entry} and/or related plugins ") for key, value in modes.items(): mod.mode(key, value)
ctx.lists["self.language_mode"] = { name: language for language in language_extensions for name in language_name_overrides.get(language, [language]) } # Maps extension to languages. extension_lang_map = { '.' + ext: language for language, extensions in language_extensions.items() for ext in extensions.split() } # Create a context for each defined language for lang in language_extensions.keys(): mod.tag(lang) mod.tag(f"{lang}_forced") c = Context() # Context is active if language is forced or auto language matches c.matches = f""" tag: user.{lang}_forced tag: user.auto_lang and code.language: {lang} """ c.tags = [f"user.{lang}"] # Create a mode for the automated language detection. This is active when no lang is forced. mod.tag("auto_lang") ctx.tags = ["user.auto_lang"]
import platform, shutil, subprocess from talon import Module, Context module = Module() module.tag( "arch", "Active when the OS is Arch Linux. Will NOT match on derivatives like Manjaro.", ) module.tag("manjaro", "Active when the OS is Manjaro.") module.tag("ubuntu", "Active when the OS is Ubuntu.") module.tag("debian", "Active when the OS is Debian.") module.tag("fedora", "Active when the OS is Fedora.") context = Context() if platform.system() == "Linux" and shutil.which("lsb_release"): release_id_output = subprocess.run( ["lsb_release", "-i"], capture_output=True).stdout.decode("utf-8") release_id = release_id_output.split(":", 1)[1].strip() if "arch" in release_id.lower(): # TODO: Arch matching untested context.tags = ["user.arch"] elif "manjaro" in release_id.lower(): # Manjaro matching is tested & works context.tags = ["user.manjaro"] elif "ubuntu" in release_id.lower(): # TODO: Ubuntu matching untested context.tags = ["user.ubuntu"] elif "debian" in release_id.lower():
# These are pluralized because of how you speak vim grammars # ex: yank inside braces "curly braces": "{", "braces": "{", "square brackets": "[", "squares ": "[", "brackets": "[", "backticks": "`", "sentence": "s", "sentences": "s", "paragraph": "p", "paragraphs": "p", "tag block": "t", } mod.tag("vim", desc="a tag to load various vim plugins") mod.setting( "vim_preserve_insert_mode", type=int, default=1, desc="If normal mode actions are called from insert mode, stay in insert", ) mod.setting( "vim_adjust_modes", type=int, default=1, desc="User wants talon to automatically adjust modes for commands", ) mod.setting( "vim_notify_mode_changes", type=int,
from typing import Callable, Any from talon import app, Module, actions, Context, speech_system, cron, scope, fs from .typing import HudWalkThrough, HudWalkThroughStep, HudContentPage from ..utils import retrieve_available_voice_commands, md_to_richtext_content from ..configuration import hud_get_configuration import os import json import copy walkthrough_file_location = os.path.join(hud_get_configuration("content_preferences_folder"), "walkthrough.csv") initial_walkthrough_title = "Head up display" mod = Module() mod.tag("talon_hud_walkthrough", desc="Whether or not the walk through widget is on display") ctx = Context() class WalkthroughPoller: content = None enabled = False scope_job = None walkthroughs = None walkthrough_steps = None current_walkthrough = None current_walkthrough_title = None current_stepnumber = -1 current_words = [] in_right_context = True development_mode = False reload_job = None next_step_job = None
from talon import Context, Module, actions, app mod = Module() ctx = Context() ctx.matches = r""" os: linux tag: user.terminal """ mod.tag("service_manager", desc="generic service manager support") mod.tag("systemd", desc="systemd service management") mod.tag("upstart", desc="ubuntu upstart service management") @mod.action_class class Actions: def service(): """Run the default service manager""" def service_status(): """Show the service status""" def service_stop(): """Stop a service""" def service_start(): """Start a service""" def service_reload(): """Reload a service"""
from talon import Module mod = Module() mod.tag("yarn", desc="command for working with the yarn package manager")
from talon import Context, Module ctx = Context() mod = Module() mod.tag("code_operators_array", desc="Tag for enabling array operator commands") @mod.action_class class Actions: def code_operator_subscript(): """code_operator_subscript (e.g., C++ [])"""
from talon import Module, Context mod = Module() mod.tag("terraform", desc="tag for enabling terraform commands in your terminal")
from typing import Any from talon import Context, Module, actions, app from ..csv_overrides import init_csv_and_watch_changes from ..paired_delimiter import paired_delimiters_map mod = Module() mod.tag( "cursorless_experimental_snippets", desc="tag for enabling experimental snippet support", ) mod.list("cursorless_wrap_action", desc="Cursorless wrap action") mod.list("cursorless_wrapper_snippet", desc="Cursorless wrapper snippet") experimental_snippets_ctx = Context() experimental_snippets_ctx.matches = r""" tag: user.cursorless_experimental_snippets """ # NOTE: Please do not change these dicts. Use the CSVs for customization. # See https://www.cursorless.org/docs/user/customization/ wrapper_snippets = { "else": "ifElseStatement.alternative", "if else": "ifElseStatement.consequence", "if": "ifStatement.consequence", "try": "tryCatchStatement.body", "link": "link.text", }
from talon import Context, Module mod = Module() ctx = Context() ctx.matches = r""" os: linux tag: user.timer_manager """ # systemd is already in service_manager # mod.tag("systemd", desc="systemd management") mod.tag("timer_manager", desc="generic timer manager support") mod.tag("cron", desc="non-systemd timer timer") @mod.action_class class Actions: # System-wide timer control def timer(): """Run the default timer manager""" def timer_status(): """Show the timer status""" def timer_stop(): """Stop a timer""" def timer_start(): """Start a timer""" def timer_disable():
from talon import Module, actions, app mod = Module() mod.tag("splits", desc='Tag for enabling generic window split commands') @mod.action_class class Actions: def split_window_right(): """Move active tab to right split""" def split_window_left(): """Move active tab to left split""" def split_window_down(): """Move active tab to lower split""" def split_window_up(): """Move active tab to upper split""" def split_window_vertically(): """Splits window vertically""" def split_window_horizontally(): """Splits window horizontally""" def split_flip(): """Flips the orietation of the active split""" def split_window(): """Splits the window""" def split_clear():
from talon import Module mod = Module() mod.tag("ide", desc="Tag for enabling generic ide commands") @mod.action_class class Actions: def ide_refactor(): """Trigger refactoring menu of the ide""" def ide_perfect(): """Trigger better auto complete in the ide""" def ide_smart(): """Trigger suggestion / type completion in the ide""" def ide_finish(): """Select auto complete statement""" def ide_done(): """Select auto complete statement""" def ide_intellisense_suggest_parameters(): """Trigger parameter hints""" def ide_toggle_tools(): """Hide all windows""" def ide_editor_copylines_down(): """Editor copy line down"""
from talon import Context, Module, actions ctx = Context() mod = Module() mod.tag("code_comment_block", desc="Tag for enabling generic block comment commands") ctx.matches = """ tag: user.code_comment_block """ @mod.action_class class Actions: def code_comment_block(): """Block comment""" def code_comment_block_prefix(): """Block comment start syntax""" def code_comment_block_suffix(): """Block comment end syntax"""
from talon import Context, Module ctx = Context() mod = Module() mod.tag("code_operators_assignment", desc="Tag for enabling assignment commands") @mod.action_class class Actions: def code_operator_assignment(): """code_operator_assignment""" def code_operator_subtraction_assignment(): """code_operator_subtraction_equals""" def code_operator_addition_assignment(): """code_operator_addition_assignment""" def code_operator_increment(): """code_operator_increment""" def code_operator_multiplication_assignment(): """code_operator_multiplication_assignment""" def code_operator_division_assignment(): """code_operator_division_assignment""" def code_operator_modulo_assignment(): """code_operator_modulo_assignment"""
from talon import Context, actions, ui, Module, app mod = Module() mod.tag("todo_list", desc="Tag for enabling generic todo list commands") @mod.action_class class Actions: def mark_complete(): """Mark a todo as completed""" pass def mark_cancelled(): """Mark a todo as cancelled""" pass def show_today(): """Show today""" pass def show_inbox(): """Show inbox""" pass def show_upcoming(): """Show upcoming""" pass def show_anytime(): """Show anytime""" pass
from talon import Context, Module, actions, app, imgui, registry, settings ctx = Context() mod = Module() mod.tag("python_repl", desc="Tag for indicating a generic python repl") mod.tag("talon_repl", desc="Tag for indicating the talon repl") ctx.matches = r""" mode: command tag: user.python_repl mode: command tag: user.talon_repl """
from talon import Context, Module ctx = Context() mod = Module() # TODO: Could split into numeric, comparison, and logic? mod.tag("code_operators_math", desc="Tag for enabling mathematical operator commands") @mod.action_class class Actions: def code_operator_subtraction(): """code_operator_subtraction""" def code_operator_addition(): """code_operator_addition""" def code_operator_multiplication(): """code_operator_multiplication""" def code_operator_exponent(): """code_operator_exponent""" def code_operator_division(): """code_operator_division""" def code_operator_modulo(): """code_operator_modulo"""
default=0, desc="Enable to show the file/directories pickers automatically", ) setting_folder_limit = mod.setting( "file_manager_folder_limit", type=int, default=1000, desc="Maximum number of files/folders to iterate", ) setting_file_limit = mod.setting( "file_manager_file_limit", type=int, default=1000, desc="Maximum number of files to iterate", ) mod.tag("file_manager", desc="Tag for enabling generic file management commands") user_path = os.path.expanduser("~") folder_selections = [] file_selections = [] is_windows = False is_mac = False is_terminal = False is_linux = False cached_title = None if app.platform == "windows": is_windows = True import ctypes
# XXX - execute until line number/cursor # XXX - more memory printing # XXX - need a way to disable the architecture modes, maybe be on context # destruction from talon import Context, Module, actions, app mod = Module() mod.tag("debugger", desc="Tag for enabling generic debugger commands") # this list is updated by architecture specific python files mod.list("registers", desc="A list of architecture registers") ctx = Context() ctx.matches = r""" tag: user.debugger """ ctx.lists["user.registers"] = {} @mod.capture(rule="{self.registers}") def registers(m) -> str: "Returns a register" return m.registers class Debugger: def __init__(self, mod): self.arch_index = 0 self.architectures = ["x86", "x64"] for arch in self.architectures:
from talon import Module, actions # --- Tag definition --- mod = Module() mod.tag("chapters", desc="Reader app with chapter navigation") # --- Define actions --- @mod.action_class class Actions: def chapter_current() -> int: """Return current chapter number""" def chapter_next(): """Go to next chapter""" actions.user.chapter_jump(actions.user.chapter_current() + 1) def chapter_previous(): """Go to previous chapter""" actions.user.chapter_jump(actions.user.chapter_current() - 1) def chapter_jump(number: int): """Go to chapter number""" def chapter_final(): """Go to final chapter"""
from talon import Module mod = Module() mod.tag("ide", desc='Tag for enabling generic ide commands') @mod.action_class class Actions: def ide_refactor(): """Trigger refactoring menu of the ide""" def ide_perfect(): """Trigger better auto complete in the ide""" def ide_smart(): """Trigger suggestion / type completion in the ide""" def ide_finish(): """Select auto complete statement""" def ide_done(): """Select auto complete statement""" def ide_intellisense_suggest_parameters(): """Trigger parameter hints""" def ide_toggle_tools(): """Hide all windows""" def ide_editor_copylines_down(): """Editor copy line down"""
"vim_obsession", "vim_plug", "vim_signature", "vim_surround", "vim_taboo", "vim_tabular", "vim_wiki", "vim_unicode", "vim_ultisnips", "vim_you_are_here", "vim_youcompleteme", "vim_zoom", ] for entry in tag_list: mod.tag(entry, f"tag to load {entry} and/or related plugins ") # Based on you using a custom title string like this: # see doc/vim.md @ctx.action_class("win") class win_actions: def filename(): title = actions.win.title() result = title.split(")") # Assumes the last word after the last ) entry has the filename if len(result) > 1: result = result[-1] # print(result) if "." in result: return result
from typing import Union import math, time import typing mod = Module() narrow_expansion = mod.setting( "grid_narrow_expansion", type=int, default=0, desc= """After narrowing, grow the new region by this many pixels in every direction, to make things immediately on edges easier to hit, and when the grid is at its smallest, it allows you to still nudge it around""", ) mod.tag("mouse_grid_showing", desc="Tag indicates whether the mouse grid is showing") mod.tag("mouse_grid_enabled", desc="Deprecated: do not use. Activates legacy m grid command") ctx = Context() class MouseSnapNine: def __init__(self): self.screen = None self.rect = None self.history = [] self.img = None self.mcanvas = None self.active = False self.count = 0 self.was_control_mouse_active = False
from talon import Context, Module, actions mod = Module() mod.tag("gdb", desc="tag for running the gdb debugger") mod.tag("gef", desc="Gef gdb plugin") mod.tag("pwndbg", desc="pwndbg gdb plugin") mod.tag("libptmalloc", desc="libptmalloc gdb plugin") mod.tag("libdlmalloc", desc="libdlmalloc gdb plugin") mod.tag("libheap", desc="libheap gdb plugin") ctx = Context() ctx.matches = r""" tag: user.gdb """ @ctx.action_class("user") class user_actions: def debugger_clear_breakpoint_id(number_small: int): actions.insert(f"d br {number_small}\n") def debugger_disable_breakpoint_id(number_small: int): actions.insert(f"disable br {number_small}\n") def debugger_enable_breakpoint_id(number_small: int): actions.insert(f"enable br {number_small}\n") def pop(): """Optional way of pressing enter via pop sound""" actions.key("enter")
ctx = Context() mod = Module() mod.list("code_libraries", desc="List of libraries for active language") # global library_list = [] @mod.capture(rule="{user.code_libraries}") def code_libraries(m) -> str: """Returns a type""" return m.code_libraries mod.tag("code_libraries_gui", desc="Tag for enabling GUI support for common libraries") @mod.action_class class Actions: def code_toggle_libraries(): """GUI: List libraries for active language""" global library_list if gui_libraries.showing: library_list = [] gui_libraries.hide() else: update_library_list_and_freeze() def code_select_library(number: int, selection: str): """Inserts the selected library when the imgui is open"""