Last active
February 27, 2026 18:42
-
-
Save lgmoneda/96ab3b6a437828427f979407cc4a388e to your computer and use it in GitHub Desktop.
Org-roam links in agent-shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Visually hide [[id:UUID][ and ]] leaving only the description | |
| (defun my/agent-shell-setup-org-roam-links () | |
| (require 'org) ;; for org-link face | |
| (font-lock-add-keywords | |
| nil | |
| '(("\\(\\[\\[id:[A-Za-z0-9-]+\\]\\[\\)\\([^]]+\\)\\(\\]\\]\\)" | |
| ;; hide prefix and suffix | |
| (1 (prog1 nil | |
| (compose-region (match-beginning 1) (match-end 1) ""))) | |
| (3 (prog1 nil | |
| (compose-region (match-beginning 3) (match-end 3) ""))) | |
| ;; style the visible description like org-mode | |
| (2 'org-link t))) | |
| 'append) | |
| ;; make sure it applies right away | |
| (font-lock-flush)) | |
| (add-hook 'agent-shell-mode-hook #'my/agent-shell-setup-org-roam-links) | |
| (defun my/org-roam-link-at-point () | |
| "Return the org-roam ID if point is inside an [[id:UUID][Description]] link, else nil." | |
| (let ((pos (point))) | |
| (save-excursion | |
| (beginning-of-line) | |
| (let ((found nil)) | |
| (while (and (not found) | |
| (re-search-forward | |
| "\\[\\[id:\\([A-Za-z0-9-]+\\)\\]\\[[^]]+\\]\\]" | |
| (line-end-position) t)) | |
| (when (and (>= pos (match-beginning 0)) | |
| (<= pos (match-end 0))) | |
| (setq found (match-string 1)))) | |
| found)))) | |
| (defun my/agent-shell-C-c-C-o () | |
| "Follow org-roam link at point, or fall back to agent-shell-other-buffer." | |
| (interactive) | |
| (if-let ((id (my/org-roam-link-at-point))) | |
| (if (org-id-find id 'marker) | |
| (org-id-open id 'marker) | |
| (message "No org entry found with ID: %s" id)) | |
| (agent-shell-other-buffer))) | |
| (with-eval-after-load 'agent-shell | |
| (define-key agent-shell-mode-map (kbd "C-c C-o") #'my/agent-shell-C-c-C-o)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment