From 8b8f6252bf71648f39b8af8c98ea2b1c399ef9d5 Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 29 Aug 2022 02:39:22 +0100 Subject: new lib: jao-pdf --- init.el | 56 ++++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index 933a79c..4360de7 100644 --- a/init.el +++ b/init.el @@ -468,6 +468,9 @@ (let ((tl (jao-shell-string jao-sway-get-active-title))) (and (string-match "\"\\(.+\\)\"" tl) (match-string 1 tl)))) +(defun jao-sway-zathura-org () + (jao-pdf-goto-zathura-org (jao-sway-get-active-title) t)) + (defun jao-sway-send (txt) (jao-shell-string "wtype" txt)) (defun jao-zathura--open-cmd (file page &optional suffix) @@ -1773,36 +1776,16 @@ ("k" . pdf-view-previous-line-or-previous-page) ("K" . pdf-view-scroll-down-or-previous-page)))) -;;;; zathura -(defun jao-zathura-file-info (title) - (when (string-match "\\(.+\\) \\[\\(.+\\) (\\([0-9]+\\)/\\([0-9]+\\))\\]" - title) - (list (expand-file-name (match-string 1 title)) - (string-to-number (match-string 3 title)) - (string-to-number (match-string 4 title)) - (match-string 2 title)))) - -(defun jao-zathura-goto-org (&optional title no-ask) - (when-let* ((title (or title - (and jao-sway-enabled - (jao-sway-get-active-title)) - (jao-shell-string "xdotool" - "getactivewindow" - "getwindowname"))) - (info (jao-zathura-file-info title)) - (file (jao-org-pdf-to-org-file (car info))) - (page (cadr info)) - (pageno (or (car (last info)) page))) - (ignore-errors (jao-afio--goto-docs)) - (let* ((exists (file-exists-p file)) - (fn (file-name-nondirectory file)) - (lnk (format "[[doc:%s::%d][Page %s]]" fn page pageno))) - (find-file file) - (unless exists (jao-org-insert-doc-skeleton)) - (if (or (not exists) no-ask (y-or-n-p "Insert link?")) - (insert lnk "\n") - (kill-new lnk) - (message "Link to %s (%s) killed" file page))))) +;;;; open pdfs +(use-package jao-pdf :demand t) + +(use-package saveplace-pdf-view + :ensure t + :demand t + :after doc-view) + +(setq jao-open-doc-fun 'jao-find-or-open) +(setq jao-org-open-pdf-fun 'jao-find-or-open) (defun jao-zathura-open (file page) (let ((id (jao-shell-string (format "xdotool search --name %s" @@ -1816,14 +1799,11 @@ (cmd (format "xdotool windowactivate %s%s" id page))) (jao-shell-string cmd))))) -;;;; open pdfs -(use-package saveplace-pdf-view - :ensure t - :demand t - :after doc-view) - -(setq jao-open-doc-fun 'jao-find-or-open) -(setq jao-org-open-pdf-fun 'jao-find-or-open) +(defun jao-x11-zathura-goto-org (&optional title no-ask) + (let ((title (or title (jao-shell-string "xdotool" + "getactivewindow" + "getwindowname")))) + (jao-pdf-goto-zathura-org title no-ask))) (defun jao-find-or-open (file &optional page height) (cond ((and jao-browse-doc-use-emacs-p window-system) -- cgit v1.2.3