def emacs_helm_goto_line(line_number: int): """Move to a specific line in the helm buffer. Pass `0` in order to avoid moving. """ if line_number: rpc_call("voicemacs-helm-goto-line", [line_number])
def find(text: str = None): if text: text = text.lower() # `swoop` can be slow to open on large documents because it initially # matches every line. It's much faster if text is provided up-front. rpc_call("voicemacs-helm-swoop", [text]) else: emacs_command("helm-swoop")
def open_in_emacs(path: Optional[str] = None) -> None: """Open `path` in Emacs. Required Emacs to initialize as a server. Note this requires Emacs to already be open. """ # TODO: Start Emacs if it's not already running. rpc_call("x-focus-frame", [None]) if path: # FIXME: Porthole can't handle unencodable return values rpc_call("voicemacs-find-file", [path])
def emacs_wrap_object(object_type: str, pair_opening: str) -> None: """Wrap the current object of `object_type`. `pair_opening` is the start of the pair to wrap it with. """ rpc_call( "it-wrap", [ # Convert to Elisp symbol # # FIXME: Probably fix `it` to allow reference by symbol or string f"'{object_type}", pair_opening, ], )
def surrounding_text() -> Optional[SurroundingText]: # TODO: If the voicemacs server is inactive, return nothing. raw_info = rpc_call( "voicemacs-surrounding-text", [":chars-before", 30000, ":chars-after", 30000], # Use a very long timeout timeout=10, ) return SurroundingText(text_before=raw_info["text-before"], text_after=raw_info["text-after"])
def emacs_partial_buffer_switch(partial_name: str) -> None: """Switch to buffer matching `partial_name`. If there is anything other than a single match, opens the buffer switching dialogue. """ with _buffers_lock: candidates = _partial_buffers_map.get(partial_name, []) if len(candidates) == 1: try: rpc_call("voicemacs-switch-to-existing-buffer", [candidates[0]]) return except Exception as e: # If this fails just fall back to normal method. print(f"Error switching to buffer: {e}") pass else: print(f"More than one candidate, falling back: {candidates}") # Fallback method actions.self.emacs_switch_buffer() actions.insert(partial_name.lower().replace(" dot ", " "))
def emacs_insert_yasnippet(snippet_name: str) -> None: """Insert a yasnippet by name.""" rpc_call("voicemacs-insert-snippet", [snippet_name])
def emacs_dired_highlight(number: int) -> None: """Move cursor to a Dired candidate by number.""" # HACK: Technically it does change the state, but it doesn't mater if # we do it multiple times. rpc_call("voicemacs-dired-move-to-item", [number])
def org_set_todo(state: str) -> None: """Set the current item to a specific TODO state.""" rpc_call("org-todo", [str(state)])
def get_that_dwim() -> str: return rpc_call("it-text-of-thing-at-dwim")