emacs-diffs
[Top][All Lists]
Advanced

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

master c45c1e8: Make eww-open-file work with Tramp file names


From: Lars Ingebrigtsen
Subject: master c45c1e8: Make eww-open-file work with Tramp file names
Date: Sat, 18 Jul 2020 12:02:54 -0400 (EDT)

branch: master
commit c45c1e8c4376cbbe68cec997a5ef686732377ca6
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make eww-open-file work with Tramp file names
    
    * lisp/net/eww.el (eww-open-file): Allow opening non-local Tramp
    files (bug#40425).
    (eww): Adjust calling convention to allow passing in data directly
    via a buffer.
---
 lisp/net/eww.el | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 5fc0b08..f4e3aa3 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -263,13 +263,17 @@ This list can be customized via `eww-suggest-uris'."
     (nreverse uris)))
 
 ;;;###autoload
-(defun eww (url &optional arg)
+(defun eww (url &optional arg buffer)
   "Fetch URL and render the page.
 If the input doesn't look like an URL or a domain name, the
 word(s) will be searched for via `eww-search-prefix'.
 
 If called with a prefix ARG, use a new buffer instead of reusing
-the default EWW buffer."
+the default EWW buffer.
+
+If BUFFER, the data to be rendered is in that buffer.  In that
+case, this function doesn't actually fetch URL.  BUFFER will be
+killed after rendering."
   (interactive
    (let* ((uris (eww-suggested-uris))
          (prompt (concat "Enter URL or keywords"
@@ -307,8 +311,12 @@ the default EWW buffer."
     (insert (format "Loading %s..." url))
     (goto-char (point-min)))
   (let ((url-mime-accept-string eww-accept-content-types))
-    (url-retrieve url #'eww-render
-                  (list url nil (current-buffer)))))
+    (if buffer
+        (let ((eww-buffer (current-buffer)))
+          (with-current-buffer buffer
+            (eww-render nil url nil eww-buffer)))
+      (url-retrieve url #'eww-render
+                    (list url nil (current-buffer))))))
 
 (function-put 'eww 'browse-url-browser-kind 'internal)
 
@@ -361,7 +369,19 @@ the default EWW buffer."
   (eww (concat "file://"
               (and (memq system-type '(windows-nt ms-dos))
                    "/")
-              (expand-file-name file))))
+              (expand-file-name file))
+       nil
+       ;; The file name may be a non-local Tramp file.  The URL
+       ;; library doesn't understand these file names, so use the
+       ;; normal Emacs machinery to load the file.
+       (with-current-buffer (generate-new-buffer " *eww file*")
+         (set-buffer-multibyte nil)
+         (insert "Content-type: " (or (mailcap-extension-to-mime
+                                      (url-file-extension file))
+                                      "application/octet-stream")
+                 "\n\n")
+         (insert-file-contents file)
+         (current-buffer))))
 
 ;;;###autoload
 (defun eww-search-words ()



reply via email to

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