unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] add epub support to doc-view
@ 2022-01-11  2:20 dalanicolai
  2022-01-11  2:32 ` Po Lu
  2022-01-11  2:48 ` Stefan Monnier
  0 siblings, 2 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11  2:20 UTC (permalink / raw)
  To: Emacs Devel


[-- Attachment #1.1: Type: text/plain, Size: 654 bytes --]

Here is a patch to add epub support to doc-view, via the mutool command of
the
mupdf library,I guess the patch needs no further explanation. I've read the
info
about sending patches, however, I don't understand the section about the
changelog (it mentions that there is a changelog or something, but it
doesn't
say where). Also, the info tells us to write the commit log entries, but it
does
not say where to do this.Looking at the changelog files, I guess that info
is
just really outdated (am I right?).Anyway, the patch is in the attachment.
If
there is some part of the 'protocol' that I did not understand then please
inform me about it.

Thank you

[-- Attachment #1.2: Type: text/html, Size: 730 bytes --]

[-- Attachment #2: add-epub-to-doc-view.patch --]
[-- Type: text/x-patch, Size: 8978 bytes --]

diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 5b462b24f5..6ac1fb4945 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
 ;;
 ;; Author: Tassilo Horn <tsdh@gnu.org>
-;; Keywords: files, pdf, ps, dvi
+;; Keywords: files, pdf, ps, dvi, epub, djvu
 
 ;; This file is part of GNU Emacs.
 
@@ -25,15 +25,16 @@
 ;; Viewing PS/PDF/DVI files requires Ghostscript, `dvipdf' (comes with
 ;; Ghostscript) or `dvipdfm' (comes with teTeX or TeXLive) and
 ;; `pdftotext', which comes with xpdf (https://www.foolabs.com/xpdf/)
-;; or poppler (https://poppler.freedesktop.org/).
-;; Djvu documents require `ddjvu' (from DjVuLibre).
-;; ODF files require `soffice' (from LibreOffice).
+;; or poppler (https://poppler.freedesktop.org/). EPUB documents
+;; require `mutool' which comes with mupdf
+;; (https://mupdf.com/index.html). Djvu documents require `ddjvu'
+;; (from DjVuLibre).  ODF files require `soffice' (from LibreOffice).
 
 ;;; Commentary:
 
 ;; DocView is a document viewer for Emacs.  It converts a number of
-;; document formats (including PDF, PS, DVI, Djvu and ODF files) to a
-;; set of PNG files, one PNG for each page, and displays the PNG
+;; document formats (including PDF, EPUB, PS, DVI, Djvu and ODF files)
+;; to a set of PNG files, one PNG for each page, and displays the PNG
 ;; images inside an Emacs buffer.  This buffer uses `doc-view-mode'
 ;; which provides convenient key bindings for browsing the document.
 ;;
@@ -147,7 +148,7 @@
 ;;;; Customization Options
 
 (defgroup doc-view nil
-  "In-buffer viewer for PDF, PostScript, DVI, and DJVU files."
+  "In-buffer viewer for PDF, EPUB, PostScript, DVI, and DJVU files."
   :link '(function-link doc-view)
   :version "22.2"
   :group 'applications
@@ -257,8 +258,8 @@ doc-view-dvipdf-program
   :type 'file)
 
 (define-obsolete-variable-alias 'doc-view-unoconv-program
-                                'doc-view-odf->pdf-converter-program
-                                "24.4")
+  'doc-view-odf->pdf-converter-program
+  "24.4")
 
 (defcustom doc-view-odf->pdf-converter-program
   (cond
@@ -329,6 +330,7 @@ doc-view--current-converter-processes
   "Only used internally.")
 
 (defun doc-view-new-window-function (winprops)
+  ;; TODO: write documentation!
   ;; (message "New window %s for buf %s" (car winprops) (current-buffer))
   (cl-assert (or (eq t (car winprops))
                  (eq (window-buffer (car winprops)) (current-buffer))))
@@ -382,7 +384,7 @@ doc-view--buffer-file-name
 
 (defvar doc-view-doc-type nil
   "The type of document in the current buffer.
-Can be `dvi', `pdf', `ps', `djvu' or `odf'.")
+Can be `dvi', `pdf', 'epub', `ps', `djvu' or `odf'.")
 
 (defvar doc-view-single-page-converter-function nil
   "Function to call to convert a single page of the document to a bitmap file.
@@ -738,7 +740,7 @@ doc-view-kill-proc
   (interactive)
   (while (consp doc-view--current-converter-processes)
     (ignore-errors ;; Some entries might not be processes, and maybe
-		   ;; some are dead already?
+      ;; some are dead already?
       (kill-process (pop doc-view--current-converter-processes))))
   (when doc-view--current-timer
     (cancel-timer doc-view--current-timer)
@@ -810,11 +812,12 @@ doc-view-mode-p
 		       (executable-find doc-view-dvipdf-program))
 		  (and doc-view-dvipdfm-program
 		       (executable-find doc-view-dvipdfm-program)))))
-	((memq type '(postscript ps eps pdf))
-	 (or (and doc-view-ghostscript-program
-	          (executable-find doc-view-ghostscript-program))
-             (and doc-view-pdfdraw-program
-                  (executable-find doc-view-pdfdraw-program))))
+	((memq type '(postscript ps eps pdf epub))
+         (if-let (command (and (memq type '(pdf epub)) (executable-find "mutool")))
+             command
+	   (unless (eq type 'epub)
+             (and doc-view-ghostscript-program
+	          (executable-find doc-view-ghostscript-program)))))
 	((eq type 'odf)
 	 (and doc-view-odf->pdf-converter-program
 	      (executable-find doc-view-odf->pdf-converter-program)
@@ -1053,7 +1056,7 @@ doc-view-start-process
   ;; some file-name-handler-managed dir, for example).
   (let* ((default-directory (or (unhandled-file-name-directory
                                  default-directory)
-			      (expand-file-name "~/")))
+			        (expand-file-name "~/")))
          (proc (apply #'start-process name doc-view-conversion-buffer
                       program args)))
     (push proc doc-view--current-converter-processes)
@@ -1189,7 +1192,7 @@ doc-view-pdf/ps->png
   "Convert PDF-PS to PNG asynchronously."
   (funcall
    (pcase doc-view-doc-type
-     ('pdf doc-view-pdf->png-converter-function)
+     ((or 'pdf 'epub) doc-view-pdf->png-converter-function)
      ('djvu #'doc-view-djvu->tiff-converter-ddjvu)
      (_ #'doc-view-ps->png-converter-ghostscript))
    pdf-ps png nil
@@ -1227,20 +1230,20 @@ doc-view-document->bitmap
     (let ((rest (cdr pages)))
       (funcall doc-view-single-page-converter-function
 	       pdf (format png (car pages)) (car pages)
-       (lambda ()
-         (if rest
-             (doc-view-document->bitmap pdf png rest)
-           ;; Yippie, the important pages are done, update the display.
-           (clear-image-cache)
-           ;; For the windows that have a message (like "Welcome to
-           ;; DocView") display property, clearing the image cache is
-           ;; not sufficient.
-           (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
-             (with-selected-window win
-	       (when (stringp (overlay-get (doc-view-current-overlay) 'display))
-		 (doc-view-goto-page (doc-view-current-page)))))
-           ;; Convert the rest of the pages.
-           (doc-view-pdf/ps->png pdf png)))))))
+               (lambda ()
+                 (if rest
+                     (doc-view-document->bitmap pdf png rest)
+                   ;; Yippie, the important pages are done, update the display.
+                   (clear-image-cache)
+                   ;; For the windows that have a message (like "Welcome to
+                   ;; DocView") display property, clearing the image cache is
+                   ;; not sufficient.
+                   (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
+                     (with-selected-window win
+	               (when (stringp (overlay-get (doc-view-current-overlay) 'display))
+		         (doc-view-goto-page (doc-view-current-page)))))
+                   ;; Convert the rest of the pages.
+                   (doc-view-pdf/ps->png pdf png)))))))
 
 (defun doc-view-pdf->txt (pdf txt callback)
   "Convert PDF to TXT asynchronously and call CALLBACK when finished."
@@ -1337,7 +1340,12 @@ doc-view-convert-current-doc
 		    ;; Rename to doc.pdf
 		    (rename-file opdf pdf)
 		    (doc-view-pdf/ps->png pdf png-file)))))
-      ((or 'pdf 'djvu)
+      ((or 'pdf 'epub 'djvu)
+       (when (eq doc-view-doc-type 'epub)
+         (unless (eq doc-view-pdf->png-converter-function 'doc-view-pdf->png-converter-mupdf)
+           (user-error "Viewing epub documents requires the`mutool' command to be available,
+and `doc-view-pdf->png-converter-function' variable set to
+`doc-view-pdf->png-converter-mupdf'")))
        (let ((pages (doc-view-active-pages)))
          ;; Convert doc to bitmap images starting with the active pages.
          (doc-view-document->bitmap doc-view--buffer-file-name png-file pages)))
@@ -1869,6 +1877,8 @@ doc-view-set-doc-type
                    ("dvi" dvi)
                    ;; PDF
                    ("pdf" pdf) ("epdf" pdf)
+                   ;; EPUB
+                   ("epub" epub)
                    ;; PostScript
                    ("ps" ps) ("eps" ps)
                    ;; DjVu
@@ -1889,7 +1899,8 @@ doc-view-set-doc-type
 	    ((looking-at "%!") '(ps))
 	    ((looking-at "%PDF") '(pdf))
 	    ((looking-at "\367\002") '(dvi))
-	    ((looking-at "AT&TFORM") '(djvu))))))
+	    ((looking-at "AT&TFORM") '(djvu))
+            ((looking-at "PK") '(epub))))))
     (setq-local
      doc-view-doc-type
      (car (or (nreverse (seq-intersection name-types content-types #'eq))
diff --git a/lisp/files.el b/lisp/files.el
index a11786fca2..74f9d83d4e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2925,7 +2925,7 @@ auto-mode-alist
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MS-DOS
      ("\\.[eE]?[pP][sS]\\'" . ps-mode)
-     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
+     ("\\.\\(?:PDF\\|EPUB\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|epub\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  2:20 [PATCH] add epub support to doc-view dalanicolai
@ 2022-01-11  2:32 ` Po Lu
  2022-01-11  9:34   ` dalanicolai
  2022-01-11  2:48 ` Stefan Monnier
  1 sibling, 1 reply; 26+ messages in thread
From: Po Lu @ 2022-01-11  2:32 UTC (permalink / raw)
  To: dalanicolai; +Cc: Emacs Devel

dalanicolai <dalanicolai@gmail.com> writes:

> I've read the info about sending patches, however, I don't understand
> the section about the changelog (it mentions that there is a changelog
> or something, but it doesn't say where).

> Also, the info tells us to write the commit log entries, but it does
> not say where to do this.

Basically, the VCS will ask you to type in a message describing each
commit you make.  You simply have to format that message like you would
an entry in a ChangeLog.

> Looking at the changelog files, I guess that info is just really
> outdated (am I right?).

The ChangeLog files are automatically generated from VCS history (your
commit log entries) every time a release is made, AFAIK.

I hope I cleared up some things.

> Anyway, the patch is in the attachment.

Thanks!  Have you signed the copyright papers?

> If there is some part of the 'protocol' that I did not understand then
> please inform me about it.

You should read CONTRIBUTE, it details the procedure quite well.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  2:20 [PATCH] add epub support to doc-view dalanicolai
  2022-01-11  2:32 ` Po Lu
@ 2022-01-11  2:48 ` Stefan Monnier
  2022-01-11  3:30   ` Stefan Kangas
  2022-01-11  9:59   ` dalanicolai
  1 sibling, 2 replies; 26+ messages in thread
From: Stefan Monnier @ 2022-01-11  2:48 UTC (permalink / raw)
  To: dalanicolai; +Cc: Emacs Devel

> Here is a patch to add epub support to doc-view, via the mutool
> command of the mupdf library,I guess the patch needs no further
> explanation.  I've read the info about sending patches, however,
> I don't understand the section about the changelog (it mentions that
> there is a changelog or something, but it doesn't say where). Also,
> the info tells us to write the commit log entries, but it does not say
> where to do this.Looking at the changelog files, I guess that info is
> just really outdated (am I right?).  Anyway, the patch is in the
> attachment.  If there is some part of the 'protocol' that I did not
> understand then please inform me about it.

Looks pretty good, see below for some comments/questions.
Regarding the changelog, we just need you to give us something like

    doc-view.el: Add support for EPub

    <Some explanation for the general idea>

    * lisp/doc-view.el (<fun1>): <Do this>.
    (<var2>): <Do that>.
    ...

    * lisp/files.el (auto-mode-alist): Extend doc-view-mode-maybe
    regexp to match `.epub` files.

>  (define-obsolete-variable-alias 'doc-view-unoconv-program
> -                                'doc-view-odf->pdf-converter-program
> -                                "24.4")
> +  'doc-view-odf->pdf-converter-program
> +  "24.4")


Thanks.  At this point, the last two args can be placed on the same
line ;-)

>  (defun doc-view-new-window-function (winprops)
> +  ;; TODO: write documentation!
>    ;; (message "New window %s for buf %s" (car winprops) (current-buffer))
>    (cl-assert (or (eq t (car winprops))
>                   (eq (window-buffer (car winprops)) (current-buffer))))

I plead guilty, but if you give me a more specific question, I'll find
it easier to answer it (even in the form of a docstring or comment).

> @@ -738,7 +740,7 @@ doc-view-kill-proc
>    (interactive)
>    (while (consp doc-view--current-converter-processes)
>      (ignore-errors ;; Some entries might not be processes, and maybe
> -		   ;; some are dead already?
> +      ;; some are dead already?
>        (kill-process (pop doc-view--current-converter-processes))))
>    (when doc-view--current-timer
>      (cancel-timer doc-view--current-timer)

Here the auto-indentation gets it wrong, sadly.

> @@ -810,11 +812,12 @@ doc-view-mode-p
>  		       (executable-find doc-view-dvipdf-program))
>  		  (and doc-view-dvipdfm-program
>  		       (executable-find doc-view-dvipdfm-program)))))
> -	((memq type '(postscript ps eps pdf))
> -	 (or (and doc-view-ghostscript-program
> -	          (executable-find doc-view-ghostscript-program))
> -             (and doc-view-pdfdraw-program
> -                  (executable-find doc-view-pdfdraw-program))))
> +	((memq type '(postscript ps eps pdf epub))
> +         (if-let (command (and (memq type '(pdf epub)) (executable-find "mutool")))
> +             command
> +	   (unless (eq type 'epub)
> +             (and doc-view-ghostscript-program
> +	          (executable-find doc-view-ghostscript-program)))))
>  	((eq type 'odf)
>  	 (and doc-view-odf->pdf-converter-program
>  	      (executable-find doc-view-odf->pdf-converter-program)

Hmm... for PDF files, this changes the previous behavior where we
checked for the presence of `doc-view-pdfdraw-program` rather than "mutool".
Was there a strong reason to hardcode "mutool" here?

Depending on the reason, we may be better off splitting the epub
handling into its own `cond` branch.

Also, I think the rest of the code will still launch
`doc-view-pdfdraw-program` rather than `mutool`, so there's
something fishy.

> -      ((or 'pdf 'djvu)
> +      ((or 'pdf 'epub 'djvu)
> +       (when (eq doc-view-doc-type 'epub)
> +         (unless (eq doc-view-pdf->png-converter-function 'doc-view-pdf->png-converter-mupdf)
> +           (user-error "Viewing epub documents requires the`mutool' command to be available,
> +and `doc-view-pdf->png-converter-function' variable set to
> +`doc-view-pdf->png-converter-mupdf'")))

This error message needs to be shorter.  It probably shouldn't talk
about `mutool`.  Even with this simplification I think we're going to
have to be creative to make it short enough to fit in a single line of
80 columns.  We should probably just say something like

    doc-view-pdf->png-converter-function invalid for EPub

and then add in the docstring of `doc-view-pdf->png-converter-function`
a note about the fact that only `doc-view-pdf->png-converter-mupdf`
supports EPub.

The rest looks good.


        Stefan




^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  2:48 ` Stefan Monnier
@ 2022-01-11  3:30   ` Stefan Kangas
  2022-01-11 10:01     ` dalanicolai
  2022-01-11  9:59   ` dalanicolai
  1 sibling, 1 reply; 26+ messages in thread
From: Stefan Kangas @ 2022-01-11  3:30 UTC (permalink / raw)
  To: Stefan Monnier, dalanicolai; +Cc: Emacs Devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Regarding the changelog, we just need you to give us something like
>
>     doc-view.el: Add support for EPub
>
>     <Some explanation for the general idea>
>
>     * lisp/doc-view.el (<fun1>): <Do this>.
>     (<var2>): <Do that>.
>     ...
>
>     * lisp/files.el (auto-mode-alist): Extend doc-view-mode-maybe
>     regexp to match `.epub` files.

I recommend using `C-x 4 a' (`add-change-log-entry-other-window') to
save you some typing.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  2:32 ` Po Lu
@ 2022-01-11  9:34   ` dalanicolai
  2022-01-11  9:50     ` Tassilo Horn
  2022-01-11  9:59     ` Robert Pluim
  0 siblings, 2 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11  9:34 UTC (permalink / raw)
  To: Po Lu; +Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 1841 bytes --]

>
> Basically, the VCS will ask you to type in a message describing each
> commit you make.  You simply have to format that message like you would
> an entry in a ChangeLog.


I guess you mean that git will ask to enter a commit message? So I did that,
but how does it get into the patch? (I am using magit, maybe I should check
out vc, which is what I am doing now)

The ChangeLog files are automatically generated from VCS history (your
> commit log entries) every time a release is made, AFAIK.
>

Indeed, I think I've read that somewhere .

Thanks!  Have you signed the copyright papers?
>

yes

You should read CONTRIBUTE, it details the procedure quite well.
>

good idea, I forgot about that document

On Tue, 11 Jan 2022 at 03:32, Po Lu <luangruo@yahoo.com> wrote:

> dalanicolai <dalanicolai@gmail.com> writes:
>
> > I've read the info about sending patches, however, I don't understand
> > the section about the changelog (it mentions that there is a changelog
> > or something, but it doesn't say where).
>
> > Also, the info tells us to write the commit log entries, but it does
> > not say where to do this.
>
> Basically, the VCS will ask you to type in a message describing each
> commit you make.  You simply have to format that message like you would
> an entry in a ChangeLog.
>
> > Looking at the changelog files, I guess that info is just really
> > outdated (am I right?).
>
> The ChangeLog files are automatically generated from VCS history (your
> commit log entries) every time a release is made, AFAIK.
>
> I hope I cleared up some things.
>
> > Anyway, the patch is in the attachment.
>
> Thanks!  Have you signed the copyright papers?
>
> > If there is some part of the 'protocol' that I did not understand then
> > please inform me about it.
>
> You should read CONTRIBUTE, it details the procedure quite well.
>

[-- Attachment #2: Type: text/html, Size: 3065 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:34   ` dalanicolai
@ 2022-01-11  9:50     ` Tassilo Horn
  2022-01-11 10:04       ` dalanicolai
  2022-01-11  9:59     ` Robert Pluim
  1 sibling, 1 reply; 26+ messages in thread
From: Tassilo Horn @ 2022-01-11  9:50 UTC (permalink / raw)
  To: dalanicolai; +Cc: Po Lu, emacs-devel

dalanicolai <dalanicolai@gmail.com> writes:

>> Basically, the VCS will ask you to type in a message describing each
>> commit you make.  You simply have to format that message like you
>> would an entry in a ChangeLog.
>
> I guess you mean that git will ask to enter a commit message? So I did
> that, but how does it get into the patch? (I am using magit, maybe I
> should check out vc, which is what I am doing now)

You export the commit as git patch using "git format-patch
<commit-or-range>".  With Magit, that's available using `W c c'.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  2:48 ` Stefan Monnier
  2022-01-11  3:30   ` Stefan Kangas
@ 2022-01-11  9:59   ` dalanicolai
  2022-01-11 10:13     ` dalanicolai
  2022-01-11 14:39     ` Stefan Monnier
  1 sibling, 2 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11  9:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 9632 bytes --]

>  (define-obsolete-variable-alias 'doc-view-unoconv-program
>
> -                                'doc-view-odf->pdf-converter-program
> > -                                "24.4")
> > +  'doc-view-odf->pdf-converter-program
> > +  "24.4")
>
> Thanks.  At this point, the last two args can be placed on the same
> line ;-)


This is also due to the auto-indent, but I will correct it manually.

>  (defun doc-view-new-window-function (winprops)
> > +  ;; TODO: write documentation!
> >    ;; (message "New window %s for buf %s" (car winprops)
> (current-buffer))
> >    (cl-assert (or (eq t (car winprops))
> >                   (eq (window-buffer (car winprops)) (current-buffer))))
>
> I plead guilty, but if you give me a more specific question, I'll find
> it easier to answer it (even in the form of a docstring or comment).
>

This I copied from pdf-tools. However, I am planning to enter this
documentation
myself, while I am implementing real continuous scroll. I have got that
working in
pdf-tools already, but I had to disable all kinds of minor modes there. So
I thought
let's start with a simpler task of implementing it in doc-view, however,
the same
difficulty, that I encountered also in pdf-tools is that somehow
`bookroll-mode-winprops-alist` (which is exactly the equivalent/copy of
`bookroll-mode-winprops-alist`) obtains a value `t`. I think I've spent
some hours
already investigating where it obtains it (somehow I fixed it after
debugging for
pdf-tools for few hours, but clearly I do not understand how, and have to
repeat the
same things again, well I guess it is a good exercise. Anyway, in the end I
hope to
add some useful documentation to prevent other hackers from 'wasting' their
time :)
Anyway, if I can keep it like this for now, that would be great, as the
TODO really
jumps out font lock wise, and also I can search for it.

> @@ -738,7 +740,7 @@ doc-view-kill-proc
> >    (interactive)
> >    (while (consp doc-view--current-converter-processes)
> >      (ignore-errors ;; Some entries might not be processes, and maybe
> > -                ;; some are dead already?
> > +      ;; some are dead already?
> >        (kill-process (pop doc-view--current-converter-processes))))
> >    (when doc-view--current-timer
> >      (cancel-timer doc-view--current-timer)
>
> Here the auto-indentation gets it wrong, sadly.
>

You mean because it aligns with the line below so that it looks like it
belongs
to that one? Because otherwise, I think it does not look bad.

> +     ((memq type '(postscript ps eps pdf epub))
> > +         (if-let (command (and (memq type '(pdf epub)) (executable-find
> "mutool")))
> > +             command
> > +        (unless (eq type 'epub)
> > +             (and doc-view-ghostscript-program
> > +               (executable-find doc-view-ghostscript-program)))))
> >       ((eq type 'odf)
> >        (and doc-view-odf->pdf-converter-program
> >             (executable-find doc-view-odf->pdf-converter-program)
>
> Hmm... for PDF files, this changes the previous behavior where we
> checked for the presence of `doc-view-pdfdraw-program` rather than
> "mutool".
> Was there a strong reason to hardcode "mutool" here
>

Ah yes, I was aware of that, but indeed I did that consciously. I have very
good experiences
with (py)mupdf (I have implemented an alternative pdf-tools server using
it, and indeed it is
much faster than the epdfinfo server, well at least the mupdf vs poppler
parts.

really take a very quick look at the two histograms in this link
<https://hub.alfresco.com/t5/alfresco-content-services-blog/pdf-rendering-engine-performance-and-fidelity-comparison/ba-p/287618>
.
So I decided this behavior really wouldn't be a problem, why not prefer
mutool when it is
available?

Also, I think the rest of the code will still launch
> `doc-view-pdfdraw-program` rather than `mutool`, so there's
> something fishy.
>

That I do not understand immediately, for me the behavior is still somewhat
opaque. But I
will be trying to understand things further today (anyway for implementing
the continuous scroll)
and try to understand how it all works (and correct it here).

This error message needs to be shorter.  It probably shouldn't talk
> about `mutool`.  Even with this simplification I think we're going to
> have to be creative to make it short enough to fit in a single line of
> 80 columns.  We should probably just say something like
>
>     doc-view-pdf->png-converter-function invalid for EPub
>
> and then add in the docstring of `doc-view-pdf->png-converter-function`
> a note about the fact that only `doc-view-pdf->png-converter-mupdf`
> supports EPub.
>

That sounds good indeed. I will take care of that.

Thanks, for the feedback... I will try another 'round' probably sooner than
later :)





On Tue, 11 Jan 2022 at 03:48, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > Here is a patch to add epub support to doc-view, via the mutool
> > command of the mupdf library,I guess the patch needs no further
> > explanation.  I've read the info about sending patches, however,
> > I don't understand the section about the changelog (it mentions that
> > there is a changelog or something, but it doesn't say where). Also,
> > the info tells us to write the commit log entries, but it does not say
> > where to do this.Looking at the changelog files, I guess that info is
> > just really outdated (am I right?).  Anyway, the patch is in the
> > attachment.  If there is some part of the 'protocol' that I did not
> > understand then please inform me about it.
>
> Looks pretty good, see below for some comments/questions.
> Regarding the changelog, we just need you to give us something like
>
>     doc-view.el: Add support for EPub
>
>     <Some explanation for the general idea>
>
>     * lisp/doc-view.el (<fun1>): <Do this>.
>     (<var2>): <Do that>.
>     ...
>
>     * lisp/files.el (auto-mode-alist): Extend doc-view-mode-maybe
>     regexp to match `.epub` files.
>
> >  (define-obsolete-variable-alias 'doc-view-unoconv-program
> > -                                'doc-view-odf->pdf-converter-program
> > -                                "24.4")
> > +  'doc-view-odf->pdf-converter-program
> > +  "24.4")
>
>
> Thanks.  At this point, the last two args can be placed on the same
> line ;-)
>
> >  (defun doc-view-new-window-function (winprops)
> > +  ;; TODO: write documentation!
> >    ;; (message "New window %s for buf %s" (car winprops)
> (current-buffer))
> >    (cl-assert (or (eq t (car winprops))
> >                   (eq (window-buffer (car winprops)) (current-buffer))))
>
> I plead guilty, but if you give me a more specific question, I'll find
> it easier to answer it (even in the form of a docstring or comment).
>
> > @@ -738,7 +740,7 @@ doc-view-kill-proc
> >    (interactive)
> >    (while (consp doc-view--current-converter-processes)
> >      (ignore-errors ;; Some entries might not be processes, and maybe
> > -                ;; some are dead already?
> > +      ;; some are dead already?
> >        (kill-process (pop doc-view--current-converter-processes))))
> >    (when doc-view--current-timer
> >      (cancel-timer doc-view--current-timer)
>
> Here the auto-indentation gets it wrong, sadly.
>
> > @@ -810,11 +812,12 @@ doc-view-mode-p
> >                      (executable-find doc-view-dvipdf-program))
> >                 (and doc-view-dvipdfm-program
> >                      (executable-find doc-view-dvipdfm-program)))))
> > -     ((memq type '(postscript ps eps pdf))
> > -      (or (and doc-view-ghostscript-program
> > -               (executable-find doc-view-ghostscript-program))
> > -             (and doc-view-pdfdraw-program
> > -                  (executable-find doc-view-pdfdraw-program))))
> > +     ((memq type '(postscript ps eps pdf epub))
> > +         (if-let (command (and (memq type '(pdf epub)) (executable-find
> "mutool")))
> > +             command
> > +        (unless (eq type 'epub)
> > +             (and doc-view-ghostscript-program
> > +               (executable-find doc-view-ghostscript-program)))))
> >       ((eq type 'odf)
> >        (and doc-view-odf->pdf-converter-program
> >             (executable-find doc-view-odf->pdf-converter-program)
>
> Hmm... for PDF files, this changes the previous behavior where we
> checked for the presence of `doc-view-pdfdraw-program` rather than
> "mutool".
> Was there a strong reason to hardcode "mutool" here?
>
> Depending on the reason, we may be better off splitting the epub
> handling into its own `cond` branch.
>
> Also, I think the rest of the code will still launch
> `doc-view-pdfdraw-program` rather than `mutool`, so there's
> something fishy.
>
> > -      ((or 'pdf 'djvu)
> > +      ((or 'pdf 'epub 'djvu)
> > +       (when (eq doc-view-doc-type 'epub)
> > +         (unless (eq doc-view-pdf->png-converter-function
> 'doc-view-pdf->png-converter-mupdf)
> > +           (user-error "Viewing epub documents requires the`mutool'
> command to be available,
> > +and `doc-view-pdf->png-converter-function' variable set to
> > +`doc-view-pdf->png-converter-mupdf'")))
>
> This error message needs to be shorter.  It probably shouldn't talk
> about `mutool`.  Even with this simplification I think we're going to
> have to be creative to make it short enough to fit in a single line of
> 80 columns.  We should probably just say something like
>
>     doc-view-pdf->png-converter-function invalid for EPub
>
> and then add in the docstring of `doc-view-pdf->png-converter-function`
> a note about the fact that only `doc-view-pdf->png-converter-mupdf`
> supports EPub.
>
> The rest looks good.
>
>
>         Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 12943 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:34   ` dalanicolai
  2022-01-11  9:50     ` Tassilo Horn
@ 2022-01-11  9:59     ` Robert Pluim
  2022-01-11 10:09       ` dalanicolai
  1 sibling, 1 reply; 26+ messages in thread
From: Robert Pluim @ 2022-01-11  9:59 UTC (permalink / raw)
  To: dalanicolai; +Cc: Po Lu, Emacs Devel

>>>>> On Tue, 11 Jan 2022 10:34:01 +0100, dalanicolai <dalanicolai@gmail.com> said:

    >> 
    >> Basically, the VCS will ask you to type in a message describing each
    >> commit you make.  You simply have to format that message like you would
    >> an entry in a ChangeLog.


    dalanicolai> I guess you mean that git will ask to enter a commit message? So I did that,
    dalanicolai> but how does it get into the patch? (I am using magit, maybe I should check
    dalanicolai> out vc, which is what I am doing now)

The commit message is part of the patch. This is git, you
should not skimp on committing locally :-) (you can always run 'git
commit --amend' if you need to make more changes to the same patch)

You then generate the patch using 'git format-patch HEAD~' or the
equivalent magit command.

Since youʼre using magit, you can start your commit, then run
`magit-generate-changelog', which will insert a skeleton ChangeLog
formatted entry based on the diffs of the files that youʼre
committing. You then just need to write a one-line summary of the
change, and describe the changes in the individual files.

Robert
-- 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  3:30   ` Stefan Kangas
@ 2022-01-11 10:01     ` dalanicolai
  2022-01-11 10:16       ` Robert Pluim
  0 siblings, 1 reply; 26+ messages in thread
From: dalanicolai @ 2022-01-11 10:01 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Stefan Monnier, Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

Haha, okay. It is still not clear to me where. But I guess that will become
clear then.
Anyway, thanks for the tip.

On Tue, 11 Jan 2022 at 04:30, Stefan Kangas <stefankangas@gmail.com> wrote:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> > Regarding the changelog, we just need you to give us something like
> >
> >     doc-view.el: Add support for EPub
> >
> >     <Some explanation for the general idea>
> >
> >     * lisp/doc-view.el (<fun1>): <Do this>.
> >     (<var2>): <Do that>.
> >     ...
> >
> >     * lisp/files.el (auto-mode-alist): Extend doc-view-mode-maybe
> >     regexp to match `.epub` files.
>
> I recommend using `C-x 4 a' (`add-change-log-entry-other-window') to
> save you some typing.
>

[-- Attachment #2: Type: text/html, Size: 1244 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:50     ` Tassilo Horn
@ 2022-01-11 10:04       ` dalanicolai
  2022-01-11 10:08         ` dalanicolai
  2022-01-11 10:15         ` Robert Pluim
  0 siblings, 2 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11 10:04 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Po Lu, Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Thanks, yeah I tried that, but it does not seem to work. I am selecting the
commit first,
but the command does not 'fill in' the range and does not create a patch
(to me it looks like
a bug, but probably I am doing something wrong)

On Tue, 11 Jan 2022 at 10:53, Tassilo Horn <tsdh@gnu.org> wrote:

> dalanicolai <dalanicolai@gmail.com> writes:
>
> >> Basically, the VCS will ask you to type in a message describing each
> >> commit you make.  You simply have to format that message like you
> >> would an entry in a ChangeLog.
> >
> > I guess you mean that git will ask to enter a commit message? So I did
> > that, but how does it get into the patch? (I am using magit, maybe I
> > should check out vc, which is what I am doing now)
>
> You export the commit as git patch using "git format-patch
> <commit-or-range>".  With Magit, that's available using `W c c'.
>
> Bye,
> Tassilo
>

[-- Attachment #2: Type: text/html, Size: 1368 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11 10:04       ` dalanicolai
@ 2022-01-11 10:08         ` dalanicolai
  2022-01-11 10:15         ` Robert Pluim
  1 sibling, 0 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11 10:08 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Po Lu, Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

so I resorted to W s (Save diff as patch)

On Tue, 11 Jan 2022 at 11:04, dalanicolai <dalanicolai@gmail.com> wrote:

> Thanks, yeah I tried that, but it does not seem to work. I am selecting
> the commit first,
> but the command does not 'fill in' the range and does not create a patch
> (to me it looks like
> a bug, but probably I am doing something wrong)
>
> On Tue, 11 Jan 2022 at 10:53, Tassilo Horn <tsdh@gnu.org> wrote:
>
>> dalanicolai <dalanicolai@gmail.com> writes:
>>
>> >> Basically, the VCS will ask you to type in a message describing each
>> >> commit you make.  You simply have to format that message like you
>> >> would an entry in a ChangeLog.
>> >
>> > I guess you mean that git will ask to enter a commit message? So I did
>> > that, but how does it get into the patch? (I am using magit, maybe I
>> > should check out vc, which is what I am doing now)
>>
>> You export the commit as git patch using "git format-patch
>> <commit-or-range>".  With Magit, that's available using `W c c'.
>>
>> Bye,
>> Tassilo
>>
>

[-- Attachment #2: Type: text/html, Size: 1786 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:59     ` Robert Pluim
@ 2022-01-11 10:09       ` dalanicolai
  0 siblings, 0 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11 10:09 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Po Lu, Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

That sounds like even I understand how to do it! Thanks, will give it a
try...

On Tue, 11 Jan 2022 at 10:59, Robert Pluim <rpluim@gmail.com> wrote:

> >>>>> On Tue, 11 Jan 2022 10:34:01 +0100, dalanicolai <
> dalanicolai@gmail.com> said:
>
>     >>
>     >> Basically, the VCS will ask you to type in a message describing each
>     >> commit you make.  You simply have to format that message like you
> would
>     >> an entry in a ChangeLog.
>
>
>     dalanicolai> I guess you mean that git will ask to enter a commit
> message? So I did that,
>     dalanicolai> but how does it get into the patch? (I am using magit,
> maybe I should check
>     dalanicolai> out vc, which is what I am doing now)
>
> The commit message is part of the patch. This is git, you
> should not skimp on committing locally :-) (you can always run 'git
> commit --amend' if you need to make more changes to the same patch)
>
> You then generate the patch using 'git format-patch HEAD~' or the
> equivalent magit command.
>
> Since youʼre using magit, you can start your commit, then run
> `magit-generate-changelog', which will insert a skeleton ChangeLog
> formatted entry based on the diffs of the files that youʼre
> committing. You then just need to write a one-line summary of the
> change, and describe the changes in the individual files.
>
> Robert
> --
>

[-- Attachment #2: Type: text/html, Size: 1853 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:59   ` dalanicolai
@ 2022-01-11 10:13     ` dalanicolai
  2022-01-11 14:39     ` Stefan Monnier
  1 sibling, 0 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-11 10:13 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 10155 bytes --]

Forgot to provide the link to the (info about the) pymupdf server, in case
someone is interested...

https://github.com/vedang/pdf-tools/pull/61

On Tue, 11 Jan 2022 at 10:59, dalanicolai <dalanicolai@gmail.com> wrote:

> >  (define-obsolete-variable-alias 'doc-view-unoconv-program
>>
> > -                                'doc-view-odf->pdf-converter-program
>> > -                                "24.4")
>> > +  'doc-view-odf->pdf-converter-program
>> > +  "24.4")
>>
>> Thanks.  At this point, the last two args can be placed on the same
>> line ;-)
>
>
> This is also due to the auto-indent, but I will correct it manually.
>
> >  (defun doc-view-new-window-function (winprops)
>> > +  ;; TODO: write documentation!
>> >    ;; (message "New window %s for buf %s" (car winprops)
>> (current-buffer))
>> >    (cl-assert (or (eq t (car winprops))
>> >                   (eq (window-buffer (car winprops)) (current-buffer))))
>>
>> I plead guilty, but if you give me a more specific question, I'll find
>> it easier to answer it (even in the form of a docstring or comment).
>>
>
> This I copied from pdf-tools. However, I am planning to enter this
> documentation
> myself, while I am implementing real continuous scroll. I have got that
> working in
> pdf-tools already, but I had to disable all kinds of minor modes there. So
> I thought
> let's start with a simpler task of implementing it in doc-view, however,
> the same
> difficulty, that I encountered also in pdf-tools is that somehow
> `bookroll-mode-winprops-alist` (which is exactly the equivalent/copy of
> `bookroll-mode-winprops-alist`) obtains a value `t`. I think I've spent
> some hours
> already investigating where it obtains it (somehow I fixed it after
> debugging for
> pdf-tools for few hours, but clearly I do not understand how, and have to
> repeat the
> same things again, well I guess it is a good exercise. Anyway, in the end
> I hope to
> add some useful documentation to prevent other hackers from 'wasting'
> their time :)
> Anyway, if I can keep it like this for now, that would be great, as the
> TODO really
> jumps out font lock wise, and also I can search for it.
>
> > @@ -738,7 +740,7 @@ doc-view-kill-proc
>> >    (interactive)
>> >    (while (consp doc-view--current-converter-processes)
>> >      (ignore-errors ;; Some entries might not be processes, and maybe
>> > -                ;; some are dead already?
>> > +      ;; some are dead already?
>> >        (kill-process (pop doc-view--current-converter-processes))))
>> >    (when doc-view--current-timer
>> >      (cancel-timer doc-view--current-timer)
>>
>> Here the auto-indentation gets it wrong, sadly.
>>
>
> You mean because it aligns with the line below so that it looks like it
> belongs
> to that one? Because otherwise, I think it does not look bad.
>
> > +     ((memq type '(postscript ps eps pdf epub))
>> > +         (if-let (command (and (memq type '(pdf epub))
>> (executable-find "mutool")))
>> > +             command
>> > +        (unless (eq type 'epub)
>> > +             (and doc-view-ghostscript-program
>> > +               (executable-find doc-view-ghostscript-program)))))
>> >       ((eq type 'odf)
>> >        (and doc-view-odf->pdf-converter-program
>> >             (executable-find doc-view-odf->pdf-converter-program)
>>
>> Hmm... for PDF files, this changes the previous behavior where we
>> checked for the presence of `doc-view-pdfdraw-program` rather than
>> "mutool".
>> Was there a strong reason to hardcode "mutool" here
>>
>
> Ah yes, I was aware of that, but indeed I did that consciously. I have
> very good experiences
> with (py)mupdf (I have implemented an alternative pdf-tools server using
> it, and indeed it is
> much faster than the epdfinfo server, well at least the mupdf vs poppler
> parts.
>
> really take a very quick look at the two histograms in this link
> <https://hub.alfresco.com/t5/alfresco-content-services-blog/pdf-rendering-engine-performance-and-fidelity-comparison/ba-p/287618>
> .
> So I decided this behavior really wouldn't be a problem, why not prefer
> mutool when it is
> available?
>
> Also, I think the rest of the code will still launch
>> `doc-view-pdfdraw-program` rather than `mutool`, so there's
>> something fishy.
>>
>
> That I do not understand immediately, for me the behavior is still
> somewhat opaque. But I
> will be trying to understand things further today (anyway for implementing
> the continuous scroll)
> and try to understand how it all works (and correct it here).
>
> This error message needs to be shorter.  It probably shouldn't talk
>> about `mutool`.  Even with this simplification I think we're going to
>> have to be creative to make it short enough to fit in a single line of
>> 80 columns.  We should probably just say something like
>>
>>     doc-view-pdf->png-converter-function invalid for EPub
>>
>> and then add in the docstring of `doc-view-pdf->png-converter-function`
>> a note about the fact that only `doc-view-pdf->png-converter-mupdf`
>> supports EPub.
>>
>
> That sounds good indeed. I will take care of that.
>
> Thanks, for the feedback... I will try another 'round' probably sooner
> than later :)
>
>
>
>
>
> On Tue, 11 Jan 2022 at 03:48, Stefan Monnier <monnier@iro.umontreal.ca>
> wrote:
>
>> > Here is a patch to add epub support to doc-view, via the mutool
>> > command of the mupdf library,I guess the patch needs no further
>> > explanation.  I've read the info about sending patches, however,
>> > I don't understand the section about the changelog (it mentions that
>> > there is a changelog or something, but it doesn't say where). Also,
>> > the info tells us to write the commit log entries, but it does not say
>> > where to do this.Looking at the changelog files, I guess that info is
>> > just really outdated (am I right?).  Anyway, the patch is in the
>> > attachment.  If there is some part of the 'protocol' that I did not
>> > understand then please inform me about it.
>>
>> Looks pretty good, see below for some comments/questions.
>> Regarding the changelog, we just need you to give us something like
>>
>>     doc-view.el: Add support for EPub
>>
>>     <Some explanation for the general idea>
>>
>>     * lisp/doc-view.el (<fun1>): <Do this>.
>>     (<var2>): <Do that>.
>>     ...
>>
>>     * lisp/files.el (auto-mode-alist): Extend doc-view-mode-maybe
>>     regexp to match `.epub` files.
>>
>> >  (define-obsolete-variable-alias 'doc-view-unoconv-program
>> > -                                'doc-view-odf->pdf-converter-program
>> > -                                "24.4")
>> > +  'doc-view-odf->pdf-converter-program
>> > +  "24.4")
>>
>>
>> Thanks.  At this point, the last two args can be placed on the same
>> line ;-)
>>
>> >  (defun doc-view-new-window-function (winprops)
>> > +  ;; TODO: write documentation!
>> >    ;; (message "New window %s for buf %s" (car winprops)
>> (current-buffer))
>> >    (cl-assert (or (eq t (car winprops))
>> >                   (eq (window-buffer (car winprops)) (current-buffer))))
>>
>> I plead guilty, but if you give me a more specific question, I'll find
>> it easier to answer it (even in the form of a docstring or comment).
>>
>> > @@ -738,7 +740,7 @@ doc-view-kill-proc
>> >    (interactive)
>> >    (while (consp doc-view--current-converter-processes)
>> >      (ignore-errors ;; Some entries might not be processes, and maybe
>> > -                ;; some are dead already?
>> > +      ;; some are dead already?
>> >        (kill-process (pop doc-view--current-converter-processes))))
>> >    (when doc-view--current-timer
>> >      (cancel-timer doc-view--current-timer)
>>
>> Here the auto-indentation gets it wrong, sadly.
>>
>> > @@ -810,11 +812,12 @@ doc-view-mode-p
>> >                      (executable-find doc-view-dvipdf-program))
>> >                 (and doc-view-dvipdfm-program
>> >                      (executable-find doc-view-dvipdfm-program)))))
>> > -     ((memq type '(postscript ps eps pdf))
>> > -      (or (and doc-view-ghostscript-program
>> > -               (executable-find doc-view-ghostscript-program))
>> > -             (and doc-view-pdfdraw-program
>> > -                  (executable-find doc-view-pdfdraw-program))))
>> > +     ((memq type '(postscript ps eps pdf epub))
>> > +         (if-let (command (and (memq type '(pdf epub))
>> (executable-find "mutool")))
>> > +             command
>> > +        (unless (eq type 'epub)
>> > +             (and doc-view-ghostscript-program
>> > +               (executable-find doc-view-ghostscript-program)))))
>> >       ((eq type 'odf)
>> >        (and doc-view-odf->pdf-converter-program
>> >             (executable-find doc-view-odf->pdf-converter-program)
>>
>> Hmm... for PDF files, this changes the previous behavior where we
>> checked for the presence of `doc-view-pdfdraw-program` rather than
>> "mutool".
>> Was there a strong reason to hardcode "mutool" here?
>>
>> Depending on the reason, we may be better off splitting the epub
>> handling into its own `cond` branch.
>>
>> Also, I think the rest of the code will still launch
>> `doc-view-pdfdraw-program` rather than `mutool`, so there's
>> something fishy.
>>
>> > -      ((or 'pdf 'djvu)
>> > +      ((or 'pdf 'epub 'djvu)
>> > +       (when (eq doc-view-doc-type 'epub)
>> > +         (unless (eq doc-view-pdf->png-converter-function
>> 'doc-view-pdf->png-converter-mupdf)
>> > +           (user-error "Viewing epub documents requires the`mutool'
>> command to be available,
>> > +and `doc-view-pdf->png-converter-function' variable set to
>> > +`doc-view-pdf->png-converter-mupdf'")))
>>
>> This error message needs to be shorter.  It probably shouldn't talk
>> about `mutool`.  Even with this simplification I think we're going to
>> have to be creative to make it short enough to fit in a single line of
>> 80 columns.  We should probably just say something like
>>
>>     doc-view-pdf->png-converter-function invalid for EPub
>>
>> and then add in the docstring of `doc-view-pdf->png-converter-function`
>> a note about the fact that only `doc-view-pdf->png-converter-mupdf`
>> supports EPub.
>>
>> The rest looks good.
>>
>>
>>         Stefan
>>
>>

[-- Attachment #2: Type: text/html, Size: 13569 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11 10:04       ` dalanicolai
  2022-01-11 10:08         ` dalanicolai
@ 2022-01-11 10:15         ` Robert Pluim
  1 sibling, 0 replies; 26+ messages in thread
From: Robert Pluim @ 2022-01-11 10:15 UTC (permalink / raw)
  To: dalanicolai; +Cc: Po Lu, Emacs Devel, Tassilo Horn

>>>>> On Tue, 11 Jan 2022 11:04:54 +0100, dalanicolai <dalanicolai@gmail.com> said:

    dalanicolai> Thanks, yeah I tried that, but it does not seem to work. I am selecting the
    dalanicolai> commit first,
    dalanicolai> but the command does not 'fill in' the range and does not create a patch
    dalanicolai> (to me it looks like
    dalanicolai> a bug, but probably I am doing something wrong)

With magit, it should be enough to do 'W c c HEAD RET' (it doesnʼt
matter where you are in the status buffer).

Robert
-- 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11 10:01     ` dalanicolai
@ 2022-01-11 10:16       ` Robert Pluim
  2022-01-13  9:14         ` dalanicolai
  0 siblings, 1 reply; 26+ messages in thread
From: Robert Pluim @ 2022-01-11 10:16 UTC (permalink / raw)
  To: dalanicolai; +Cc: Emacs Devel, Stefan Kangas, Stefan Monnier

>>>>> On Tue, 11 Jan 2022 11:01:35 +0100, dalanicolai <dalanicolai@gmail.com> said:

    dalanicolai> Haha, okay. It is still not clear to me where. But I guess that will become
    dalanicolai> clear then.

From the file where youʼve made changes. But
`magit-generate-changelog' is more convenient.

Robert
-- 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11  9:59   ` dalanicolai
  2022-01-11 10:13     ` dalanicolai
@ 2022-01-11 14:39     ` Stefan Monnier
  2022-01-13  9:25       ` dalanicolai
  1 sibling, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2022-01-11 14:39 UTC (permalink / raw)
  To: dalanicolai; +Cc: Emacs Devel

> This I copied from pdf-tools. However, I am planning to enter this
> documentation myself, while I am implementing real continuous
> scroll. I have got that working in pdf-tools already, but I had to
> disable all kinds of minor modes there. So I thought let's start with
> a simpler task of implementing it in doc-view, however, the same
> difficulty, that I encountered also in pdf-tools is that somehow
> `bookroll-mode-winprops-alist` (which is exactly the equivalent/copy
> of `bookroll-mode-winprops-alist`) obtains a value `t`. I think I've
> spent some hours already investigating where it obtains it (somehow
> I fixed it after debugging for pdf-tools for few hours, but clearly
> I do not understand how, and have to repeat the same things again,
> well I guess it is a good exercise. Anyway, in the end I hope to add
> some useful documentation to prevent other hackers from 'wasting'
> their time :) Anyway, if I can keep it like this for now, that would
> be great, as the TODO really jumps out font lock wise, and also I can
> search for it.

I've wrestled with this function a fair bit.  It was quite some years
ago, so it would take time for me to remember all the details, don't
hesitate to send me email along the way for help.

I'm not sure what you mean by "obtains a value t" but if you mean that
(car winprops) is t, then usually it happens when the buffer is not yet
displayed (`find-file` creates the buffer, enables the mode, and then
displays the buffer, so there's a time-window during which the buffer
is not displayed).

>> @@ -738,7 +740,7 @@ doc-view-kill-proc
>> >    (interactive)
>> >    (while (consp doc-view--current-converter-processes)
>> >      (ignore-errors ;; Some entries might not be processes, and maybe
>> > -                ;; some are dead already?
>> > +      ;; some are dead already?
>> >        (kill-process (pop doc-view--current-converter-processes))))
>> >    (when doc-view--current-timer
>> >      (cancel-timer doc-view--current-timer)
>>
>> Here the auto-indentation gets it wrong, sadly.
>
> You mean because it aligns with the line below so that it looks like
> it belongs to that one?

Yes, that indentation suggests that the second comment is separate from
the first rather than being its continuation.

I think we can get out cake and eat it by replacing the ";;" with ";" here.

> Because otherwise, I think it does not look bad.

It's not the end of the world, no.

>> +     ((memq type '(postscript ps eps pdf epub))
>> > +         (if-let (command (and (memq type '(pdf epub)) (executable-find
>> "mutool")))
>> > +             command
>> > +        (unless (eq type 'epub)
>> > +             (and doc-view-ghostscript-program
>> > +               (executable-find doc-view-ghostscript-program)))))
>> >       ((eq type 'odf)
>> >        (and doc-view-odf->pdf-converter-program
>> >             (executable-find doc-view-odf->pdf-converter-program)
>>
>> Hmm... for PDF files, this changes the previous behavior where we
>> checked for the presence of `doc-view-pdfdraw-program` rather than
>> "mutool".
>> Was there a strong reason to hardcode "mutool" here
>>
>
> Ah yes, I was aware of that, but indeed I did that consciously. I have
> very good experiences with (py)mupdf (I have implemented an
> alternative pdf-tools server using it, and indeed it is much faster
> than the epdfinfo server, well at least the mupdf vs poppler parts.

Not sure I understand.  My comment is about hardcoding "mutool" vs
obeying `doc-view-pdfdraw-program` which can refer to "mutool",
"mudraw", "pdfdraw", or any other file name (e.g. in case it's not in
$PATH).  AFAIK they all end up running the same code.


        Stefan




^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11 10:16       ` Robert Pluim
@ 2022-01-13  9:14         ` dalanicolai
  0 siblings, 0 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-13  9:14 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Emacs Devel, Stefan Kangas, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

>
> With magit, it should be enough to do 'W c c HEAD RET' (it doesnʼt
> matter where you are in the status buffer).
>

Thanks for the 'golden tip'!

From the file where youʼve made changes. But
> `magit-generate-changelog' is more convenient.
>

Great, I will check this out also...


On Tue, 11 Jan 2022 at 11:16, Robert Pluim <rpluim@gmail.com> wrote:

> >>>>> On Tue, 11 Jan 2022 11:01:35 +0100, dalanicolai <
> dalanicolai@gmail.com> said:
>
>     dalanicolai> Haha, okay. It is still not clear to me where. But I
> guess that will become
>     dalanicolai> clear then.
>
> From the file where youʼve made changes. But
> `magit-generate-changelog' is more convenient.
>
> Robert
> --
>

[-- Attachment #2: Type: text/html, Size: 1503 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-11 14:39     ` Stefan Monnier
@ 2022-01-13  9:25       ` dalanicolai
  2022-01-14 16:15         ` dalanicolai
  0 siblings, 1 reply; 26+ messages in thread
From: dalanicolai @ 2022-01-13  9:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 4992 bytes --]

>
> don't hesitate to send me email along the way for help
>

Thanks, will do that (i.e. not the hesitate :)


> I'm not sure what you mean by "obtains a value t" but if you mean that
> (car winprops) is t, then usually it happens when the buffer is not yet
> displayed (`find-file` creates the buffer, enables the mode, and then
> displays the buffer, so there's a time-window during which the buffer
> is not displayed).


Thanks, I've read about that value being 't' in one of the docstring.
However,
the motivation for it is better explained in your answer here I think (If I
remember
well, I will 'check' it when I see it again)

Not sure I understand.  My comment is about hardcoding "mutool" vs
> obeying `doc-view-pdfdraw-program` which can refer to "mutool",
> "mudraw", "pdfdraw", or any other file name (e.g. in case it's not in
> $PATH).  AFAIK they all end up running the same code.
>

Ah okay, I see now. I took note of the feedback, however I will first focus
on the continuous scroll now, and then later come back to this patch.

Thanks again, you all!



On Tue, 11 Jan 2022 at 15:39, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > This I copied from pdf-tools. However, I am planning to enter this
> > documentation myself, while I am implementing real continuous
> > scroll. I have got that working in pdf-tools already, but I had to
> > disable all kinds of minor modes there. So I thought let's start with
> > a simpler task of implementing it in doc-view, however, the same
> > difficulty, that I encountered also in pdf-tools is that somehow
> > `bookroll-mode-winprops-alist` (which is exactly the equivalent/copy
> > of `bookroll-mode-winprops-alist`) obtains a value `t`. I think I've
> > spent some hours already investigating where it obtains it (somehow
> > I fixed it after debugging for pdf-tools for few hours, but clearly
> > I do not understand how, and have to repeat the same things again,
> > well I guess it is a good exercise. Anyway, in the end I hope to add
> > some useful documentation to prevent other hackers from 'wasting'
> > their time :) Anyway, if I can keep it like this for now, that would
> > be great, as the TODO really jumps out font lock wise, and also I can
> > search for it.
>
> I've wrestled with this function a fair bit.  It was quite some years
> ago, so it would take time for me to remember all the details, don't
> hesitate to send me email along the way for help.
>
> I'm not sure what you mean by "obtains a value t" but if you mean that
> (car winprops) is t, then usually it happens when the buffer is not yet
> displayed (`find-file` creates the buffer, enables the mode, and then
> displays the buffer, so there's a time-window during which the buffer
> is not displayed).
>
> >> @@ -738,7 +740,7 @@ doc-view-kill-proc
> >> >    (interactive)
> >> >    (while (consp doc-view--current-converter-processes)
> >> >      (ignore-errors ;; Some entries might not be processes, and maybe
> >> > -                ;; some are dead already?
> >> > +      ;; some are dead already?
> >> >        (kill-process (pop doc-view--current-converter-processes))))
> >> >    (when doc-view--current-timer
> >> >      (cancel-timer doc-view--current-timer)
> >>
> >> Here the auto-indentation gets it wrong, sadly.
> >
> > You mean because it aligns with the line below so that it looks like
> > it belongs to that one?
>
> Yes, that indentation suggests that the second comment is separate from
> the first rather than being its continuation.
>
> I think we can get out cake and eat it by replacing the ";;" with ";" here.
>
> > Because otherwise, I think it does not look bad.
>
> It's not the end of the world, no.
>
> >> +     ((memq type '(postscript ps eps pdf epub))
> >> > +         (if-let (command (and (memq type '(pdf epub))
> (executable-find
> >> "mutool")))
> >> > +             command
> >> > +        (unless (eq type 'epub)
> >> > +             (and doc-view-ghostscript-program
> >> > +               (executable-find doc-view-ghostscript-program)))))
> >> >       ((eq type 'odf)
> >> >        (and doc-view-odf->pdf-converter-program
> >> >             (executable-find doc-view-odf->pdf-converter-program)
> >>
> >> Hmm... for PDF files, this changes the previous behavior where we
> >> checked for the presence of `doc-view-pdfdraw-program` rather than
> >> "mutool".
> >> Was there a strong reason to hardcode "mutool" here
> >>
> >
> > Ah yes, I was aware of that, but indeed I did that consciously. I have
> > very good experiences with (py)mupdf (I have implemented an
> > alternative pdf-tools server using it, and indeed it is much faster
> > than the epdfinfo server, well at least the mupdf vs poppler parts.
>
> Not sure I understand.  My comment is about hardcoding "mutool" vs
> obeying `doc-view-pdfdraw-program` which can refer to "mutool",
> "mudraw", "pdfdraw", or any other file name (e.g. in case it's not in
> $PATH).  AFAIK they all end up running the same code.
>
>
>         Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 6802 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-13  9:25       ` dalanicolai
@ 2022-01-14 16:15         ` dalanicolai
  2022-01-14 20:02           ` dalanicolai
  0 siblings, 1 reply; 26+ messages in thread
From: dalanicolai @ 2022-01-14 16:15 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel


[-- Attachment #1.1: Type: text/plain, Size: 639 bytes --]

So here is a second version of the patch. But it adds a few more extensions
to the list
I forgot about them, as I don't use or experimented with them, but I
figured that
this is a good opportunity to add the support for those extensions also.
A small comment for those who are interested, the CBZ (and by mupdf
unsupported CBR)
files seem to be just zipped/rarred collections of image files (I guess
usually png/jpg). So
supporting those extensions doesn't really require the `mutool` command if
emacs would
just uncompress the collections.

I guess there is not much more to comment on in addition to the comments
within the patch/files.

[-- Attachment #1.2: Type: text/html, Size: 789 bytes --]

[-- Attachment #2: 0001-Add-support-for-EPUB-CBZ-FB2-and-O-XPS-extension-to-.patch --]
[-- Type: text/x-patch, Size: 15578 bytes --]

From 9bd57c7a942cbe2ebcfdfb12600cabc9354d1ba6 Mon Sep 17 00:00:00 2001
From: Daniel Nicolai <dalanicolai@gmail.com>
Date: Tue, 11 Jan 2022 20:37:36 +0100
Subject: [PATCH] Add support for EPUB, CBZ, FB2 and (O)XPS extension to doc
 view

* doc/emacs/misc.texi (Document View):
Add requirements for new extensions (i.e. mutool)

* lisp/doc-view.el (doc-view): Additionally update preliminary comment
(doc-view-unoconv-program): Put code all on one line
(doc-view-doc-type): Update docstring.
(doc-view-kill-proc): Fix comment indentation
(doc-view-mode-p):
Add check for new extensions and alternative check for PDF
(doc-view-pdf/ps->png): Associate new extension with png converter
(doc-view-convert-current-doc): Handle new extensions like PDF's
(doc-view-set-doc-type): Set correct doc-type for new extensions.

* lisp/files.el (auto-mode-alist):
Associate new extension types with doc-view
---
 doc/emacs/misc.texi |  23 +++++---
 lisp/doc-view.el    | 126 ++++++++++++++++++++++++++------------------
 lisp/files.el       |   2 +-
 3 files changed, 92 insertions(+), 59 deletions(-)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index df1e5ef238..365c079e89 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -455,20 +455,27 @@ Document View
 @cindex PostScript file
 @cindex OpenDocument file
 @cindex Microsoft Office file
+@cindex EPUB file
+@cindex CBZ file
+@cindex FB2 file
+@cindex XPS file
+@cindex OXPS file
 @cindex DocView mode
 @cindex mode, DocView
 @cindex document viewer (DocView)
 @findex doc-view-mode
 
   DocView mode is a major mode for viewing DVI, PostScript (PS), PDF,
-OpenDocument, and Microsoft Office documents.  It provides features
-such as slicing, zooming, and searching inside documents.  It works by
-converting the document to a set of images using the @command{gs}
-(GhostScript) or @command{mudraw}/@command{pdfdraw} (MuPDF) commands
-and other external tools @footnote{For PostScript files, GhostScript
-is a hard requirement.  For DVI files, @code{dvipdf} or @code{dvipdfm}
-is needed.  For OpenDocument and Microsoft Office documents, the
-@code{unoconv} tool is needed.}, and displaying those images.
+OpenDocument, Microsoft Office, EPUB, CBZ, FB2, XPS and OXPS
+documents.  It provides features such as slicing, zooming, and
+searching inside documents.  It works by converting the document to a
+set of images using the @command{gs} (GhostScript) or
+@command{pdfdraw}/@command{mutool draw} (MuPDF) commands and other
+external tools @footnote{PostScript files require GhostScript, DVI
+files require @code{dvipdf} or @code{dvipdfm}, OpenDocument and
+Microsoft Office documents require the @code{unoconv} tool, and EPUB,
+CBZ, FB2, XPS and OXPS files require @code{mutool} to be available.},
+and displaying those images.
 
 @findex doc-view-toggle-display
 @findex doc-view-minor-mode
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 5b462b24f5..d13480310c 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
 ;;
 ;; Author: Tassilo Horn <tsdh@gnu.org>
-;; Keywords: files, pdf, ps, dvi
+;; Keywords: files, pdf, ps, dvi, djvu, epub, cbz, fb2, xps, openxps
 
 ;; This file is part of GNU Emacs.
 
@@ -25,17 +25,19 @@
 ;; Viewing PS/PDF/DVI files requires Ghostscript, `dvipdf' (comes with
 ;; Ghostscript) or `dvipdfm' (comes with teTeX or TeXLive) and
 ;; `pdftotext', which comes with xpdf (https://www.foolabs.com/xpdf/)
-;; or poppler (https://poppler.freedesktop.org/).
-;; Djvu documents require `ddjvu' (from DjVuLibre).
-;; ODF files require `soffice' (from LibreOffice).
+;; or poppler (https://poppler.freedesktop.org/). EPUB, CBZ, FB2, XPS
+;; and OXPS documents require `mutool' which comes with mupdf
+;; (https://mupdf.com/index.html). Djvu documents require `ddjvu'
+;; (from DjVuLibre).  ODF files require `soffice' (from LibreOffice).
 
 ;;; Commentary:
 
 ;; DocView is a document viewer for Emacs.  It converts a number of
-;; document formats (including PDF, PS, DVI, Djvu and ODF files) to a
-;; set of PNG files, one PNG for each page, and displays the PNG
-;; images inside an Emacs buffer.  This buffer uses `doc-view-mode'
-;; which provides convenient key bindings for browsing the document.
+;; document formats (including PDF, PS, DVI, Djvu, ODF, EPUB, CBZ,
+;; FB2, XPS and OXPS files) to a set of PNG (or TIFF for djvu) files,
+;; one image for each page, and displays the images inside an Emacs
+;; buffer.  This buffer uses `doc-view-mode' which provides convenient
+;; key bindings for browsing the document.
 ;;
 ;; To use it simply open a document file with
 ;;
@@ -147,7 +149,10 @@
 ;;;; Customization Options
 
 (defgroup doc-view nil
-  "In-buffer viewer for PDF, PostScript, DVI, and DJVU files."
+  "In-buffer document viewer.
+The viewer handles PDF, PostScript, DVI, DJVU, ODF, EPUB, CBZ,
+FB2, XPS and OXPS files, if the appropriate converter programs
+are available (see Info node `(emacs)Document View')"
   :link '(function-link doc-view)
   :version "22.2"
   :group 'applications
@@ -256,9 +261,7 @@ doc-view-dvipdf-program
 `doc-view-dvipdf-program' will be preferred."
   :type 'file)
 
-(define-obsolete-variable-alias 'doc-view-unoconv-program
-                                'doc-view-odf->pdf-converter-program
-                                "24.4")
+(define-obsolete-variable-alias 'doc-view-unoconv-program 'doc-view-odf->pdf-converter-program "24.4")
 
 (defcustom doc-view-odf->pdf-converter-program
   (cond
@@ -382,7 +385,8 @@ doc-view--buffer-file-name
 
 (defvar doc-view-doc-type nil
   "The type of document in the current buffer.
-Can be `dvi', `pdf', `ps', `djvu' or `odf'.")
+Can be `dvi', `pdf', `ps', `djvu', `odf', 'epub', `cbz', `fb2',
+`'xps' or `oxps'.")
 
 (defvar doc-view-single-page-converter-function nil
   "Function to call to convert a single page of the document to a bitmap file.
@@ -464,17 +468,17 @@ doc-view--revert-buffer
       ;; It's normal for this operation to result in a very large undo entry.
       (setq-local undo-outer-limit (* 2 (buffer-size))))
   (cl-labels ((revert ()
-                      (let ((revert-buffer-preserve-modes t))
-                        (apply orig-fun args)
-                        ;; Update the cached version of the pdf file,
-                        ;; too.  This is the one that's used when
-                        ;; rendering (bug#26996).
-                        (unless (equal buffer-file-name
-                                       doc-view--buffer-file-name)
-                          ;; FIXME: Lars says he needed to recreate
-                          ;; the dir, we should figure out why.
-                          (doc-view-make-safe-dir doc-view-cache-directory)
-                          (write-region nil nil doc-view--buffer-file-name)))))
+                (let ((revert-buffer-preserve-modes t))
+                  (apply orig-fun args)
+                  ;; Update the cached version of the pdf file,
+                  ;; too.  This is the one that's used when
+                  ;; rendering (bug#26996).
+                  (unless (equal buffer-file-name
+                                 doc-view--buffer-file-name)
+                    ;; FIXME: Lars says he needed to recreate
+                    ;; the dir, we should figure out why.
+                    (doc-view-make-safe-dir doc-view-cache-directory)
+                    (write-region nil nil doc-view--buffer-file-name)))))
     (if (and (eq 'pdf doc-view-doc-type)
              (executable-find "pdfinfo"))
         ;; We don't want to revert if the PDF file is corrupted which
@@ -738,7 +742,7 @@ doc-view-kill-proc
   (interactive)
   (while (consp doc-view--current-converter-processes)
     (ignore-errors ;; Some entries might not be processes, and maybe
-		   ;; some are dead already?
+                    ; some are dead already?
       (kill-process (pop doc-view--current-converter-processes))))
   (when doc-view--current-timer
     (cancel-timer doc-view--current-timer)
@@ -799,8 +803,8 @@ doc-view--current-cache-dir
 ;;;###autoload
 (defun doc-view-mode-p (type)
   "Return non-nil if document type TYPE is available for `doc-view'.
-Document types are symbols like `dvi', `ps', `pdf', or `odf' (any
-OpenDocument format)."
+Document types are symbols like `dvi', `ps', `pdf', `epub',
+`cbz', `fb2', `xps', `oxps', or`odf' (any OpenDocument format)."
   (and (display-graphic-p)
        (image-type-available-p 'png)
        (cond
@@ -811,16 +815,22 @@ doc-view-mode-p
 		  (and doc-view-dvipdfm-program
 		       (executable-find doc-view-dvipdfm-program)))))
 	((memq type '(postscript ps eps pdf))
-	 (or (and doc-view-ghostscript-program
+         (or (and doc-view-ghostscript-program
 	          (executable-find doc-view-ghostscript-program))
-             (and doc-view-pdfdraw-program
-                  (executable-find doc-view-pdfdraw-program))))
+             ;; for pdf also check for `doc-view-pdfdraw-program'
+             (when (eq type 'pdf)
+               (and doc-view-pdfdraw-program
+                    (executable-find doc-view-pdfdraw-program)))))
 	((eq type 'odf)
 	 (and doc-view-odf->pdf-converter-program
 	      (executable-find doc-view-odf->pdf-converter-program)
 	      (doc-view-mode-p 'pdf)))
 	((eq type 'djvu)
 	 (executable-find "ddjvu"))
+        ((memq type '(epub cbz fb2 xps oxps))
+         ;; first check if `doc-view-pdfdraw-program' is set to mutool
+         (and (string= doc-view-pdfdraw-program "mutool")
+              (executable-find "mutool")))
 	(t ;; unknown image type
 	 nil))))
 
@@ -1053,7 +1063,7 @@ doc-view-start-process
   ;; some file-name-handler-managed dir, for example).
   (let* ((default-directory (or (unhandled-file-name-directory
                                  default-directory)
-			      (expand-file-name "~/")))
+			        (expand-file-name "~/")))
          (proc (apply #'start-process name doc-view-conversion-buffer
                       program args)))
     (push proc doc-view--current-converter-processes)
@@ -1189,7 +1199,7 @@ doc-view-pdf/ps->png
   "Convert PDF-PS to PNG asynchronously."
   (funcall
    (pcase doc-view-doc-type
-     ('pdf doc-view-pdf->png-converter-function)
+     ((or 'pdf 'epub 'cbz 'fb2 'xps 'oxps) doc-view-pdf->png-converter-function)
      ('djvu #'doc-view-djvu->tiff-converter-ddjvu)
      (_ #'doc-view-ps->png-converter-ghostscript))
    pdf-ps png nil
@@ -1227,20 +1237,20 @@ doc-view-document->bitmap
     (let ((rest (cdr pages)))
       (funcall doc-view-single-page-converter-function
 	       pdf (format png (car pages)) (car pages)
-       (lambda ()
-         (if rest
-             (doc-view-document->bitmap pdf png rest)
-           ;; Yippie, the important pages are done, update the display.
-           (clear-image-cache)
-           ;; For the windows that have a message (like "Welcome to
-           ;; DocView") display property, clearing the image cache is
-           ;; not sufficient.
-           (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
-             (with-selected-window win
-	       (when (stringp (overlay-get (doc-view-current-overlay) 'display))
-		 (doc-view-goto-page (doc-view-current-page)))))
-           ;; Convert the rest of the pages.
-           (doc-view-pdf/ps->png pdf png)))))))
+               (lambda ()
+                 (if rest
+                     (doc-view-document->bitmap pdf png rest)
+                   ;; Yippie, the important pages are done, update the display.
+                   (clear-image-cache)
+                   ;; For the windows that have a message (like "Welcome to
+                   ;; DocView") display property, clearing the image cache is
+                   ;; not sufficient.
+                   (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
+                     (with-selected-window win
+	               (when (stringp (overlay-get (doc-view-current-overlay) 'display))
+		         (doc-view-goto-page (doc-view-current-page)))))
+                   ;; Convert the rest of the pages.
+                   (doc-view-pdf/ps->png pdf png)))))))
 
 (defun doc-view-pdf->txt (pdf txt callback)
   "Convert PDF to TXT asynchronously and call CALLBACK when finished."
@@ -1337,7 +1347,9 @@ doc-view-convert-current-doc
 		    ;; Rename to doc.pdf
 		    (rename-file opdf pdf)
 		    (doc-view-pdf/ps->png pdf png-file)))))
-      ((or 'pdf 'djvu)
+      ;; The doc-view-mode-p check ensures that epub, cbz, fb2 and
+      ;; (o)xps are handled with mutool
+      ((or 'pdf 'djvu 'epub 'cbz 'fb2 'xps 'oxps)
        (let ((pages (doc-view-active-pages)))
          ;; Convert doc to bitmap images starting with the active pages.
          (doc-view-document->bitmap doc-view--buffer-file-name png-file pages)))
@@ -1432,7 +1444,7 @@ doc-view-paper-sizes
 (defun doc-view-guess-paper-size (iw ih)
   "Guess the paper size according to the aspect ratio."
   (cl-labels ((div (x y)
-		   (round (/ (* 100.0 x) y))))
+		(round (/ (* 100.0 x) y))))
     (let ((ar (div iw ih))
 	  (al (mapcar (lambda (l)
 			(list (div (nth 1 l) (nth 2 l)) (car l)))
@@ -1869,6 +1881,8 @@ doc-view-set-doc-type
                    ("dvi" dvi)
                    ;; PDF
                    ("pdf" pdf) ("epdf" pdf)
+                   ;; EPUB
+                   ("epub" epub)
                    ;; PostScript
                    ("ps" ps) ("eps" ps)
                    ;; DjVu
@@ -1880,7 +1894,13 @@ doc-view-set-doc-type
                    ;; Microsoft Office formats (also handled by the odf
                    ;; conversion chain).
                    ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
-                   ("ppt" odf) ("pps" odf) ("pptx" odf) ("rtf" odf))
+                   ("ppt" odf) ("pps" odf) ("pptx" odf) ("rtf" odf)
+                   ;; CBZ
+                   ("cbz" cbz)
+                   ;; FB2
+                   ("fb2" fb2)
+                   ;; (Open)XPS
+                   ("xps" xps) ("oxps" oxps))
 		 t))))
 	(content-types
 	 (save-excursion
@@ -1889,7 +1909,13 @@ doc-view-set-doc-type
 	    ((looking-at "%!") '(ps))
 	    ((looking-at "%PDF") '(pdf))
 	    ((looking-at "\367\002") '(dvi))
-	    ((looking-at "AT&TFORM") '(djvu))))))
+	    ((looking-at "AT&TFORM") '(djvu))
+            ;; The following pattern actually is for recognizing
+            ;; zip-archives, so that this same association is used for
+            ;; cbz files. This is fine, as cbz files should be handled
+            ;; like epub anyway.
+            ((looking-at "PK") '(epub))
+            ))))
     (setq-local
      doc-view-doc-type
      (car (or (nreverse (seq-intersection name-types content-types #'eq))
diff --git a/lisp/files.el b/lisp/files.el
index a11786fca2..f2c656bfde 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2925,7 +2925,7 @@ auto-mode-alist
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MS-DOS
      ("\\.[eE]?[pP][sS]\\'" . ps-mode)
-     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
+     ("\\.\\(?:PDF\\|EPUB\\|CBZ\\|FB2\\|O?XPS\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|epub\\|cbz\\|fb2\\|o?xps\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-14 16:15         ` dalanicolai
@ 2022-01-14 20:02           ` dalanicolai
  2022-01-26 20:28             ` dalanicolai
  0 siblings, 1 reply; 26+ messages in thread
From: dalanicolai @ 2022-01-14 20:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel


[-- Attachment #1.1: Type: text/plain, Size: 829 bytes --]

And another, updated, patch, adding an extra option to configure the epub
font-size

On Fri, 14 Jan 2022 at 17:15, dalanicolai <dalanicolai@gmail.com> wrote:

> So here is a second version of the patch. But it adds a few more
> extensions to the list
> I forgot about them, as I don't use or experimented with them, but I
> figured that
> this is a good opportunity to add the support for those extensions also.
> A small comment for those who are interested, the CBZ (and by mupdf
> unsupported CBR)
> files seem to be just zipped/rarred collections of image files (I guess
> usually png/jpg). So
> supporting those extensions doesn't really require the `mutool` command if
> emacs would
> just uncompress the collections.
>
> I guess there is not much more to comment on in addition to the comments
> within the patch/files.
>

[-- Attachment #1.2: Type: text/html, Size: 1233 bytes --]

[-- Attachment #2: 0001-Add-support-for-EPUB-CBZ-FB2-and-O-XPS-extension-to-.patch --]
[-- Type: text/x-patch, Size: 17588 bytes --]

From 53913d3b2c667fa8fda1df671212a3c64a3b21a2 Mon Sep 17 00:00:00 2001
From: Daniel Nicolai <dalanicolai@gmail.com>
Date: Tue, 11 Jan 2022 20:37:36 +0100
Subject: [PATCH] Add support for EPUB, CBZ, FB2 and (O)XPS extension to doc
 view

* doc/emacs/misc.texi (Document View):
Add requirements for new extensions (i.e. mutool)

* lisp/doc-view.el (doc-view): Additionally update preliminary comment
(doc-view-custom-set-epub-font-size): redraw image after setting
(doc-view-unoconv-program): Put code all on one line
(doc-view-doc-type): Update docstring.
(doc-view-kill-proc): Fix comment indentation
(doc-view-mode-p):
Add check for new extensions and alternative check for PDF
(doc-view-pdf/ps->png): Associate new extension with png converter
(doc-view-convert-current-doc): Handle new extensions like PDF's
(doc-view-set-doc-type): Set correct doc-type for new extensions.

* lisp/files.el (auto-mode-alist):
Associate new extension types with doc-view
---
 doc/emacs/misc.texi |  23 ++++---
 lisp/doc-view.el    | 153 ++++++++++++++++++++++++++++----------------
 lisp/files.el       |   2 +-
 3 files changed, 114 insertions(+), 64 deletions(-)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index df1e5ef238..365c079e89 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -455,20 +455,27 @@ Document View
 @cindex PostScript file
 @cindex OpenDocument file
 @cindex Microsoft Office file
+@cindex EPUB file
+@cindex CBZ file
+@cindex FB2 file
+@cindex XPS file
+@cindex OXPS file
 @cindex DocView mode
 @cindex mode, DocView
 @cindex document viewer (DocView)
 @findex doc-view-mode
 
   DocView mode is a major mode for viewing DVI, PostScript (PS), PDF,
-OpenDocument, and Microsoft Office documents.  It provides features
-such as slicing, zooming, and searching inside documents.  It works by
-converting the document to a set of images using the @command{gs}
-(GhostScript) or @command{mudraw}/@command{pdfdraw} (MuPDF) commands
-and other external tools @footnote{For PostScript files, GhostScript
-is a hard requirement.  For DVI files, @code{dvipdf} or @code{dvipdfm}
-is needed.  For OpenDocument and Microsoft Office documents, the
-@code{unoconv} tool is needed.}, and displaying those images.
+OpenDocument, Microsoft Office, EPUB, CBZ, FB2, XPS and OXPS
+documents.  It provides features such as slicing, zooming, and
+searching inside documents.  It works by converting the document to a
+set of images using the @command{gs} (GhostScript) or
+@command{pdfdraw}/@command{mutool draw} (MuPDF) commands and other
+external tools @footnote{PostScript files require GhostScript, DVI
+files require @code{dvipdf} or @code{dvipdfm}, OpenDocument and
+Microsoft Office documents require the @code{unoconv} tool, and EPUB,
+CBZ, FB2, XPS and OXPS files require @code{mutool} to be available.},
+and displaying those images.
 
 @findex doc-view-toggle-display
 @findex doc-view-minor-mode
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 5b462b24f5..57144ece1c 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
 ;;
 ;; Author: Tassilo Horn <tsdh@gnu.org>
-;; Keywords: files, pdf, ps, dvi
+;; Keywords: files, pdf, ps, dvi, djvu, epub, cbz, fb2, xps, openxps
 
 ;; This file is part of GNU Emacs.
 
@@ -25,17 +25,19 @@
 ;; Viewing PS/PDF/DVI files requires Ghostscript, `dvipdf' (comes with
 ;; Ghostscript) or `dvipdfm' (comes with teTeX or TeXLive) and
 ;; `pdftotext', which comes with xpdf (https://www.foolabs.com/xpdf/)
-;; or poppler (https://poppler.freedesktop.org/).
-;; Djvu documents require `ddjvu' (from DjVuLibre).
-;; ODF files require `soffice' (from LibreOffice).
+;; or poppler (https://poppler.freedesktop.org/). EPUB, CBZ, FB2, XPS
+;; and OXPS documents require `mutool' which comes with mupdf
+;; (https://mupdf.com/index.html). Djvu documents require `ddjvu'
+;; (from DjVuLibre).  ODF files require `soffice' (from LibreOffice).
 
 ;;; Commentary:
 
 ;; DocView is a document viewer for Emacs.  It converts a number of
-;; document formats (including PDF, PS, DVI, Djvu and ODF files) to a
-;; set of PNG files, one PNG for each page, and displays the PNG
-;; images inside an Emacs buffer.  This buffer uses `doc-view-mode'
-;; which provides convenient key bindings for browsing the document.
+;; document formats (including PDF, PS, DVI, Djvu, ODF, EPUB, CBZ,
+;; FB2, XPS and OXPS files) to a set of PNG (or TIFF for djvu) files,
+;; one image for each page, and displays the images inside an Emacs
+;; buffer.  This buffer uses `doc-view-mode' which provides convenient
+;; key bindings for browsing the document.
 ;;
 ;; To use it simply open a document file with
 ;;
@@ -147,7 +149,10 @@
 ;;;; Customization Options
 
 (defgroup doc-view nil
-  "In-buffer viewer for PDF, PostScript, DVI, and DJVU files."
+  "In-buffer document viewer.
+The viewer handles PDF, PostScript, DVI, DJVU, ODF, EPUB, CBZ,
+FB2, XPS and OXPS files, if the appropriate converter programs
+are available (see Info node `(emacs)Document View')"
   :link '(function-link doc-view)
   :version "22.2"
   :group 'applications
@@ -221,6 +226,20 @@ doc-view-resolution
 Higher values result in larger images."
   :type 'number)
 
+(defun doc-view-custom-set-epub-font-size (option-name new-value)
+  (set-default option-name new-value)
+  (dolist (x (buffer-list))
+    (with-current-buffer x
+      (when (eq doc-view-doc-type 'epub)
+        (delete-directory doc-view--current-cache-dir t)
+        (doc-view-initiate-display)
+        (doc-view-goto-page (doc-view-current-page))))))
+
+(defcustom doc-view-epub-font-size nil
+  "Font size in points for EPUB layout."
+  :type 'integer
+  :set #'doc-view-custom-set-epub-font-size)
+
 (defcustom doc-view-scale-internally t
   "Whether we should try to rescale images ourselves.
 If nil, the document is re-rendered every time the scaling factor is modified.
@@ -256,9 +275,7 @@ doc-view-dvipdf-program
 `doc-view-dvipdf-program' will be preferred."
   :type 'file)
 
-(define-obsolete-variable-alias 'doc-view-unoconv-program
-                                'doc-view-odf->pdf-converter-program
-                                "24.4")
+(define-obsolete-variable-alias 'doc-view-unoconv-program 'doc-view-odf->pdf-converter-program "24.4")
 
 (defcustom doc-view-odf->pdf-converter-program
   (cond
@@ -382,7 +399,8 @@ doc-view--buffer-file-name
 
 (defvar doc-view-doc-type nil
   "The type of document in the current buffer.
-Can be `dvi', `pdf', `ps', `djvu' or `odf'.")
+Can be `dvi', `pdf', `ps', `djvu', `odf', 'epub', `cbz', `fb2',
+`'xps' or `oxps'.")
 
 (defvar doc-view-single-page-converter-function nil
   "Function to call to convert a single page of the document to a bitmap file.
@@ -464,17 +482,17 @@ doc-view--revert-buffer
       ;; It's normal for this operation to result in a very large undo entry.
       (setq-local undo-outer-limit (* 2 (buffer-size))))
   (cl-labels ((revert ()
-                      (let ((revert-buffer-preserve-modes t))
-                        (apply orig-fun args)
-                        ;; Update the cached version of the pdf file,
-                        ;; too.  This is the one that's used when
-                        ;; rendering (bug#26996).
-                        (unless (equal buffer-file-name
-                                       doc-view--buffer-file-name)
-                          ;; FIXME: Lars says he needed to recreate
-                          ;; the dir, we should figure out why.
-                          (doc-view-make-safe-dir doc-view-cache-directory)
-                          (write-region nil nil doc-view--buffer-file-name)))))
+                (let ((revert-buffer-preserve-modes t))
+                  (apply orig-fun args)
+                  ;; Update the cached version of the pdf file,
+                  ;; too.  This is the one that's used when
+                  ;; rendering (bug#26996).
+                  (unless (equal buffer-file-name
+                                 doc-view--buffer-file-name)
+                    ;; FIXME: Lars says he needed to recreate
+                    ;; the dir, we should figure out why.
+                    (doc-view-make-safe-dir doc-view-cache-directory)
+                    (write-region nil nil doc-view--buffer-file-name)))))
     (if (and (eq 'pdf doc-view-doc-type)
              (executable-find "pdfinfo"))
         ;; We don't want to revert if the PDF file is corrupted which
@@ -738,7 +756,7 @@ doc-view-kill-proc
   (interactive)
   (while (consp doc-view--current-converter-processes)
     (ignore-errors ;; Some entries might not be processes, and maybe
-		   ;; some are dead already?
+                    ; some are dead already?
       (kill-process (pop doc-view--current-converter-processes))))
   (when doc-view--current-timer
     (cancel-timer doc-view--current-timer)
@@ -799,8 +817,8 @@ doc-view--current-cache-dir
 ;;;###autoload
 (defun doc-view-mode-p (type)
   "Return non-nil if document type TYPE is available for `doc-view'.
-Document types are symbols like `dvi', `ps', `pdf', or `odf' (any
-OpenDocument format)."
+Document types are symbols like `dvi', `ps', `pdf', `epub',
+`cbz', `fb2', `xps', `oxps', or`odf' (any OpenDocument format)."
   (and (display-graphic-p)
        (image-type-available-p 'png)
        (cond
@@ -811,16 +829,22 @@ doc-view-mode-p
 		  (and doc-view-dvipdfm-program
 		       (executable-find doc-view-dvipdfm-program)))))
 	((memq type '(postscript ps eps pdf))
-	 (or (and doc-view-ghostscript-program
+         (or (and doc-view-ghostscript-program
 	          (executable-find doc-view-ghostscript-program))
-             (and doc-view-pdfdraw-program
-                  (executable-find doc-view-pdfdraw-program))))
+             ;; for pdf also check for `doc-view-pdfdraw-program'
+             (when (eq type 'pdf)
+               (and doc-view-pdfdraw-program
+                    (executable-find doc-view-pdfdraw-program)))))
 	((eq type 'odf)
 	 (and doc-view-odf->pdf-converter-program
 	      (executable-find doc-view-odf->pdf-converter-program)
 	      (doc-view-mode-p 'pdf)))
 	((eq type 'djvu)
 	 (executable-find "ddjvu"))
+        ((memq type '(epub cbz fb2 xps oxps))
+         ;; first check if `doc-view-pdfdraw-program' is set to mutool
+         (and (string= doc-view-pdfdraw-program "mutool")
+              (executable-find "mutool")))
 	(t ;; unknown image type
 	 nil))))
 
@@ -1053,7 +1077,7 @@ doc-view-start-process
   ;; some file-name-handler-managed dir, for example).
   (let* ((default-directory (or (unhandled-file-name-directory
                                  default-directory)
-			      (expand-file-name "~/")))
+			        (expand-file-name "~/")))
          (proc (apply #'start-process name doc-view-conversion-buffer
                       program args)))
     (push proc doc-view--current-converter-processes)
@@ -1139,14 +1163,17 @@ doc-view-pdf-password-protected-pdfdraw-p
     (search-forward "error: cannot authenticate password" nil t)))
 
 (defun doc-view-pdf->png-converter-mupdf (pdf png page callback)
-  (let ((pdf-passwd (if (doc-view-pdf-password-protected-pdfdraw-p pdf)
-                        (read-passwd "Enter password for PDF file: "))))
+  (let* ((pdf-passwd (if (doc-view-pdf-password-protected-pdfdraw-p pdf)
+                         (read-passwd "Enter password for PDF file: ")))
+         (options `(,(concat "-o" png)
+                    ,(format "-r%d" (round doc-view-resolution))
+                    ,@(if pdf-passwd `("-p" ,pdf-passwd)))))
+    (when (and (eq doc-view-doc-type 'epub) doc-view-epub-font-size)
+      (setq options (append options (list (format "-S%s" doc-view-epub-font-size)))))
     (doc-view-start-process
      "pdf->png" doc-view-pdfdraw-program
      `(,@(doc-view-pdfdraw-program-subcommand)
-       ,(concat "-o" png)
-       ,(format "-r%d" (round doc-view-resolution))
-       ,@(if pdf-passwd `("-p" ,pdf-passwd))
+       ,@options
        ,pdf
        ,@(if page `(,(format "%d" page))))
      callback)))
@@ -1189,7 +1216,7 @@ doc-view-pdf/ps->png
   "Convert PDF-PS to PNG asynchronously."
   (funcall
    (pcase doc-view-doc-type
-     ('pdf doc-view-pdf->png-converter-function)
+     ((or 'pdf 'epub 'cbz 'fb2 'xps 'oxps) doc-view-pdf->png-converter-function)
      ('djvu #'doc-view-djvu->tiff-converter-ddjvu)
      (_ #'doc-view-ps->png-converter-ghostscript))
    pdf-ps png nil
@@ -1227,20 +1254,20 @@ doc-view-document->bitmap
     (let ((rest (cdr pages)))
       (funcall doc-view-single-page-converter-function
 	       pdf (format png (car pages)) (car pages)
-       (lambda ()
-         (if rest
-             (doc-view-document->bitmap pdf png rest)
-           ;; Yippie, the important pages are done, update the display.
-           (clear-image-cache)
-           ;; For the windows that have a message (like "Welcome to
-           ;; DocView") display property, clearing the image cache is
-           ;; not sufficient.
-           (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
-             (with-selected-window win
-	       (when (stringp (overlay-get (doc-view-current-overlay) 'display))
-		 (doc-view-goto-page (doc-view-current-page)))))
-           ;; Convert the rest of the pages.
-           (doc-view-pdf/ps->png pdf png)))))))
+               (lambda ()
+                 (if rest
+                     (doc-view-document->bitmap pdf png rest)
+                   ;; Yippie, the important pages are done, update the display.
+                   (clear-image-cache)
+                   ;; For the windows that have a message (like "Welcome to
+                   ;; DocView") display property, clearing the image cache is
+                   ;; not sufficient.
+                   (dolist (win (get-buffer-window-list (current-buffer) nil 'visible))
+                     (with-selected-window win
+	               (when (stringp (overlay-get (doc-view-current-overlay) 'display))
+		         (doc-view-goto-page (doc-view-current-page)))))
+                   ;; Convert the rest of the pages.
+                   (doc-view-pdf/ps->png pdf png)))))))
 
 (defun doc-view-pdf->txt (pdf txt callback)
   "Convert PDF to TXT asynchronously and call CALLBACK when finished."
@@ -1337,7 +1364,9 @@ doc-view-convert-current-doc
 		    ;; Rename to doc.pdf
 		    (rename-file opdf pdf)
 		    (doc-view-pdf/ps->png pdf png-file)))))
-      ((or 'pdf 'djvu)
+      ;; The doc-view-mode-p check ensures that epub, cbz, fb2 and
+      ;; (o)xps are handled with mutool
+      ((or 'pdf 'djvu 'epub 'cbz 'fb2 'xps 'oxps)
        (let ((pages (doc-view-active-pages)))
          ;; Convert doc to bitmap images starting with the active pages.
          (doc-view-document->bitmap doc-view--buffer-file-name png-file pages)))
@@ -1432,7 +1461,7 @@ doc-view-paper-sizes
 (defun doc-view-guess-paper-size (iw ih)
   "Guess the paper size according to the aspect ratio."
   (cl-labels ((div (x y)
-		   (round (/ (* 100.0 x) y))))
+		(round (/ (* 100.0 x) y))))
     (let ((ar (div iw ih))
 	  (al (mapcar (lambda (l)
 			(list (div (nth 1 l) (nth 2 l)) (car l)))
@@ -1869,6 +1898,8 @@ doc-view-set-doc-type
                    ("dvi" dvi)
                    ;; PDF
                    ("pdf" pdf) ("epdf" pdf)
+                   ;; EPUB
+                   ("epub" epub)
                    ;; PostScript
                    ("ps" ps) ("eps" ps)
                    ;; DjVu
@@ -1880,7 +1911,13 @@ doc-view-set-doc-type
                    ;; Microsoft Office formats (also handled by the odf
                    ;; conversion chain).
                    ("doc" odf) ("docx" odf) ("xls" odf) ("xlsx" odf)
-                   ("ppt" odf) ("pps" odf) ("pptx" odf) ("rtf" odf))
+                   ("ppt" odf) ("pps" odf) ("pptx" odf) ("rtf" odf)
+                   ;; CBZ
+                   ("cbz" cbz)
+                   ;; FB2
+                   ("fb2" fb2)
+                   ;; (Open)XPS
+                   ("xps" xps) ("oxps" oxps))
 		 t))))
 	(content-types
 	 (save-excursion
@@ -1889,7 +1926,13 @@ doc-view-set-doc-type
 	    ((looking-at "%!") '(ps))
 	    ((looking-at "%PDF") '(pdf))
 	    ((looking-at "\367\002") '(dvi))
-	    ((looking-at "AT&TFORM") '(djvu))))))
+	    ((looking-at "AT&TFORM") '(djvu))
+            ;; The following pattern actually is for recognizing
+            ;; zip-archives, so that this same association is used for
+            ;; cbz files. This is fine, as cbz files should be handled
+            ;; like epub anyway.
+            ((looking-at "PK") '(epub))
+            ))))
     (setq-local
      doc-view-doc-type
      (car (or (nreverse (seq-intersection name-types content-types #'eq))
diff --git a/lisp/files.el b/lisp/files.el
index a11786fca2..f2c656bfde 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2925,7 +2925,7 @@ auto-mode-alist
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MS-DOS
      ("\\.[eE]?[pP][sS]\\'" . ps-mode)
-     ("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
+     ("\\.\\(?:PDF\\|EPUB\\|CBZ\\|FB2\\|O?XPS\\|DVI\\|OD[FGPST]\\|DOCX\\|XLSX?\\|PPTX?\\|pdf\\|epub\\|cbz\\|fb2\\|o?xps\\|djvu\\|dvi\\|od[fgpst]\\|docx\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("\\.s\\(v\\|iv\\|ieve\\)\\'" . sieve-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-14 20:02           ` dalanicolai
@ 2022-01-26 20:28             ` dalanicolai
  2022-01-27 16:05               ` Lars Ingebrigtsen
  0 siblings, 1 reply; 26+ messages in thread
From: dalanicolai @ 2022-01-26 20:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 1167 bytes --]

Just a gentle reminder, because I am not sure if you have seen this.
I think this patch is more or less ready for merging (all previous feedback
 has been processed, and it is only a small patch).
Otherwise... no pressure, just checking

On Fri, 14 Jan 2022 at 21:02, dalanicolai <dalanicolai@gmail.com> wrote:

> And another, updated, patch, adding an extra option to configure the epub
> font-size
>
> On Fri, 14 Jan 2022 at 17:15, dalanicolai <dalanicolai@gmail.com> wrote:
>
>> So here is a second version of the patch. But it adds a few more
>> extensions to the list
>> I forgot about them, as I don't use or experimented with them, but I
>> figured that
>> this is a good opportunity to add the support for those extensions also.
>> A small comment for those who are interested, the CBZ (and by mupdf
>> unsupported CBR)
>> files seem to be just zipped/rarred collections of image files (I guess
>> usually png/jpg). So
>> supporting those extensions doesn't really require the `mutool` command
>> if emacs would
>> just uncompress the collections.
>>
>> I guess there is not much more to comment on in addition to the comments
>> within the patch/files.
>>
>

[-- Attachment #2: Type: text/html, Size: 1888 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-26 20:28             ` dalanicolai
@ 2022-01-27 16:05               ` Lars Ingebrigtsen
  2022-01-27 21:09                 ` Iñigo Serna
  2022-01-29 17:07                 ` dalanicolai
  0 siblings, 2 replies; 26+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-27 16:05 UTC (permalink / raw)
  To: dalanicolai; +Cc: Stefan Monnier, Emacs Devel

dalanicolai <dalanicolai@gmail.com> writes:

> Just a gentle reminder, because I am not sure if you have seen this.
> I think this patch is more or less ready for merging (all previous feedback
>  has been processed, and it is only a small patch).

Thanks; pushed to Emacs 29 (with some changes -- there were
byte-compilation warnings due to the ordering of macros and variables).

And it's usually safer to submit patches with `M-x submit-emacs-patch'
so that the patches land in the bug tracker.  Patches posted to
emacs-devel have an unfortunate tendency to get lost.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-27 16:05               ` Lars Ingebrigtsen
@ 2022-01-27 21:09                 ` Iñigo Serna
  2022-01-28 13:47                   ` Lars Ingebrigtsen
  2022-01-29 17:07                 ` dalanicolai
  1 sibling, 1 reply; 26+ messages in thread
From: Iñigo Serna @ 2022-01-27 21:09 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: dalanicolai, Stefan Monnier, emacs-devel

Hi,

I'm afraid this chunk is missing from the commit, so opening epub 
or fb2
fails with this cryptic error message:

    DocView: process pdf/ps->png changed status to exited 
    abnormally with code 1.


@@ -1189,7 +1216,7 @@ doc-view-pdf/ps->png
   "Convert PDF-PS to PNG asynchronously."
   (funcall
    (pcase doc-view-doc-type
-     ('pdf doc-view-pdf->png-converter-function)
+     ((or 'pdf 'epub 'cbz 'fb2 'xps 'oxps) 
doc-view-pdf->png-converter-function)
      ('djvu #'doc-view-djvu->tiff-converter-ddjvu)
      (_ #'doc-view-ps->png-converter-ghostscript))
    pdf-ps png nil

Thanks,
Iñigo

On 27 January 2022 at 17:05 +01, Lars Ingebrigtsen 
<larsi@gnus.org> wrote:

> dalanicolai <dalanicolai@gmail.com> writes:
>
>> Just a gentle reminder, because I am not sure if you have seen 
>> this.
>> I think this patch is more or less ready for merging (all 
>> previous feedback
>>  has been processed, and it is only a small patch).
>
> Thanks; pushed to Emacs 29 (with some changes -- there were
> byte-compilation warnings due to the ordering of macros and 
> variables).
>
> And it's usually safer to submit patches with `M-x 
> submit-emacs-patch'
> so that the patches land in the bug tracker.  Patches posted to
> emacs-devel have an unfortunate tendency to get lost.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-27 21:09                 ` Iñigo Serna
@ 2022-01-28 13:47                   ` Lars Ingebrigtsen
  2022-01-28 19:51                     ` Iñigo Serna
  0 siblings, 1 reply; 26+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-28 13:47 UTC (permalink / raw)
  To: Iñigo Serna; +Cc: dalanicolai, Stefan Monnier, emacs-devel

Iñigo Serna <inigoserna@gmx.com> writes:

> -     ('pdf doc-view-pdf->png-converter-function)
> +     ((or 'pdf 'epub 'cbz 'fb2 'xps 'oxps)

I missed the merge error; should be fixed now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-28 13:47                   ` Lars Ingebrigtsen
@ 2022-01-28 19:51                     ` Iñigo Serna
  0 siblings, 0 replies; 26+ messages in thread
From: Iñigo Serna @ 2022-01-28 19:51 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: dalanicolai, Stefan Monnier, emacs-devel

Thanks Lars!

On 28 January 2022 at 14:47 +01, Lars Ingebrigtsen 
<larsi@gnus.org> wrote:

> Iñigo Serna <inigoserna@gmx.com> writes:
>
>> -     ('pdf doc-view-pdf->png-converter-function)
>> +     ((or 'pdf 'epub 'cbz 'fb2 'xps 'oxps)
>
> I missed the merge error; should be fixed now.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH] add epub support to doc-view
  2022-01-27 16:05               ` Lars Ingebrigtsen
  2022-01-27 21:09                 ` Iñigo Serna
@ 2022-01-29 17:07                 ` dalanicolai
  1 sibling, 0 replies; 26+ messages in thread
From: dalanicolai @ 2022-01-29 17:07 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Stefan Monnier, Emacs Devel

[-- Attachment #1: Type: text/plain, Size: 959 bytes --]

Great!

I am checking for compiling errors frequently now, and will try to make
that always.
And handy to know about `M-x submit-emacs-patch` also.

Anyway... thanks for merging!

On Thu, 27 Jan 2022 at 17:05, Lars Ingebrigtsen <larsi@gnus.org> wrote:

> dalanicolai <dalanicolai@gmail.com> writes:
>
> > Just a gentle reminder, because I am not sure if you have seen this.
> > I think this patch is more or less ready for merging (all previous
> feedback
> >  has been processed, and it is only a small patch).
>
> Thanks; pushed to Emacs 29 (with some changes -- there were
> byte-compilation warnings due to the ordering of macros and variables).
>
> And it's usually safer to submit patches with `M-x submit-emacs-patch'
> so that the patches land in the bug tracker.  Patches posted to
> emacs-devel have an unfortunate tendency to get lost.
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #2: Type: text/html, Size: 1516 bytes --]

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2022-01-29 17:07 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  2:20 [PATCH] add epub support to doc-view dalanicolai
2022-01-11  2:32 ` Po Lu
2022-01-11  9:34   ` dalanicolai
2022-01-11  9:50     ` Tassilo Horn
2022-01-11 10:04       ` dalanicolai
2022-01-11 10:08         ` dalanicolai
2022-01-11 10:15         ` Robert Pluim
2022-01-11  9:59     ` Robert Pluim
2022-01-11 10:09       ` dalanicolai
2022-01-11  2:48 ` Stefan Monnier
2022-01-11  3:30   ` Stefan Kangas
2022-01-11 10:01     ` dalanicolai
2022-01-11 10:16       ` Robert Pluim
2022-01-13  9:14         ` dalanicolai
2022-01-11  9:59   ` dalanicolai
2022-01-11 10:13     ` dalanicolai
2022-01-11 14:39     ` Stefan Monnier
2022-01-13  9:25       ` dalanicolai
2022-01-14 16:15         ` dalanicolai
2022-01-14 20:02           ` dalanicolai
2022-01-26 20:28             ` dalanicolai
2022-01-27 16:05               ` Lars Ingebrigtsen
2022-01-27 21:09                 ` Iñigo Serna
2022-01-28 13:47                   ` Lars Ingebrigtsen
2022-01-28 19:51                     ` Iñigo Serna
2022-01-29 17:07                 ` dalanicolai

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).