# a list of homophones where each line is a comma separated list # e.g. where,wear,ware # a suitable one can be found here: # https://github.com/pimentel/homophones cwd = os.path.dirname(os.path.realpath(__file__)) homophones_file = os.path.join(cwd, "homophones.csv") # if quick_replace, then when a word is selected and only one homophone exists, # replace it without bringing up the options quick_replace = True show_help = False ######################################################################## ctx = Context() mod = Module() mod.mode("homophones") mod.list("homophones_canonicals", desc="list of words ") main_screen = ui.main_screen() def update_homophones(name, flags): if name != homophones_file: return phones = {} canonical_list = [] with open(homophones_file, "r") as f: for line in f: words = line.rstrip().split(",") canonical_list.append(max(words, key=len))
import typing def hx(v: int) -> str: return '{0:x}'.format(v) mod = Module() mod.tag("full_mouse_grid_showing", desc="Tag indicates whether the full mouse grid is showing") mod.tag("full_mouse_grid_enabled", desc="Tag enables the full mouse grid commands.") mod.list("mg_point_of_compass", desc="point of compass for full mouse grid") mod.mode("full_mouse_grid", desc="indicate the full mouse grid is active") setting_letters_background_color = mod.setting( "full_mouse_grid_letters_background_color", type=str, default="000000", desc="set the background color of the small letters in the full mouse grid", ) setting_row_highlighter = mod.setting( "full_mouse_grid_row_highlighter", type=str, default="ff0000", desc="set the color of the row to highlight", )
@ctx.action_class("code") class code_actions: def language(): result = "" file_extension = actions.win.file_ext() if file_extension and file_extension in extension_lang_map: result = extension_lang_map[file_extension] print("code.language: " + result) return result # create a mode for each defined language for __, lang in extension_lang_map.items(): mod.mode(lang) # Create a mode for the automated language detection. This is active when no lang is forced. mod.mode("auto_lang") # Auto lang is enabled by default app.register("ready", lambda: actions.user.code_clear_language_mode()) @mod.action_class class Actions: def code_set_language_mode(language: str): """Sets the active language mode, and disables extension matching""" actions.user.code_clear_language_mode() actions.mode.disable("user.auto_lang") actions.mode.enable("user.{}".format(language))
from talon import Module, actions, ui, app import time mod = Module() mod.mode("draft_editor", "Indicates whether the draft editor has been activated") default_names = [ "Visual Studio Code", "Code", "VSCodium", "Codium", "code-oss" ] setting_editor_names = mod.setting( "draft_editor", type=str, default=None, desc="List of application names to use for draft editor", ) editor_names = {} @mod.scope def scope(): for app in ui.apps(background=False): if app.name in editor_names: return {"draft_editor_running": True} return {"draft_editor_running": False} def on_ready(): global editor_names
import json import os import sys from typing import Set from talon import Context, Module, actions, fs, imgui, settings, ui mod = Module() mod.mode("personal_info") mod.setting( "personal_info_auto_select", type=int, default=1, desc="Auto select specified entry in json list, or none if 0", ) mod.list("personal_info", desc="List of personal info populated by json file") ctx = Context() @mod.capture(rule="{user.personal_info}") def personal_info(m) -> list: return m.personal_info # ctx.matches = r""" # mode: command # """ main_screen = ui.main_screen() personal_info_list = []
mod.list("vim_text_object_range", desc="VIM text object ranges") mod.list("vim_text_object_select", desc="VIM text object selections") mod.list("vim_jump_range", desc="VIM jump ranges") mod.list("vim_jumps", desc="VIM jump verbs") mod.list("vim_jump_targets", desc="VIM jump targets") mod.list("vim_normal_counted_motion_command", desc="Counted normal VIM commands") mod.list("vim_counted_motion_command_with_ordinals", desc="Counted normal VIM commands") mod.list("vim_select_motion", desc="VIM visual mode selection motions") # Plugin-specific lists mod.list("vim_surround_targets", desc="VIM surround plugin targets") # Plugin modes mod.mode("vim_fugitive", desc="A fugitive mode that exposes git mappings") @mod.capture def vim_arrow(m) -> str: "An arrow direction to be converted to vim direction" return m.vim_arrow @mod.capture def vim_surround_targets(m) -> str: "Returns a text object used by the surround plugin" @mod.capture def vim_select_motion(m) -> str:
from talon import Context, Module, actions, app mod = Module() mod.mode("arrow_selection") arrow_direction = '' def press_arrow_key(n: int): direction_callable = None if arrow_direction.startswith('u'): direction_callable = actions.edit.up elif arrow_direction.startswith('d'): direction_callable = actions.edit.down elif arrow_direction.startswith('l'): direction_callable = actions.edit.left elif arrow_direction.startswith('r'): direction_callable = actions.edit.right else: app.notify('selection.py', 'Unknown direction: ' + repr(arrow_direction)) # This is indexed by 1, so subtract here for i in range(max(0, n-1)): direction_callable() @mod.action_class class Actions: def enable_arrow_selection(direction: str='right'): """Enable arrow selection mode""" global arrow_direction arrow_direction = direction.lower()
import talon from talon import Context, Module, actions, ui, app, speech_system, scope, settings import unicodedata mod = Module() mod.mode('german') ctx = Context() ctx.matches = 'mode: user.german' ctx.settings = { 'speech.engine': 'vosk', # 'speech.language': 'de_DE', 'speech.timeout': 0.3 } mod.setting("german_unicode", type=int, default=1, desc="Enable proper unicode punctuation") mod.list("buchstabe", desc="The spoken phonetic alphabet") ctx.lists["self.buchstabe"] = { "alpha": "a", "bravo": "b", "charlie": "c", "delta": "d", "echo": "e", "foxtrott": "f", "golf": "g", "hotel": "h", "india": "i",
from talon import Context, Module, actions, app, imgui, ui mod = Module() ctx = Context() ctx.matches = r""" os: linux tag: terminal and tag: user.package_manager """ mod.mode("packager_picker_open") mod.tag("package_manager", desc="linux package manager") packager_list = [ { "tag": "packager_yay", "desc": "Arch Linux YAY packager" }, { "tag": "packager_pacman", "desc": "Arch Linux YAY packager" }, { "tag": "packager_pamac", "desc": "Manjaro Linux packager" }, { "tag": "packager_apt", "desc": "Debian/Ubuntu Linux packager" }, {
event that you feel that it wasn't actually an error. because the number of recordings that can happen change fairly quickly it also provides a gui selector that allows you to choose from a list of the most recent recordings and have one of those specifically save to the preconfigured directory.""" import os import pathlib import shutil import subprocess from typing import List from talon import Context, Module, actions, app, clip, imgui, settings, ui from talon_init import TALON_HOME ctx = Context() mod = Module() mod.mode("replay_picker_open") mod.tag("record_replay", desc="a tag that will enable certain replay recording commands") mod.setting( "saved_replay_recordings_directory", type=str, default=None, desc="Location that you can use to store saved recordings", ) mod.setting( "replay_recordings_list_count", type=int, default=30, desc="The number of recordings to show in the replay recordings gui",
from talon import Module, actions, imgui, Module, scope, ui mod = Module() mod.mode("help_scope", "Mode for showing the scope help gui") setting_max_length = mod.setting( "help_scope_max_length", type=int, default=50, ) @imgui.open(x=ui.main_screen().x) def gui(gui: imgui.GUI): gui.text("Scope") gui.line() gui.spacer() gui.text("Modes") gui.line() for mode in sorted(scope.get("mode")): gui.text(mode) gui.spacer() gui.text("Tags") gui.line() for tag in sorted(scope.get("tag")): gui.text(tag) gui.spacer() gui.text("Misc") gui.line() ignore = {"main", "mode", "tag"} keys = {*scope.data.keys(), *scope.data["main"].keys()}
from talon import Module mod = Module() mod.mode("slow")
from talon import Module, Context # prior art: knausj_talon/code/sleep_toggle.py mod = Module() mod.setting('noise_enabled', type=bool, desc='Enable callbacks to noise events') mod.mode('coma', desc='deep sleep where even noises are not handled anymore') @mod.action_class class Actions: def ignore(m: [str]): """ignores everything""" print(f"ignored phrase: {m}")
import math import webbrowser from talon import Module, actions, cron, skia, ui from talon.canvas import Canvas from .get_list import get_list, get_lists from .sections.actions import get_actions from .sections.compound_targets import get_compound_targets from .sections.scopes import get_scopes mod = Module() mod.mode("cursorless_cheat_sheet", "Mode for showing cursorless cheat sheet gui") cheat_sheet = None instructions_url = "https://www.cursorless.org/docs/" instructions_text = "Full docs" line_height = 34 outer_padding = 27 text_size = 16 url_text_size = 30 close_size = 24 header_size = 22 padding = 4 command_font = "monospace" text_font = "" background_color = "fafafa" border_color = "000000"
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)
from talon import Module, actions, noise, ctrl from talon_plugins import eye_mouse, eye_zoom_mouse mod = Module() mod.mode("hiss_to_scroll", "mode for commands that are available only when hiss to scroll is active") all_modes = [ 'scroll' ] hiss_mode = '' @mod.action_class class Actions: def noise_toggle_hiss_mode(mode: str) -> None: """toggle the hiss mouse mode""" global hiss_mode if hiss_mode == mode: hiss_mode = '' elif mode in all_modes: hiss_mode = mode else: print(mode + ' is not a valid hiss mode.') raise if hiss_mode == '': actions.mode.disable('user.hiss_to_scroll') elif hiss_mode == 'scroll': actions.mode.enable('user.hiss_to_scroll') # def noise_hiss_scroll_reverse(): # """reverse the direction of the hissing scroll"""
if file_extension != "": result = file_extension # it should always be the last split... elif file_name != "" and "." in file_name: result = file_name.split(".")[-1] if result in extension_lang_map: result = extension_lang_map[result] # print("code.language: " + result) return result # create a mode for each defined language for __, lang in extension_lang_map.items(): mod.mode(lang) @mod.action_class class Actions: def code_set_language_mode(language: str): """Sets the active language mode, and disables extension matching""" global forced_language actions.user.code_clear_language_mode() actions.mode.enable("user.{}".format(language)) # app.notify("Enabled {} mode".format(language)) forced_language = True def code_clear_language_mode(): """Clears the active language mode, and re-enables code.language: extension matching""" global forced_language
from talon import Context, Module mod = Module() mod.mode("gdb", "a way to force gdb commands to be loaded") mod.tag("gdb", "tag to help load gdb plugins")
from collections import defaultdict import itertools import math from typing import Dict, List, Iterable, Set, Tuple, Union from talon import Module, Context, actions, imgui, Module, registry, ui from talon.grammar import Phrase mod = Module() mod.list("help_contexts", desc="list of available contexts") mod.mode("help", "mode for commands that are available only when help is visible") setting_help_max_contexts_per_page = mod.setting( "help_max_contexts_per_page", type=int, default=20, desc="Max contexts to display per page in help", ) setting_help_max_command_lines_per_page = mod.setting( "help_max_command_lines_per_page", type=int, default=50, desc="Max lines of command to display per page in help", ) ctx = Context() # context name -> commands context_command_map = {} # rule word -> Set[(context name, rule)] rule_word_map: Dict[str, Set[Tuple[str, str]]] = defaultdict(set)
from talon import Module mod = Module() mod.mode('solo', desc='non-global command mode')