;;; Customization and Extension for Emacs e-book viewers ;;; doc-view ;;; reading progress support for doc-view-mode (setq-default doc-view-resolution 140) (defun wl-doc-view-bookmark-name () "Append postfix %->#->auto" (concat (file-name-nondirectory (buffer-file-name)) "%->#->auto")) (defun wl-bookmark-get-resolution (bookmark) "Get doc view resolution." (or (bookmark-prop-get bookmark 'resolution) (default-value 'doc-view-resolution))) (defun wl-doc-view-bookmark-jump (bookmark) (prog1 (doc-view-bookmark-jump bookmark) (let ((resolution (wl-bookmark-get-resolution bookmark))) (assert (> resolution 0)) (when (/= doc-view-resolution resolution) (set (make-local-variable 'doc-view-resolution) resolution) (doc-view-reconvert-doc))))) (defun wl-doc-view-auto-load-bookmark () "Load bookmark automatically if there is one when opening PDF file." (setq bookmark-make-record-function 'wl-doc-view-bookmark-make-record) (let ((bookmark (wl-doc-view-bookmark-name))) (when (bookmark-get-bookmark bookmark 'noerror) (let ((filename (expand-file-name (bookmark-get-filename bookmark)))) (when (string-equal filename (buffer-file-name)) (wl-doc-view-bookmark-jump bookmark)))))) (defun wl-doc-view-bookmark-make-record () (nconc (bookmark-make-record-default) `((page . ,(doc-view-current-page)) (resolution . ,doc-view-resolution) (handler . wl-doc-view-bookmark-jump)))) (defadvice doc-view-goto-page (after wl-doc-view-goto-page-bookmark (page)) (bookmark-set (wl-doc-view-bookmark-name))) (defadvice doc-view-enlarge (after wl-doc-view-enlarge-bookmark (factor)) (bookmark-set (wl-doc-view-bookmark-name))) (ad-activate 'doc-view-goto-page) (ad-activate 'doc-view-enlarge) (defun wl-doc-view-keep-resolution-permanent-local () (put 'doc-view-resolution 'permanent-local t)) (add-hook 'doc-view-mode-hook 'wl-doc-view-auto-load-bookmark) (add-hook 'doc-view-mode-hook 'wl-doc-view-keep-resolution-permanent-local) (provide 'wl-ebook-viewer)