From 0db03a3d92fda3c0cf368826d0fe5a224ad688d0 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 23 Sep 2022 00:59:24 +0100 Subject: cleanups for pdf navigation --- lib/doc/jao-org-links.el | 34 +++++++++++++++------------------- lib/doc/jao-org-notes.el | 13 +++++++++++++ lib/doc/jao-pdf.el | 16 ---------------- 3 files changed, 28 insertions(+), 35 deletions(-) (limited to 'lib/doc') diff --git a/lib/doc/jao-org-links.el b/lib/doc/jao-org-links.el index acfe176..8b5c42e 100644 --- a/lib/doc/jao-org-links.el +++ b/lib/doc/jao-org-links.el @@ -77,25 +77,21 @@ (insert (format "[[doc:%s][%s]]" (jao-pdf-title-to-file-name title) title))) ;;;###autoload -(defun jao-org-org-to-pdf-file () - (expand-file-name (concat "doc/" (file-name-base buffer-file-name) ".pdf") - (file-name-directory jao-org-notes-dir))) - -;;;###autoload -(defun jao-org-pdf-to-org-file (&optional file-name no-ask) - (let* ((file-name (or file-name buffer-file-name)) - (bn (file-name-base file-name)) - (rx (format "%s\\.org$" (regexp-quote bn)))) - (save-some-buffers nil - (lambda () - (string-prefix-p jao-org-notes-dir buffer-file-name))) - (or (car (directory-files-recursively jao-org-notes-dir rx)) - (let ((d (if no-ask - "" - (concat (completing-read "Notes subdir: " - (jao-org-notes-cats) nil t) - "/")))) - (expand-file-name (concat dir bn ".org") jao-org-notes-dir))))) +(defun jao-org-open-from-zathura (title &optional no-ask) + (when-let* ((info (jao-pdf-zathura-file-info title)) + (pdf-file (car info)) + (page (cadr info)) + (file (jao-org-notes-find-for-pdf pdf-file))) + (ignore-errors (jao-afio-goto-docs)) + (let ((exists (file-exists-p file))) + (find-file file) + (unless exists (jao-org-insert-doc-skeleton)) + (let ((lnk (jao-pdf--zathura-link info))) + (jao-doc-session-mark) + (if (or (not exists) (and (not no-ask) (y-or-n-p "Insert link?"))) + (insert lnk "\n") + (kill-new lnk) + (message "Link to %s (%s) killed" file page)))))) ;;;###autoload (defun jao-org-insert-doc-skeleton (&optional title) diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el index 3f3c5ea..b7700ec 100644 --- a/lib/doc/jao-org-notes.el +++ b/lib/doc/jao-org-notes.el @@ -140,6 +140,19 @@ (save-buffer) (buffer-file-name)) +;;;###autoload +(defun jao-org-notes-find-for-pdf (&optional file-name) + "Given a PDF file name, find its org notes counterpart." + (let* ((file-name (or file-name buffer-file-name)) + (bn (file-name-base file-name)) + (rx (format "%s\\.org$" (regexp-quote bn))) + (pred (lambda () (string-prefix-p jao-org-notes-dir buffer-file-name)))) + (save-some-buffers nil pred) + (or (car (directory-files-recursively jao-org-notes-dir rx)) + (let* ((d (completing-read "Notes subdir: " (jao-org-notes-cats) nil t)) + (d (file-name-as-directory d))) + (expand-file-name (concat d bn ".org") jao-org-notes-dir))))) + ;;;###autoload (defun jao-org-notes-grep () "Perform a grep search on all org notes body, via consult-ripgrep." diff --git a/lib/doc/jao-pdf.el b/lib/doc/jao-pdf.el index ad34b48..213d806 100644 --- a/lib/doc/jao-pdf.el +++ b/lib/doc/jao-pdf.el @@ -112,21 +112,5 @@ The result is cached as a local buffer variable." (defun jao-pdf-zathura-org-link (title) (jao-pdf--zathura-link (jao-pdf-zathura-file-info title))) -(defun jao-pdf-goto-zathura-org (title &optional no-ask) - (when-let* ((info (jao-pdf-zathura-file-info title)) - (pdf-file (car info)) - (page (cadr info)) - (file (jao-org-pdf-to-org-file pdf-file))) - (ignore-errors (jao-afio-goto-docs)) - (let ((exists (file-exists-p file))) - (find-file file) - (unless exists (jao-org-insert-doc-skeleton)) - (let ((lnk (jao-pdf--zathura-link info))) - (jao-doc-session-mark) - (if (or (not exists) (and (not no-ask) (y-or-n-p "Insert link?"))) - (insert lnk "\n") - (kill-new lnk) - (message "Link to %s (%s) killed" file page)))))) - (provide 'jao-pdf) ;;; jao-pdf.el ends here -- cgit v1.2.3