aboutsummaryrefslogtreecommitdiff
path: root/modules/org-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-27 15:08:52 -0500
committerCraig Jennings <c@cjennings.net>2026-05-27 15:08:52 -0500
commita6157f471c9d64c00f0a2e33224e373864a7ae80 (patch)
treec20d4e8503fda76356f9cfb994e3ffab0b3ae056 /modules/org-config.el
parent9b04860a22b30db746bbe4cd3376383cc19432ea (diff)
downloaddotemacs-a6157f471c9d64c00f0a2e33224e373864a7ae80.tar.gz
dotemacs-a6157f471c9d64c00f0a2e33224e373864a7ae80.zip
feat(org): open file links in the same window on shift/right-click
Plain left-click on an Org file link keeps org's default of opening in the other window. I added S-mouse-1 and mouse-3 as a second gesture that opens the file link in the current window instead, for when I want the file to replace the buffer the link sits in. The bindings live in org-mouse-map, the keymap org attaches to each link as a text property, rather than org-mode-map. That layer outranks both org-mode-map and the mouse-trap-mode emulation keymap, which otherwise swallows clicks in org buffers. Off a link the gesture does nothing, so a stray right-click is a silent no-op instead of a "No link found" error.
Diffstat (limited to 'modules/org-config.el')
-rw-r--r--modules/org-config.el32
1 files changed, 31 insertions, 1 deletions
diff --git a/modules/org-config.el b/modules/org-config.el
index c0c6bb82..90a0a5d2 100644
--- a/modules/org-config.el
+++ b/modules/org-config.el
@@ -286,6 +286,28 @@ edge, less the tag width.")
(org-backward-heading-same-level 1)
(org-narrow-to-subtree))
+ (defun cj/--org-follow-link-same-window ()
+ "Follow the Org link at point, opening file links in the current window.
+Org's default for file links is `find-file-other-window' (via
+`org-link-frame-setup'); this overrides it so the file replaces the buffer
+the link sits in. Off a link this does nothing, so a stray click is a silent
+no-op rather than a \"No link found\" error."
+ (when (eq (org-element-type (org-element-context)) 'link)
+ (let ((org-link-frame-setup (cons '(file . find-file) org-link-frame-setup)))
+ (org-open-at-point))))
+
+ (defun cj/org-follow-link-at-mouse-same-window (event)
+ "Follow the Org link clicked in EVENT, opening file links in the same window.
+Bound to S-mouse-1 and mouse-3 in `org-mouse-map' -- the keymap org attaches
+to each link as a `keymap' text property. That layer outranks both
+`org-mode-map' and the `mouse-trap-mode' emulation keymap, so the gesture
+lands even where mouse-trap otherwise disables clicks. A shift-click or
+right-click on a link opens it in place; org's other-window default
+(mouse-2 / plain click) is left alone."
+ (interactive "e")
+ (mouse-set-point event)
+ (cj/--org-follow-link-same-window))
+
:hook
(org-mode . turn-on-visual-line-mode)
(org-mode . (lambda () (setq-local tab-width 8)))
@@ -300,7 +322,15 @@ edge, less the tag width.")
(cj/org-general-settings)
(cj/org-appearance-settings)
- (cj/org-todo-settings))
+ (cj/org-todo-settings)
+
+ ;; Open a file link in the current window on shift-left-click or right-click.
+ ;; These bind into `org-mouse-map' (the per-link `keymap' text property)
+ ;; rather than `org-mode-map' so they outrank the `mouse-trap-mode' emulation
+ ;; keymap, which otherwise swallows clicks in org buffers. mouse-2 / plain
+ ;; click keep org's other-window default.
+ (keymap-set org-mouse-map "S-<mouse-1>" #'cj/org-follow-link-at-mouse-same-window)
+ (keymap-set org-mouse-map "<mouse-3>" #'cj/org-follow-link-at-mouse-same-window))
;; ------------------------------- Org Superstar -------------------------------