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: Mon, 06 Jun 2022 19:20:04 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20525"; mail-complaints-to="usenet@ciao.gmane.io" To: 55825@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 07 07:01:16 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 1nyRL9-0005AM-L6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Jun 2022 07:01:15 +0200 Original-Received: from localhost ([::1]:35298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyRL8-0005IM-7w for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 07 Jun 2022 01:01:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyRKw-0005Fp-Cn for bug-gnu-emacs@gnu.org; Tue, 07 Jun 2022 01:01:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyRKw-0003MB-3r for bug-gnu-emacs@gnu.org; Tue, 07 Jun 2022 01:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nyRKv-0001JJ-Rm for bug-gnu-emacs@gnu.org; Tue, 07 Jun 2022 01:01:01 -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: Tue, 07 Jun 2022 05:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55825 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16545780234974 (code B ref -1); Tue, 07 Jun 2022 05:01:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 Jun 2022 05:00:23 +0000 Original-Received: from localhost ([127.0.0.1]:37306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyRKH-0001I2-RZ for submit@debbugs.gnu.org; Tue, 07 Jun 2022 01:00:23 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:47360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyILr-00049M-JP for submit@debbugs.gnu.org; Mon, 06 Jun 2022 15:25:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyILo-0008LP-18 for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2022 15:25:22 -0400 Original-Received: from mail-dbaeur03olkn20824.outbound.protection.outlook.com ([2a01:111:f400:fe1a::824]:21985 helo=EUR03-DBA-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyILl-0004X1-7u for bug-gnu-emacs@gnu.org; Mon, 06 Jun 2022 15:25:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bUTvkguRYzMzA9SLMmAfPoskd2naiYEOV3YqXLELMhtKfP0cOMgvpqh3dgLERiL0XhUekbCuOT5PVkuCG/GVQ45UK2rrTBnqNWDgSll4YbcmDJpsmGygqhpBpdZgmZsBUQ4GJqgUfpmDY+B6HPl76dRoOTtRGHWxIujTVORccz1qKJioU2wfid/6Ky/e6NGblI8rClY7cyTJFMkEg6UZFbc31eZyWP3SpZTqSVqpghg1Oh5AxnIEyf5+LHr/E8Yo0xAw8w6h/MxmVPmPN4OOfZUPlbswnk6MQK9sG2ot7jjBOLSY7qEpzh3jyhhVD8kFPW3lmUQZg1u8pOOd43NvVQ== 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=ug9fehrUJSqBHNif6rJLROckehf+XxL+UYR5+4DDG2w=; b=U0Okdvmdc7ZNF6xo4VSHeZ5z4wU3bHeH8m3QQVI3+2gwB3bibkj9AutgW/3OmtQ7lnr6NmAi90ArdYHVJBwJRiS8ZunPp5QChhQQBmnOO9Py3Bl0N1BLIUtYReTBcMY7u4F+WocpO2A5dNdyQubKoS0RFCI4oeh+h3opIW6tC15AfeqfDP1y2L6FE0nXSU5uB9h0inOB7nsvDKffnQySHN10w8KUGEopmXuRqUbzzs9Ke3QnvOJ1+WewacoX2Dm9xhTsZQ6kMu67yoKJQEuzImF0f02FX4hpVRPF7dx7IFSnPcyymPpcyDK39mN1plguO/cfseQWQ0MR7+ibVI51gg== 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=ug9fehrUJSqBHNif6rJLROckehf+XxL+UYR5+4DDG2w=; b=Y21mJd1QHw4AhTEyz/QlhyVjaKK7xl1kRMvlYQTyuIpGtNzYuuh3o4O9GK0U3Ga6oPJ7xsuQfXrc6fOhJU0yxhT2hmu/tc8nsP/1vfYTWS7aScCyYI9hentV4sSarbU2Iz/03luqce00O1DUtlJcliIxiSz2NF5RBE2mUZ6/GXDh95fGA20/fvNEsYShf4L/pBNDbEr/fDq0BVvuo+OCZw7VIzOayMGBmIQOlFum7Mw/wMOtkEvGd1uo5Rn6eQnpWzoHLGqtQAXCaEVBtV2+n7DSYGuJRsBq70EfL9yNcObH/fH0dE4KDBKCwzLb1BteJ9qbq/TFJzhAvZGADmUiCg== Original-Received: from GV1P193MB2310.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2a::20) by GV1P193MB2022.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12; Mon, 6 Jun 2022 19:20:06 +0000 Original-Received: from GV1P193MB2310.EURP193.PROD.OUTLOOK.COM ([fe80::ec59:f94:e9c4:2f17]) by GV1P193MB2310.EURP193.PROD.OUTLOOK.COM ([fe80::ec59:f94:e9c4:2f17%8]) with mapi id 15.20.5314.019; Mon, 6 Jun 2022 19:20:05 +0000 X-TMN: [lwBTEcj8kEnJxkL+PXhDLALMj8x5SP0s] X-ClientProxiedBy: AM0PR03CA0003.eurprd03.prod.outlook.com (2603:10a6:208:14::16) To GV1P193MB2310.EURP193.PROD.OUTLOOK.COM (2603:10a6:150:2a::20) X-Microsoft-Original-Message-ID: <87o7z5k3a3.fsf@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8857189a-430c-4efb-3d77-08da47f1901b X-MS-TrafficTypeDiagnostic: GV1P193MB2022:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P96FxZBJcFtZ2qov6S5PEE5my+kMGsiJ5hX9J2tPz5ows7rtwAmNC5z6o8FUn4VsbSto7qlL/bWAV8g08v0rTiRcD0ti9/81WcZys8KdGH4VfNZhXAPw/GMJsLA3QwoYe5k8j9Ct27bkkQnJXu0LIwoAXkIG89H5twMih92MEiCElusNAGQn+DZGJsC2UTVSkP/JzWSPlIWFJHp1BFgECGRpbtf3sxC+kcvocAMdbC++JI/M84GPYvZGzlF/jYWg9vUKgiS4zB3GXZ+7tWMgVMaazP1OtpQnenqnco0jz8pH4MPZwXEbZbiasH8a5/GRw+QuBad+0Hip9mn8JbvKKX4crvmszV22HVLvE0ofCLP3KQ+DF+NB83rhT5oxQQJWctsdh3US1Kyh20ffE0n8RwNC/nS/nSter2Qrk7WlLcviokdoUzHy878bs1n3Fom4V8ZC++ZIVn3RNc0Xv8Vj6/AdGjux0DyZBim6J0CzQhoMHSUFweyEpf+qaIign69Fb9oqIDUkDG/pKJo+PDj9OfVxmNtBurE6PFggii6MjfcuE1mQOjEqWEdnhcS0zJMc8nD1Ho6++fIXqqTuuor8rw== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fm4bWzlppqc2BCXtQeHL3Z0Rz1CAJAJBZg4kweoZ54utjbhkKI7okL27T4RMHmShLFvOhr86mOrFg1gdhrG6rmna6tn3+6lR0fAH+jzVeE7JSckLVGc+fYLpA5hETBQm5pAjQ+OSanvr6fOYeXGlpZqTYcySVQsEvKDCy+QGjDWbfZwf3Elene7yIM782C+PXl4u98gwRjgWRefvA+kxaWlVAk6U1IME3RtQ94xGNnsvYJzBbYe++xgkCO0lhs7rUrPyXuNlLxowz3An3XP21hwigRmFFE1L+P6Yw5MvC4df4rnNWcjEkyV9VUK4NcmQM3L26CAlytTqdsPtTEkF+E0rQbL44zEcm4smXo7OMbmyyAVZzcC8pILCRw7aaO8SVQL/C97jD3SAvF8dubK4Qlek6PlItIHlhampphh43eQDgXoKWFmUmsJHkEl04dw8RfTghFDI7I8Yop8OHLJ6fAJSSHRrE7eJTroVTMapzWhZQNBsbNu9I5tNR2KUYHMzOW/svP3dy50UyNjW9ldT+guxrEYDxkHkhZGNORDmnWCoQ7zSINeiThpnfzAal2mnumYUysN9aA2bX5aPcfeAQHQ5ANwD19/7jQAITKXjYgxi7VfD9Uyw0dTITv1yu19YE1FfdIwXgeNXC0Y/RX51TpL4dLPYvJ3mOk0fMiVjF1NB2e/QeqDGLNHTKO3PH09SykJ8xi/k8VGdFTH4+FMDaGlwe84pPqUTIQfqBh/gVcg6cexBgcrXIw6pxs UWcHGv5JLu1BPAhBWadtxKrV//96ToccC0B0qpql1RygyUmA5ugiRCc+X2pjCpgtjB5PzjEi77F7RBpdGxdFu1SsncyT8aFKM2 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8857189a-430c-4efb-3d77-08da47f1901b X-MS-Exchange-CrossTenant-AuthSource: GV1P193MB2310.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2022 19:20:05.9083 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1P193MB2022 Received-SPF: pass client-ip=2a01:111:f400:fe1a::824; envelope-from=kjartanoli@outlook.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 07 Jun 2022 01:00:17 -0400 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:233834 Archived-At: --=-=-= Content-Type: text/plain Following my patch from a few months ago which added the `doc-view-mutool-user-stylesheet' defcustom to Doc-View making use of mutools ability to apply a user specified CSS file when converting a EPUB file. Here is a patch to reconvert existing EPUB buffers when the value of that variable (renamed to `doc-view-epub-user-stylesheet' as discussed after my last patch) is changed, or the specified file is changed, therefore applying the new CSS immediately. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Reconvert-EPUB-buffers-when-user-CSS-is-changed.patch Content-Description: Reconvert EPUB buffers whenn CSS is changed >From f7e243d02a8f19f4c433a8e9590da8364ca7f5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjartan=20=C3=93li=20=C3=81g=C3=BAstsson?= 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..fd0ee4bbb5 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." + (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 doc-view-epub-user-stylesheet + (file-notify-add-watch doc-view-epub-user-stylesheet '(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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Kjartan =C3=93li =C3=81g=C3=BAstsson GPG Key fingerprint: 4801 0D71 49C0 1DD6 E5FD 6AC9 D757 2FE3 605E E6B0 --=-=-=--