From 527693773c6ef0536a5875b9efccee64a67c8459 Mon Sep 17 00:00:00 2001 From: Daneel Date: Mon, 23 Feb 2026 21:08:54 +0100 Subject: [PATCH] fix(org-noter): auto-insert NOTER_DOCUMENT property, never prompt for document path --- config.el | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/config.el b/config.el index bed5d47..b9f7520 100644 --- a/config.el +++ b/config.el @@ -1249,28 +1249,48 @@ Otherwise: runs interactive ement-connect, then opens rooms after sync." org-noter-insert-note-no-questions nil 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)." +;; Smart org-noter launcher: works seamlessly from a PDF buffer. +;; Ensures the notes file exists with NOTER_DOCUMENT property before starting, +;; so org-noter never prompts "No document property found". +(defun my/org-noter-start () + "Start org-noter for the PDF visible in the current frame. +Auto-creates or updates the notes file with the NOTER_DOCUMENT property." (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 + (let* ((pdf-win (if (derived-mode-p 'pdf-view-mode) + (selected-window) + (cl-find-if + (lambda (w) + (with-current-buffer (window-buffer w) + (derived-mode-p 'pdf-view-mode))) + (window-list (selected-frame))))) + (pdf-path (when pdf-win + (with-current-buffer (window-buffer pdf-win) + (buffer-file-name))))) + (if (not pdf-path) + ;; No PDF open — fall back to standard org-noter + (org-noter) + ;; Build notes file path from PDF basename + notes search path + (let* ((base (file-name-base pdf-path)) + (notes-dir (car org-noter-notes-search-path)) + (notes-file (expand-file-name (concat base ".org") notes-dir))) + (make-directory notes-dir t) + ;; Ensure notes file has NOTER_DOCUMENT property + (with-current-buffer (find-file-noselect notes-file) + (unless (save-excursion + (goto-char (point-min)) + (re-search-forward ":NOTER_DOCUMENT:" nil t)) + ;; No NOTER_DOCUMENT found — insert a top-level heading with property + (goto-char (point-min)) + (insert (format "* Notes: %s\n:PROPERTIES:\n:NOTER_DOCUMENT: %s\n:END:\n\n" + base pdf-path)) + (save-buffer))) + ;; Start org-noter from the PDF window (with-selected-window pdf-win - (org-noter)) - (org-noter)))) + (org-noter)))))) (map! :leader (:prefix ("o" . "open") - :desc "org-noter (smart)" "n" #'my/org-noter-smart + :desc "org-noter" "n" #'my/org-noter-start :desc "org-noter insert note" "N" #'org-noter-insert-note))