all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Roland Winkler <winkler@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: DJVU files and ImageMagick
Date: Mon, 04 Feb 2019 18:34:37 +0100	[thread overview]
Message-ID: <87lg2vjw42.fsf@gmx.net> (raw)
In-Reply-To: <87va201e07.fsf@gnu.org> (Roland Winkler's message of "Sun, 03 Feb 2019 20:30:48 -0600")

On Sun, 03 Feb 2019 20:30:48 -0600 Roland Winkler <winkler@gnu.org> 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)
              (djvu-read-mode))
            (with-selected-window
                (or (get-buffer-window (current-buffer) 0)
                    (selected-window))
              (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



  parent reply	other threads:[~2019-02-04 17:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-02 22:12 DJVU files and ImageMagick Stephen Berman
2019-02-03 17:12 ` Eli Zaretskii
2019-02-03 21:48   ` joakim
2019-02-04  2:30 ` Roland Winkler
2019-02-04  7:18   ` Colin Baxter
2019-02-04 17:34   ` Stephen Berman [this message]
2019-02-06  3:53     ` Roland Winkler
2019-02-06  5:30       ` Drew Adams
2019-02-06 16:35         ` Roland Winkler
2019-02-06  8:45       ` Stephen Berman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lg2vjw42.fsf@gmx.net \
    --to=stephen.berman@gmx.net \
    --cc=emacs-devel@gnu.org \
    --cc=winkler@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.