diff --git a/apps/emacs/emacs.py b/apps/emacs/emacs.py index 8c47b13b35..61eef2e6f3 100644 --- a/apps/emacs/emacs.py +++ b/apps/emacs/emacs.py @@ -1,7 +1,7 @@ import logging from typing import Optional -from talon import Context, Module, actions, settings +from talon import Context, Module, actions, clip, settings mod = Module() mod.setting( @@ -320,6 +320,17 @@ def find_next(): def find_previous(): actions.key("ctrl-r") + def selected_text() -> str: + timeout = settings.get("user.selected_text_timeout") + with clip.capture(timeout) as s: + actions.edit.copy() + # this restores the selection after the copy + actions.user.emacs("exchange-point-and-mark") + try: + return s.text() + except clip.NoChange: + return "" + @ctx.action_class("app") class AppActions: