From: Kjartan Oli Agustsson <kjartanoli@outlook.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 55825@debbugs.gnu.org
Subject: bug#55825: [PATCH] Reconvert EPUB buffers when user CSS is changed
Date: Sun, 26 Jun 2022 12:33:42 +0000 [thread overview]
Message-ID: <GV1P193MB23107C409C1AFBBA89462B60DFB69@GV1P193MB2310.EURP193.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <83leu64d7y.fsf@gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 215 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> Thanks, then I guess 'change it is.
Having finally found the time to work on this again, I believe the
attached patch should fix all the issues identified by you and Lars.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: revised patch --]
[-- Type: text/x-patch, Size: 4536 bytes --]
From 32cc2061f9cdecc3bbd748097d2b7c8e64cff17a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kjartan=20=C3=93li=20=C3=81g=C3=BAstsson?=
<kjartanoli@outlook.com>
Date: Mon, 6 Jun 2022 18:34:05 +0000
Subject: [PATCH] Reconvert EPUB buffers when user CSS is changed
* lisp/doc-view.el (doc-view-epub-user-stylesheet): Add
`doc-view-custom-set-mutool-user-stylesheet' as setter, change name.
(doc-view-custom-set-epub-font-size): Factor reconvert logic out
(doc-view--epub-reconvert): Add defun
(doc-view--epub-stylesheet-watcher): Add defvar
(doc-view-custom-set-epub-user-stylesheet): Add defun
---
lisp/doc-view.el | 58 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 41 insertions(+), 17 deletions(-)
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 9d27347360..2bad50db79 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -144,6 +144,7 @@
(require 'dired)
(require 'image-mode)
(require 'jka-compr)
+(require 'filenotify)
(eval-when-compile (require 'subr-x))
;;;; Customization Options
@@ -226,17 +227,49 @@ doc-view-resolution
Higher values result in larger images."
:type 'number)
-(defcustom doc-view-mutool-user-stylesheet nil
- "User stylesheet to use when converting EPUB documents to PDF."
- :type '(choice (const nil)
- (file :must-match t))
- :version "29.1")
-
(defvar doc-view-doc-type nil
"The type of document in the current buffer.
Can be `dvi', `pdf', `ps', `djvu', `odf', `epub', `cbz', `fb2',
`xps' or `oxps'.")
+(defvar doc-view--epub-stylesheet-watcher nil
+ "File watcher for `doc-view-epub-user-stylesheet'.")
+
+(defun doc-view--epub-reconvert (&optional _event)
+ "Reconvert all epub buffers.
+
+EVENT is unused, but neccesary to work with the filenotify API"
+ (dolist (x (buffer-list))
+ (with-current-buffer x
+ (when (eq doc-view-doc-type 'epub)
+ (doc-view-reconvert-doc)))))
+
+(defun doc-view-custom-set-epub-user-stylesheet (option-name new-value)
+ "Setter for `doc-view-epub-user-stylesheet'.
+
+Reconverts existing epub buffers when the file used as a user
+stylesheet is switched, or its contents modified."
+ (set-default option-name new-value)
+ (file-notify-rm-watch doc-view--epub-stylesheet-watcher)
+ (doc-view--epub-reconvert)
+ (setq doc-view--epub-stylesheet-watcher
+ (when new-value
+ (file-notify-add-watch new-value '(change) #'doc-view--epub-reconvert))))
+
+(defcustom doc-view-epub-user-stylesheet nil
+ "User stylesheet to use when converting EPUB documents to PDF."
+ :type '(choice (const nil)
+ (file :must-match t))
+ :version "29.1"
+ :set #'doc-view-custom-set-epub-user-stylesheet)
+
+(defvar-local doc-view--current-cache-dir nil
+ "Only used internally.")
+
+(defun doc-view-custom-set-epub-font-size (option-name new-value)
+ (set-default option-name new-value)
+ (doc-view--epub-reconvert))
+
;; FIXME: The doc-view-current-* definitions below are macros because they
;; map to accessors which we want to use via `setf' as well!
(defmacro doc-view-current-page (&optional win)
@@ -249,15 +282,6 @@ doc-view-current-slice
(defvar-local doc-view--current-cache-dir nil
"Only used internally.")
-(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 '(choice (const nil) integer)
@@ -1178,12 +1202,12 @@ doc-view-pdf->png-converter-mupdf
(when doc-view-epub-font-size
(setq options (append options
(list (format "-S%s" doc-view-epub-font-size)))))
- (when doc-view-mutool-user-stylesheet
+ (when doc-view-epub-user-stylesheet
(setq options
(append options
(list (format "-U%s"
(expand-file-name
- doc-view-mutool-user-stylesheet)))))))
+ doc-view-epub-user-stylesheet)))))))
(doc-view-start-process
"pdf->png" doc-view-pdfdraw-program
`(,@(doc-view-pdfdraw-program-subcommand)
--
2.36.1
[-- Attachment #1.3: Type: text/plain, Size: 216 bytes --]
Assuming there is still interest in merging this, does this warrant a
NEWS entry/mention in the manual?
--
Kjartan Óli Ágústsson
GPG Key fingerprint: 4801 0D71 49C0 1DD6 E5FD 6AC9 D757 2FE3 605E E6B0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 691 bytes --]
next prev parent reply other threads:[~2022-06-26 12:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 19:20 bug#55825: [PATCH] Reconvert EPUB buffers when user CSS is changed Kjartan Oli Agustsson
2022-06-07 9:57 ` Lars Ingebrigtsen
2022-06-07 21:40 ` Kjartan Oli Agustsson
2022-06-08 2:35 ` Eli Zaretskii
2022-06-07 11:06 ` Eli Zaretskii
2022-06-07 21:51 ` Kjartan Oli Agustsson
2022-06-08 2:31 ` Eli Zaretskii
2022-06-08 23:10 ` Kjartan Oli Agustsson
2022-06-08 23:28 ` Kjartan Oli Agustsson
2022-06-09 5:28 ` Eli Zaretskii
2022-06-26 12:33 ` Kjartan Oli Agustsson [this message]
2022-06-26 15:53 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=GV1P193MB23107C409C1AFBBA89462B60DFB69@GV1P193MB2310.EURP193.PROD.OUTLOOK.COM \
--to=kjartanoli@outlook.com \
--cc=55825@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.