bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#43775: 28.0.50; Feature request: to include EPUB reading into doc-vi


From: Philip K.
Subject: bug#43775: 28.0.50; Feature request: to include EPUB reading into doc-view
Date: Sat, 03 Oct 2020 13:30:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Jean Louis <bugs@gnu.support> writes:

> Situation is that doc-view can read PDF files, and Libreoffice or Open
> Document files, and others, but EPUB files are not included. Many
> digital books are made in EPUB format.
>
> Vasilij Schneidermann <mail 📧 vasilij.de> have written the nov-mode
> which when aded to auto-mode-list, opens EPUB files
>
> (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode))
>
> I have asked him, he would be somehow willing to cooperate if this is
> also confirmed by more users, there are few problems with it, as it
> depends on dash.el and other packages.

I sent him a patch a few weeks ago to remove dash (attached below), so
that shouldn't be an issue if he's interested. It's not a radical
change, but at the time he wasn't interested.

The second dependency, esxml is practically part of nov-mode, and
wouldn't make sense to factor it out.

-- 
        Philip K.

>From a50b42281c8dfa4bb727f43f006cbaefa0d88640 Mon Sep 17 00:00:00 2001
From: Philip K <philipk@posteo.net>
Date: Fri, 28 Aug 2020 23:34:05 +0200
Subject: [PATCH] Drop dash dependency

---
 nov.el | 96 +++++++++++++++++++++++++++++++---------------------------
 1 file changed, 51 insertions(+), 45 deletions(-)

diff --git a/nov.el b/nov.el
index 0072ea1..43749de 100644
--- a/nov.el
+++ b/nov.el
@@ -5,7 +5,7 @@
 ;; Author: Vasilij Schneidermann <mail@vasilij.de>
 ;; URL: https://depp.brause.cc/nov.el
 ;; Version: 0.3.0
-;; Package-Requires: ((dash "2.12.0") (esxml "0.3.3") (emacs "24.4"))
+;; Package-Requires: ((esxml "0.3.3") (emacs "24.4"))
 ;; Keywords: hypermedia, multimedia, epub
 
 ;; This file is NOT part of GNU Emacs.
@@ -44,7 +44,7 @@
 ;;; Code:
 
 (require 'cl-lib)
-(require 'dash)
+(require 'pcase)
 (require 'esxml-query)
 (require 'shr)
 (require 'url-parse)
@@ -148,8 +148,9 @@ Each element of the stack is a list (NODEINDEX BUFFERPOS).")
 
 (defun nov-directory-files (directory)
   "Returns a list of files in DIRECTORY except for . and .."
-  (--remove (string-match-p "/\\.\\(?:\\.\\)?\\'" it)
-            (directory-files directory t)))
+  (cl-loop for file in (directory-files directory t)
+          unless (string-match-p "/\\.\\(?:\\.\\)?\\'" file)
+          collect file))
 
 (defun nov-contains-nested-directory-p (directory)
   "Non-nil if DIRECTORY contains exactly one directory."
@@ -167,9 +168,9 @@ Each element of the stack is a list (NODEINDEX BUFFERPOS).")
   (delete-directory child))
 
 (defun nov--fix-permissions (file-or-directory mode)
-  (->> (file-modes file-or-directory)
-       (file-modes-symbolic-to-number mode)
-       (set-file-modes file-or-directory)))
+  (let* ((modes (file-modes file-or-directory))
+        (symbolic (file-modes-symbolic-to-number mode modes)))
+    (set-file-modes file-or-directory symbolic)))
 
 (defun nov-fix-permissions (directory)
   "Iterate recursively through DIRECTORY to fix its files."
@@ -306,7 +307,9 @@ Required keys are 'identifier and everything in
   "Extract an alist of manifest files for CONTENT in DIRECTORY.
 Each alist item consists of the identifier and full path."
   (mapcar (lambda (node)
-            (-let [(&alist 'id id 'href href) (esxml-node-attributes node)]
+            (let* ((attr (esxml-node-attributes node))
+                  (id (cdr (assq 'id attr)))
+                  (href (cdr (assq 'href attr))))
               (cons (intern id)
                     (nov-make-path directory (nov-urldecode href)))))
           (esxml-query-all "package>manifest>item" content)))
@@ -336,7 +339,7 @@ Each alist item consists of the identifier and full path."
     (let ((toc-file (assq nov-toc-id manifest)))
       (when (not toc-file)
         (error "EPUB 3 <nav> file not found"))
-      (setq files (--remove (eq (car it) nov-toc-id) files))
+      (setq files (cl-remove nov-toc-id files :key #'car))
       (cons toc-file files))))
 
 (defun nov-content-files (directory content)
@@ -351,8 +354,9 @@ Each alist item consists of the identifier and full path."
 
 (defun nov--walk-ncx-node (node)
   (let ((tag (esxml-node-tag node))
-        (children (--filter (eq (esxml-node-tag it) 'navPoint)
-                            (esxml-node-children node))))
+        (children (cl-loop for node in (esxml-node-children node)
+                          when (eq (esxml-node-tag node) 'navPoint)
+                          collect node)))
     (cond
      ((eq tag 'navMap)
       (insert "<ol>\n")
@@ -449,17 +453,18 @@ This function honors `shr-max-image-proportion' if 
possible."
                 'imagemagick)))
     (if (not (display-graphic-p))
         (insert alt)
-      (-let* (((x1 y1 x2 y2) (window-inside-pixel-edges
-                              (get-buffer-window (current-buffer))))
-              (image
-               ;; `create-image' errors out for unsupported image types
-               (ignore-errors
-                 (create-image path type nil
-                               :ascent 100
-                               :max-width (truncate (* shr-max-image-proportion
-                                                       (- x2 x1)))
-                               :max-height (truncate (* 
shr-max-image-proportion
-                                                        (- y2 y1)))))))
+      (pcase-let* ((`(,x1 ,y1 ,x2 ,y2)
+                   (window-inside-pixel-edges
+                    (get-buffer-window (current-buffer))))
+                  (image
+                   ;; `create-image' errors out for unsupported image types
+                   (ignore-errors
+                      (create-image path type nil
+                                   :ascent 100
+                                   :max-width (truncate (* 
shr-max-image-proportion
+                                                           (- x2 x1)))
+                                   :max-height (truncate (* 
shr-max-image-proportion
+                                                             (- y2 y1)))))))
         (if image
             (insert-image image)
           (insert alt))))))
@@ -524,13 +529,14 @@ If the document path refers to an image (as determined by
 `image-type-file-name-regexps'), an image is inserted, otherwise
 the HTML is rendered with `nov-render-html-function'."
   (interactive)
-  (-let* (((id . path) (aref nov-documents nov-documents-index))
-          ;; HACK: this should be looked up in the manifest
-          (imagep (--find (string-match-p (car it) path)
-                          image-type-file-name-regexps))
-          ;; NOTE: allows resolving image references correctly
-          (default-directory (file-name-directory path))
-          (buffer-read-only nil))
+  (pcase-let* ((`(,id . ,path) (aref nov-documents nov-documents-index))
+               ;; HACK: this should be looked up in the manifest
+               (imagep (cl-find path image-type-file-name-regexps
+                               :test (lambda (a b) (string-match-p b a))
+                               :key #'car))
+               ;; NOTE: allows resolving image references correctly
+               (default-directory (file-name-directory path))
+               (buffer-read-only nil))
     (erase-buffer)
 
     (cond
@@ -602,7 +608,7 @@ the HTML is rendered with `nov-render-html-function'."
         (erase-buffer)
         (insert (format "EPUB Version: %s\n" version))
         (dolist (item metadata)
-          (-let [(key . value) item]
+          (pcase-let ((`(,key . ,value) item))
             (insert (format "%s: " (capitalize (symbol-name key))))
             (if value
                 (if (eq key 'description)
@@ -721,10 +727,10 @@ Saving is only done if `nov-save-place-file' is set."
   (interactive)
   (or nov-history
       (user-error "This is the first document you looked at"))
-  (-let ((history-forward
-          (cons (list nov-documents-index (point))
-                nov-history-forward))
-         ((index opoint) (car nov-history)))
+  (pcase-let ((history-forward
+               (cons (list nov-documents-index (point))
+                     nov-history-forward))
+              (`(,index ,opoint) (car nov-history)))
     (setq nov-history (cdr nov-history))
     (nov-goto-document index)
     (setq nov-history (cdr nov-history))
@@ -737,8 +743,8 @@ Saving is only done if `nov-save-place-file' is set."
   (interactive)
   (or nov-history-forward
       (user-error "This is the last document you looked at"))
-  (-let ((history-forward (cdr nov-history-forward))
-         ((index opoint) (car nov-history-forward)))
+  (pcase-let ((history-forward (cdr nov-history-forward))
+              (`(,index ,opoint) (car nov-history-forward)))
     (nov-goto-document index)
     (setq nov-history-forward history-forward)
     (goto-char opoint)
@@ -764,15 +770,15 @@ Saving is only done if `nov-save-place-file' is set."
     (nov-clean-up)
     (error "Invalid EPUB file"))
   (let* ((content (nov-slurp (nov-container-filename nov-temp-dir) t))
-         (content-file (->> (nov-container-content-filename content)
-                            (nov-make-path nov-temp-dir)))
+         (content-file (nov-make-path
+                       nov-temp-dir
+                       (nov-container-content-filename content)))
          (work-dir (file-name-directory content-file))
          (content (nov-slurp content-file t)))
     (setq nov-content-file content-file)
     (setq nov-epub-version (nov-content-version content))
     (setq nov-metadata (nov-content-metadata content))
-    (setq nov-documents (->> (nov-content-files work-dir content)
-                             (apply 'vector)))
+    (setq nov-documents (apply 'vector (nov-content-files work-dir content)))
     (setq nov-documents-index 0))
   (setq buffer-undo-list t)
   (setq nov-file-name (buffer-file-name))
@@ -880,11 +886,11 @@ See also `nov-bookmark-make-record'."
                 (libxml-parse-html-region (point-min) (point-max)))))
     (mapcar
      (lambda (node)
-       (-let* ((href (esxml-node-attribute 'href node))
-               (label (mapconcat 'string-trim-whitespace
-                                 (esxml-find-descendants #'stringp node) " "))
-               ((filename target) (nov-url-filename-and-target href)))
-         (list label filename 'nov-imenu-goto-function target)))
+       (pcase-let* ((href (esxml-node-attribute 'href node))
+                   (label (mapconcat 'string-trim-whitespace
+                                      (esxml-find-descendants #'stringp node) 
" "))
+                   (`(,filename ,target) (nov-url-filename-and-target href)))
+        (list label filename 'nov-imenu-goto-function target)))
      (esxml-query-all "a" toc))))
 
 (defun nov-imenu-setup ()
-- 
2.26.2


reply via email to

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