summaryrefslogtreecommitdiffhomepage
path: root/init.org
diff options
context:
space:
mode:
Diffstat (limited to 'init.org')
-rw-r--r--init.org64
1 files changed, 51 insertions, 13 deletions
diff --git a/init.org b/init.org
index a6fae4a..f962db5 100644
--- a/init.org
+++ b/init.org
@@ -1868,6 +1868,42 @@
("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
(use-package saveplace-pdf-view
@@ -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)