|
1 | 1 | import logging |
| 2 | +import re |
2 | 3 | from typing import Optional |
3 | 4 |
|
4 | | -from talon import Context, Module, actions, settings |
| 5 | +from talon import Context, Module, actions, settings, ui |
5 | 6 |
|
6 | 7 | mod = Module() |
7 | 8 | mod.setting( |
@@ -362,8 +363,19 @@ def language(): |
362 | 363 |
|
363 | 364 | @ctx.action_class("win") |
364 | 365 | class WinActions: |
365 | | - # This assumes the title is/contains the filename. |
366 | | - # To do this, put this in init.el: |
367 | | - # (setq-default frame-title-format '((:eval (buffer-name (window-buffer (minibuffer-selected-window)))))) |
| 366 | + # This assumes the title either is the buffer name or contains the buffer |
| 367 | + # name before a space-surrounded hyphen. This is the default for the latest |
| 368 | + # GNU Emacs. If you are not on macOS and your flavor of Emacs defaults to |
| 369 | + # something incompatible, you may need to put one of the following two |
| 370 | + # declarations into your init.el ("%b" being replaced by the buffer name): |
| 371 | + # (setq frame-title-format "%b") |
| 372 | + # (setq frame-title-format '(multiple-frames "%b" ("" "%b - Emacs at " system-name))) |
368 | 373 | def filename(): |
369 | | - return actions.win.title() |
| 374 | + # On macOS, get the filename directly |
| 375 | + if doc := getattr(ui.active_window(), "doc", None): |
| 376 | + return doc |
| 377 | + |
| 378 | + # Otherwise, get it from the window title |
| 379 | + title = actions.win.title() |
| 380 | + buffer_name = title.split(" - ")[0] |
| 381 | + return re.sub(r"<[^>]+>$", "", buffer_name) |
0 commit comments