From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Kjartan Oli Agustsson Newsgroups: gmane.emacs.bugs Subject: bug#55825: [PATCH] Reconvert EPUB buffers when user CSS is changed Date: Sun, 26 Jun 2022 12:33:42 +0000 Message-ID: References: <83pmjk7mxp.fsf@gnu.org> <83mten6g2v.fsf@gnu.org> <83leu64d7y.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13383"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.11; emacs 29.0.50 Cc: 55825@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 26 14:42:15 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5Rag-0003Ix-KQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Jun 2022 14:42:14 +0200 Original-Received: from localhost ([::1]:43712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o5Raf-0002ig-0w for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Jun 2022 08:42:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o5RaU-0002dW-Sq for bug-gnu-emacs@gnu.org; Sun, 26 Jun 2022 08:42:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o5RaU-0006rs-H8 for bug-gnu-emacs@gnu.org; Sun, 26 Jun 2022 08:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o5RaU-0006P0-G8 for bug-gnu-emacs@gnu.org; Sun, 26 Jun 2022 08:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kjartan Oli Agustsson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Jun 2022 12:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55825 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 55825-submit@debbugs.gnu.org id=B55825.165624726724543 (code B ref 55825); Sun, 26 Jun 2022 12:42:02 +0000 Original-Received: (at 55825) by debbugs.gnu.org; 26 Jun 2022 12:41:07 +0000 Original-Received: from localhost ([127.0.0.1]:46901 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o5RZa-0006Nn-Df for submit@debbugs.gnu.org; Sun, 26 Jun 2022 08:41:06 -0400 Original-Received: from mail-oln040092070072.outbound.protection.outlook.com ([40.92.70.72]:24153 helo=EUR03-AM5-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o5RZV-0006MS-MO for 55825@debbugs.gnu.org; Sun, 26 Jun 2022 08:41:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a9pxfknaavxrEkJX7G0c61++bi7BElbHVeGHLyKaW4o+L2+uY+EphDlQs0rUeJyW6PJhY/F1QeRhlQFl7Ym2KPWREdSMiAqVRKsmvh45F1mo9TVNGREM8FgDmdZIy4ge1EWBT0XvKrlXI2WWZDpoU48A/oQwUGC2CJCrU/WxqRPwkM/RLiHeByX543sHZpZcvvLiXlt7Tt23dJ50BuOwX0Y4mau2KJ09jjMZ998vtz4S4q1pMNElTazONPwPw/eqIwehK1/K93KW/bBY1i4GWASkfJpdpUF4rlU7gFCJNIPPsG3yMXCcCinyFLKpIKAhFxv5zTpp18b+hs1mNCZqVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xQoWXxzwXfH6qj26fZwBIIoKl9CmsDLSsFy7wVU2QEk=; b=nSZ5zUZPe/2FKlEI2aP+ZwB6z+YXn3BZbuX/ncpInLMyhfsJhjWARxHDqXMVfuCAG+MADF3JU/WaiwYGeabrJFwka3jnBkVUl592WFxaQnYVQZxoscisO0hXVMVChP7iEeQGdGlk5PbPMg1yFR+FM17PlTrIzUrQvGfeZ4SVhZMG5okwy7H46ZRgAxhJC63KRrWQCN5t9Yb/GWwNAgBQd6psvzmAmIgVJg8fN0vBj6Bi+cjewOD6L5BAePc8ixn4nXWCn3N2o5p+fYXu/GtosUbTT83/Gzmcd1EY7i5ZhZsJE3VZSTlLwtQq2s8Qck8rSC/oxnMEclbqst0zgG0Fvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xQoWXxzwXfH6qj26fZwBIIoKl9CmsDLSsFy7wVU2QEk=; b=FrpsUDLzUREnQANGEpds7Rb/X18kv2GKeLTd6DFrI/9EyiN1242/8VaCTVdB+U19gzPQ4fWb9LBzYxmfSwvs8pgU1WvVTTlUCQTwCtdEA5RVoqNkohAweJeuhTF+bXf3UcfHxWCXciWnxx6WrXc0WAjANNIeVSFoApb1oReZwRVyBGik5RlA+PW/6IxyRsCKePVewJojb3fmYJlbTHUFDRx/R/uBhp/wE098G8oaynV0rb/YIWv2wveJw3bJzPAw+KyJhrVKYNTTuHUoP/zeihs1Opvtsu3ZIsar0Wp+BezaxrF7P/jF71ISC5cjFP0s3qTY0gShi58sL65gkIY7hw== Original-Received: from GV1P193MB2310.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2a::20) by AS8P193MB1269.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:337::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17; Sun, 26 Jun 2022 12:40:55 +0000 Original-Received: from GV1P193MB2310.EURP193.PROD.OUTLOOK.COM ([fe80::71d2:fe40:82bd:db42]) by GV1P193MB2310.EURP193.PROD.OUTLOOK.COM ([fe80::71d2:fe40:82bd:db42%6]) with mapi id 15.20.5373.015; Sun, 26 Jun 2022 12:40:55 +0000 In-reply-to: <83leu64d7y.fsf@gnu.org> X-TMN: [s+dGCFS2GpggUuIivvNeYXHHWm3V90x2] X-ClientProxiedBy: AM3PR05CA0110.eurprd05.prod.outlook.com (2603:10a6:207:2::12) To GV1P193MB2310.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2a::20) X-Microsoft-Original-Message-ID: <871qvb4mya.fsf@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b390aa9e-9a76-40b3-c64f-08da57711c68 X-MS-TrafficTypeDiagnostic: AS8P193MB1269:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YwnwXLDGEi9Jy2iElgf5By7pH+5JfNghsozHoa257XWGtUCnSLmc+qvHKBkFADtt35D8nSFX08ri3xUU9Ig/syzgUhCsC1CyvKnGmoBm5DfQL8rA8C2VfevaFURMVA9nIvpa40Z5+s1JMSl/B0p1LK36FB8ncrqZ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WBB5OSBCNYQuUKbKnX7p81awwPEjH6kEEwFDXJYeGvmnjjpoWOELQPnR9WZxjEpZN/xarc6l1vcYxoVtDcsYOv8UbkQGoYzf4qir3WPN4oWexRwLxTeLFhrNhs0STAVm70pz4y5PUHMvGOaDumAvBM0ODuNYYFROoDS2FA2N1v011tHud5QDMkbh5IMN94U/AhmTg0vzNG6GBpwYeaP9/nE/hZnrMIInKdnp96tyf 1gJAa8UdwDpYMSTNjnBDDZOp3UIOL/JOlCAnfi2K2AcMdqyU+aHHihMDL6shVVYbDwEYwrZumO6kBEL/ON+IiDoydx0xFxBEVW X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b390aa9e-9a76-40b3-c64f-08da57711c68 X-MS-Exchange-CrossTenant-AuthSource: GV1P193MB2310.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jun 2022 12:40:54.9645 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P193MB1269 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:235324 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Eli Zaretskii 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Reconvert-EPUB-buffers-when-user-CSS-is-changed.patch Content-Transfer-Encoding: quoted-printable Content-Description: revised patch From=2032cc2061f9cdecc3bbd748097d2b7c8e64cff17a Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Kjartan=3D20=3DC3=3D93li=3D20=3DC3=3D81g=3DC3=3DBAstsson?= =3D 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 =2D-- 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 =2D-- 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)) =20 ;;;; Customization Options @@ -226,17 +227,49 @@ doc-view-resolution Higher values result in larger images." :type 'number) =20 =2D(defcustom doc-view-mutool-user-stylesheet nil =2D "User stylesheet to use when converting EPUB documents to PDF." =2D :type '(choice (const nil) =2D (file :must-match t)) =2D :version "29.1") =2D (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'.") =20 +(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-rec= onvert)))) + +(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.") =20 =2D(defun doc-view-custom-set-epub-font-size (option-name new-value) =2D (set-default option-name new-value) =2D (dolist (x (buffer-list)) =2D (with-current-buffer x =2D (when (eq doc-view-doc-type 'epub) =2D (delete-directory doc-view--current-cache-dir t) =2D (doc-view-initiate-display) =2D (doc-view-goto-page (doc-view-current-page)))))) =2D (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= ))))) =2D (when doc-view-mutool-user-stylesheet + (when doc-view-epub-user-stylesheet (setq options (append options (list (format "-U%s" (expand-file-name =2D 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) =2D-=20 2.36.1 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Assuming there is still interest in merging this, does this warrant a NEWS entry/mention in the manual? =2D-=20 Kjartan =C3=93li =C3=81g=C3=BAstsson GPG Key fingerprint: 4801 0D71 49C0 1DD6 E5FD 6AC9 D757 2FE3 605E E6B0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHLBAEBCAA1FiEESAENcUnAHdbl/WrJ11cv42Be5rAFAmK4U80XHGtqYXJ0YW5v bGlAb3V0bG9vay5jb20ACgkQ11cv42Be5rBddQv+K430L2qeEJuozTPDGjc2P2rp fTxaLokdHIpGZDjBvAUiD3tjxZZ9sd96sNG76qo5HWpe2KCxnq0ELuDxcWBpPGt9 9xPVxTyFyxCj9vxKfnBIKfTTr9lJPDF8M4JPEG7Z0BJcxSPd2WZSJtMhTpuqitHn WSqeWExetz/ETGgA6Vs0BKrjPGY2z1nr8LfOYkTj89CsJ5gK51rkxbZGgW++40LS e4y2JmkcLVteWenrPi+pHrM8PmbjZJvqFIHyPJzf+xZ3q/4049ng2AqRI/s8cGGi fj/VY26JAZKgxWanEv0xNnYwm1nqPHZ3fgjMYgx1aGFk3382BKIdSFeFTobdLtdw HULjL076ZEYuzD9PppN+MQpTtMnvsNdKup8Vm680vD34jvKLp9TN/ouO8vrsEMMm J/UTG7jaTZe2gaUOmNeO9wq+YbfeXNCdUBw5x9GYpqB0aodxlJNEWuwSU/eRuyB6 Iz+B6EYmUPCbmorHX/TETlKGnpU0LZx+fbfrYvPV =oBk8 -----END PGP SIGNATURE----- --==-=-=--