From 95b5716bfa174011a1af95a49429b1f47277dacd Mon Sep 17 00:00:00 2001 From: Daneel Date: Mon, 23 Feb 2026 20:55:16 +0100 Subject: [PATCH] fix(org-noter): smart launcher -- auto-select PDF window on SPC o n --- config.el | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/config.el b/config.el index 64ef601..6a9fe51 100644 --- a/config.el +++ b/config.el @@ -1234,18 +1234,38 @@ Otherwise: runs interactive ement-connect, then opens rooms after sync." :after (:any org pdf-view) :config (setq org-noter-notes-window-location 'horizontal-split - ;; Where to search for and create notes files (same dir as org notes) + ;; Directories to search for and create notes files org-noter-notes-search-path (list (expand-file-name "notes/" org-directory)) + ;; Default note file name when creating a new session + org-noter-default-notes-file-names '("notes.org") ;; Remember last position in PDF across sessions org-noter-auto-save-last-location t - ;; Insert note at precise location (not just page level) + ;; Insert note at precise location, not just page level org-noter-insert-note-no-questions nil - ;; Always use separate notes file per PDF (cleaner than one big file) org-noter-use-indirect-buffer nil)) +;; Smart launcher: always start org-noter from the PDF window, +;; regardless of which window is currently selected. +;; Fixes: calling SPC o n from an org buffer while PDF is visible in split. +(defun my/org-noter-smart () + "Start org-noter, auto-selecting the PDF window in the current frame. +If current buffer is pdf-view-mode: start normally. +If another visible window shows a PDF: switch to it first, then start. +Otherwise: run standard org-noter (interactive, prompts for document)." + (interactive) + (let ((pdf-win (cl-find-if + (lambda (w) + (with-current-buffer (window-buffer w) + (derived-mode-p 'pdf-view-mode))) + (window-list (selected-frame))))) + (if pdf-win + (with-selected-window pdf-win + (org-noter)) + (org-noter)))) + (map! :leader (:prefix ("o" . "open") - :desc "org-noter" "n" #'org-noter + :desc "org-noter (smart)" "n" #'my/org-noter-smart :desc "org-noter insert note" "N" #'org-noter-insert-note))