From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#44338: 27.1; EWW can't download and view pdf Date: Tue, 03 Nov 2020 23:24:57 +0000 Message-ID: <87a6vy6n1y.fsf@tcd.ie> References: <878sbmo6i0.fsf@tcd.ie> 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="9902"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 44338@debbugs.gnu.org, Nicholas Harrison To: Jean Louis , Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 04 00:26:12 2020 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 1ka5gp-0002Rx-UV for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 04 Nov 2020 00:26:12 +0100 Original-Received: from localhost ([::1]:39968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka5go-0002Bx-Gr for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 03 Nov 2020 18:26:10 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka5gg-0002Bo-Rt for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 18:26:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ka5gg-0004ag-IO for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 18:26:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ka5gg-0005Bi-C9 for bug-gnu-emacs@gnu.org; Tue, 03 Nov 2020 18:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 03 Nov 2020 23:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44338 X-GNU-PR-Package: emacs Original-Received: via spool by 44338-submit@debbugs.gnu.org id=B44338.160444590819867 (code B ref 44338); Tue, 03 Nov 2020 23:26:02 +0000 Original-Received: (at 44338) by debbugs.gnu.org; 3 Nov 2020 23:25:08 +0000 Original-Received: from localhost ([127.0.0.1]:46771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ka5fn-0005AM-Um for submit@debbugs.gnu.org; Tue, 03 Nov 2020 18:25:08 -0500 Original-Received: from mail-wm1-f48.google.com ([209.85.128.48]:35696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ka5fm-00059k-06 for 44338@debbugs.gnu.org; Tue, 03 Nov 2020 18:25:06 -0500 Original-Received: by mail-wm1-f48.google.com with SMTP id h22so799893wmb.0 for <44338@debbugs.gnu.org>; Tue, 03 Nov 2020 15:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=foPSkEGTe6PdMSmTDDWTc6ZuKCYeBS3WYPwnWCPHTVo=; b=lZk4HpzoXh3nLhtMLQAx2bxaGc+cQQH94QB+VwhILgC9kyU27I0MJTqlPx5oEPqClF K9fH5vHWsI6ctLpfEfuzrmRLVMdp372+rEqCoPKhW3zAtLxr9Z6UtSiVThC3mu9yzI9M 8rPnduNsmXuGattulsiktNxvf18pFKUdC+tMwTR+SLzopMXEJUQnSwXsrOcNeteC2afy XZlz5tC+0xgWHqxIi8mN9xuB6E+lw8Hz1TU0Kpcul6XRpmbBjqMfFPdNS4a3TffSjeUy 8jov6onrYeuUjzrmLZFN6S5K5gD4wGq3NODaqshcw2lwfsNAdiL5NK126bK/2xlMKauk wH2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=foPSkEGTe6PdMSmTDDWTc6ZuKCYeBS3WYPwnWCPHTVo=; b=LyuNdDJOEJ39JcV0wLr8ciCKWh82R7CIjxecA8zRfHEm4jyeGMx6l8Vzim1Sfu+oSI R8OTP/09R1DC7b+TTqZOibXlHfTbf+skjVignY0au6KzzzE3Cx5Du6NGsZy/LnszY4qe /RKerplaYgEBnHr5T9J+ADlyg4IBER0zMRaHNOJrN41WKn4dZvATzQr4aW8xSCiDwNTH rcWrHANJBRg50E59+fNVSwsqis2AGee5XpAbqmab/w3lZa8ggcPTzbsuo6kR6Khofaql NPUrus/eGN6029fj+rRiS8O+pufUGyz48PyGjYdLgb8ZS7BS6Wf34QxJjnbWh5GX/1xp 4nmA== X-Gm-Message-State: AOAM533YzFVNOys/DAiG6zY/LnV/pX+SessI7DQBPGEDz7FyHfynhDi6 YvryqLSfJz+w0yLvTFgetuVOCg== X-Google-Smtp-Source: ABdhPJy49Mf9LdstqnkgIa82ZgFJv65457kQoygmXoSJx/gKjEEioPf7PbOTaoilYgKT+6KdjoVAwQ== X-Received: by 2002:a1c:5545:: with SMTP id j66mr1583616wmb.31.1604445900130; Tue, 03 Nov 2020 15:25:00 -0800 (PST) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id i33sm173882wri.79.2020.11.03.15.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 15:24:58 -0800 (PST) In-Reply-To: (Jean Louis's message of "Sat, 31 Oct 2020 19:35:19 +0300") 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:192652 Archived-At: --=-=-= Content-Type: text/plain Jean Louis writes: > When external editor is used, buffer for eww pdf remains there in > background *eww pdf* and neither l or q key bindings work, it would be > expected to go back to the previous page from that buffer. Indeed, popping to an empty *eww pdf* buffer when using an external viewer is suboptimal. Even less optimal is that external viewers are called synchronously, so Emacs cannot be used simultaneously. How's the attached? -- Basil --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Improve-eww-support-for-externally-viewed-PDFs.patch >From 4595e0f159fffc93fc5be750478e52db4885d373 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Tue, 3 Nov 2020 22:54:34 +0000 Subject: [PATCH] Improve eww support for externally viewed PDFs The *eww pdf* buffer is only needed when viewing PDFs within Emacs, e.g., with doc-view-mode. External PDF viewers are called with a temporary file, so the buffer is not needed in that case. What's more, mailcap-view-mime erased the buffer and left it in fundamental-mode until now, so the user was left staring at a useless, empty buffer. To make things even worse, external viewers were invoked synchronously until now, so the user could not browse the PDF file and use Emacs simultaneously. * lisp/net/mailcap.el (mailcap--async-shell): New function. (mailcap-view-mime): Use it to invoke external viewers asynchronously. Mention erasure of current buffer in that case in docstring. Add a period between the temporary file name and its extension. * lisp/net/eww.el (eww-display-pdf): Pop to *eww pdf* buffer only if it is used for displaying a document; otherwise kill it (bug#44338). Simplify buffer-substring+insert as insert-buffer-substring. --- lisp/net/eww.el | 21 +++++++++++++-------- lisp/net/mailcap.el | 30 ++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index ebc75e0e8a..e9763ef6df 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -811,14 +811,19 @@ eww-display-image (declare-function mailcap-view-mime "mailcap" (type)) (defun eww-display-pdf () - (let ((data (buffer-substring (point) (point-max)))) - (pop-to-buffer-same-window (get-buffer-create "*eww pdf*")) - (let ((coding-system-for-write 'raw-text) - (inhibit-read-only t)) - (erase-buffer) - (insert data) - (mailcap-view-mime "application/pdf"))) - (goto-char (point-min))) + (let ((buf (current-buffer)) + (pos (point))) + (with-current-buffer (get-buffer-create "*eww pdf*") + (let ((coding-system-for-write 'raw-text) + (inhibit-read-only t)) + (erase-buffer) + (insert-buffer-substring buf pos) + (mailcap-view-mime "application/pdf")) + (if (zerop (buffer-size)) + ;; Buffer contents passed to shell command via temporary file. + (kill-buffer) + (goto-char (point-min)) + (pop-to-buffer-same-window (current-buffer)))))) (defun eww-setup-buffer () (when (or (plist-get eww-data :url) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 94cd9e2156..ad715c4b0e 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -1128,20 +1128,30 @@ mailcap-file-default-commands res))) (nreverse res))))) +(defun mailcap--async-shell (command file) + "Asynchronously call MIME viewer shell COMMAND. +Replace %s in COMMAND with FILE, as per `mailcap-mime-data'. +Delete FILE once COMMAND exits." + (let ((buf (get-buffer-create " *mailcap shell*"))) + (async-shell-command (format command file) buf) + (add-function :after (process-sentinel (get-buffer-process buf)) + (lambda (proc _msg) + (when (memq (process-status proc) '(exit signal)) + (delete-file file)))))) + (defun mailcap-view-mime (type) "View the data in the current buffer that has MIME type TYPE. -`mailcap--computed-mime-data' determines the method to use." +The variable `mailcap--computed-mime-data' determines the method +to use. If the method is a shell command string, erase the +current buffer after passing its contents to the shell command." (let ((method (mailcap-mime-info type))) (if (stringp method) - (let ((file (make-temp-file "emacs-mailcap" nil - (cadr (split-string type "/"))))) - (unwind-protect - (let ((coding-system-for-write 'binary)) - (write-region (point-min) (point-max) file nil 'silent) - (delete-region (point-min) (point-max)) - (shell-command (format method file))) - (when (file-exists-p file) - (delete-file file)))) + (let* ((ext (concat "." (cadr (split-string type "/")))) + (file (make-temp-file "emacs-mailcap" nil ext)) + (coding-system-for-write 'binary)) + (write-region nil nil file nil 'silent) + (delete-region (point-min) (point-max)) + (mailcap--async-shell method file)) (funcall method)))) (provide 'mailcap) -- 2.28.0 --=-=-=--