[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DJVU files and ImageMagick

From: Stephen Berman
Subject: Re: DJVU files and ImageMagick
Date: Mon, 04 Feb 2019 18:34:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On Sun, 03 Feb 2019 20:30:48 -0600 Roland Winkler <address@hidden> wrote:

> On Sat, Feb 02 2019, Stephen Berman wrote:
>> (I normally view DJVU files in Emacs using the djvu package from ELPA
> Really?  Hooray, someone else is using this package, too.  I thought I
> was the very only one.

I'm quite happy with this package, and the current version is even more
attractive compared to the previous one, especially the buttonized
outline.  There are a couple of features I miss; one is that I often
like to open DJVU files from Dired, so I added this to my init file:

(defun srb-djvu-mode ()
  (let ((file (buffer-file-name)))
    (kill-buffer (file-name-nondirectory file))
    (djvu-find-file file)))

(add-to-list 'auto-mode-alist '("\\.djvu\\'" . srb-djvu-mode))

Another nice thing would be integration with the Emacs bookmark facility
(I haven't tried using the djvu bookmark facility, but it looks like
it's tied to djvu outlines, so orthogonal to Emacs bookmarks).  I've
tried adapting the bookmark integration in Andreas Politz's pdf-tools
package, and it seems to works well enough for my purposes.  I also like
the way pdf-view-mode (and doc-view-mode) displays both the current and
total number of pages, so I adapted djvu-read-mode to that as well.
Here's the code, in case you or anyone else is interested:

(defun djvu-bookmark-make-record ()
  (cons (buffer-name)
       (append (bookmark-make-record-default nil t 1)
               `(,(cons 'page (djvu-ref page))
                 ,(cons 'size (djvu-ref pagesize))
                 (handler . djvu-view-bookmark-jump-handler)))))

(defun djvu-view-bookmark-jump-handler (bmk)
  (let ((page (bookmark-prop-get bmk 'page))
        ;; (slice (bookmark-prop-get bmk 'slice))
        (size (bookmark-prop-get bmk 'size))
        ;; (origin (bookmark-prop-get bmk 'origin))
        (file (bookmark-prop-get bmk 'filename))
        (show-fn-sym (make-symbol "djvu-bookmark-after-jump-hook")))
    (fset show-fn-sym
          (lambda ()
            (remove-hook 'bookmark-after-jump-hook show-fn-sym)
            (unless (derived-mode-p 'djvu-read-mode)
                (or (get-buffer-window (current-buffer) 0)
              (when size
                (setq-local djvu-doc-pagesize size))
              ;; (when slice
              ;;   (apply 'pdf-view-set-slice slice))
              (when (numberp page)
                (djvu-goto-page page))
              ;; (when origin
              ;;   (let ((size (pdf-view-image-size t)))
              ;;     (image-set-window-hscroll
              ;;      (round (/ (* (car origin) (car size))
              ;;                (frame-char-width))))
              ;;     (image-set-window-vscroll
              ;;      (round (/ (* (cdr origin) (cdr size))
              ;;                (frame-char-height))))))
    (add-hook 'bookmark-after-jump-hook show-fn-sym)
    (set-buffer (or (find-buffer-visiting file)
                    (find-file-noselect file)))))

(define-derived-mode djvu-read-mode special-mode "Djview"
  "Mode for reading Djvu files."
  (setq djvu-buffer 'read
        buffer-undo-list t
        ;; mode-line-buffer-identification
        ;; (list 24 '(:eval (format "%s  p%d" (buffer-name) (djvu-ref page))))
  (setq-local mode-line-position
              '(" P" (:eval (number-to-string (djvu-ref page)))
                ;; Avoid errors during redisplay.
                "/" (:eval (or (ignore-errors
                                 (number-to-string (djvu-ref pagemax)))
  (setq-local revert-buffer-function 'djvu-revert-buffer)
  (setq-local bookmark-make-record-function 'djvu-bookmark-make-record))

Thanks for the djvu package!

Steve Berman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]