From f31dd593db474575fe0edc298916586039b21aab Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 20 May 2022 03:23:46 +0100 Subject: working better in term mode: pdfs with zathura --- init.org | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 13 deletions(-) (limited to 'init.org') diff --git a/init.org b/init.org index a6fae4a..f962db5 100644 --- a/init.org +++ b/init.org @@ -1867,6 +1867,42 @@ ("k" . pdf-view-previous-line-or-previous-page) ("K" . pdf-view-scroll-down-or-previous-page)))) + #+end_src +*** zathura + #+begin_src emacs-lisp + (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 (title) + (when-let* ((info (jao-zathura-file-info title)) + (file (jao-org-pdf-to-org-file (car info))) + (page (cadr info)) + (pageno (or (car (last info)) page))) + (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) (y-or-n-p "Insert link?")) + (insert lnk "\n") + (kill-new lnk) + (message "Link to %s (%s) killed" file page))))) + + (defun jao-zathura-open (file page) + (let ((id (jao-shell-string (format "xdotool search --name %s" + (file-name-nondirectory file))))) + (if (string-blank-p id) + (jao-shell-exec (format "zathura %s -P %s" file (or page 1))) + (let* ((page (if page (format " && xdotool type %dg" page) "")) + (cmd (format "xdotool windowactivate %s%s" id page))) + (jao-shell-string cmd))))) + #+end_src *** open pdfs #+begin_src emacs-lisp @@ -1877,25 +1913,27 @@ (setq jao-open-doc-fun 'jao-find-or-open) - (defun jao-find-or-open (file) - (let* ((buffs (buffer-list)) - (b (catch 'done - (while buffs - (when (string-equal (buffer-file-name (car buffs)) file) - (throw 'done (car buffs))) - (setq buffs (cdr buffs)))))) - (jao-afio--goto-docs) - (if b (pop-to-buffer b) (find-file file)))) - - (defun jao-open-doc (&optional file) + (defun jao-find-or-open (file &optional page height) + (if (and jao-browse-doc-use-emacs-p window-system) + (let* ((buffs (buffer-list)) + (b (catch 'done + (while buffs + (when (string-equal (buffer-file-name (car buffs)) file) + (throw 'done (car buffs))) + (setq buffs (cdr buffs)))))) + (jao-afio--goto-docs) + (if b (pop-to-buffer b) (find-file file))) + (jao-zathura-open file page))) + + (defun jao-open-doc (&optional file page height) (interactive) (when-let (file (or file (read-file-name "Document: " (concat jao-org-dir "/doc/")))) - (funcall jao-open-doc-fun file))) + (funcall jao-open-doc-fun file page height))) (defun jao-afio-open-pdf (file page &optional height) - (jao-open-doc file) + (jao-open-doc file page height) (when page (jao-doc-view-goto-page page height))) (setq jao-org-open-pdf-fun #'jao-afio-open-pdf) -- cgit v1.2.3