fix(org-noter): auto-insert NOTER_DOCUMENT property, never prompt for document path
This commit is contained in:
54
config.el
54
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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user