[Top][All Lists]

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

bug#16211: eww should support multiple *eww* buffers

From: Ivan Shmakov
Subject: bug#16211: eww should support multiple *eww* buffers
Date: Sun, 06 Jul 2014 19:05:11 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

>>>>> Ted Zlatanov <address@hidden> writes:
>>>>> On Sat, 21 Dec 2013 21:51:49 +0000 Ivan Shmakov <address@hidden> wrote:
>>>>> "TZ" == Ted Zlatanov <address@hidden> writes:


 TZ> I don't see a need for complicated variable passing as you
 TZ> described and I omitted, but have no strong opinion about it
 TZ> either.

 IS> Please note that eww-setup-buffer is called from the buffer filled
 IS> by url-retrieve, and /not/ from one of the EWW buffers.  I see no
 IS> obvious way for it to deduce from which buffer the original command
 IS> (say, M-x eww) was called so to get back there.

 TZ> Right, OK.  I will let you and Lars figure it out, but if you can
 TZ> propose a patch to accomplish what you describe, it will probably
 TZ> speed things up.

        Well, I’ve tried to contact assign at gnu dot org and
        copyright-clerk at fsf dot org once again some weeks ago, and
        got no reply again.  I wonder if it has anything to do with the
        way my MXes work (though I clearly see the message being
        accepted by one of the FSF/GNU ones in the logs), or that I’ve
        requested a copyright /disclaimer/ (for I believe that these of
        my changes are non-copyrightable per se anyway.)

        Nevertheless, the patch that I use for quite some time is MIMEd.
        And just in case the changes I suggest /are/ copyrightable,
        here’s the license for them:

To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide.  This software is distributed without any

You should have received a copy of the CC0 Public Domain Dedication
along with this software.  If not, see

        Note though that there’re a few changes not strictly necessary.
        For instance, eww-setup-buffer now uses set-buffer instead of
        switch-to-buffer, so that it’s possible to start eww-reload in
        several EWW buffers in a row, without being switched from one to
        another at some random point.  Also, there’s a new
        eww-buffer-name variable.

FSF associate member #7257      http://boycottsystemd.org/
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 02fc575..738e462 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -57,6 +57,12 @@
   :group 'eww
   :type 'string)
+(defcustom eww-buffer-name "*eww*"
+  "Buffer name to use for rendering HTML."
+  :version "24.4"
+  :group 'eww
+  :type 'string)
 (defcustom eww-use-external-browser-for-content-type
   "Always use external browser for specified content-type."
@@ -125,6 +131,7 @@ See also `eww-form-checkbox-selected-symbol'."
   :group 'eww)
 (defvar eww-current-url nil)
+(defvar eww-current-buffer nil)
 (defvar eww-current-dom nil)
 (defvar eww-current-source nil)
 (defvar eww-current-title ""
@@ -169,7 +176,8 @@ word(s) will be searched for via `eww-search-prefix'."
                  (setq url (concat url "/"))))
            (setq url (concat eww-search-prefix
                              (replace-regexp-in-string " " "+" url))))))
-  (url-retrieve url 'eww-render (list url)))
+  (url-retrieve url 'eww-render
+               (list url nil eww-current-buffer)))
 ;;;###autoload (defalias 'browse-web 'eww)
@@ -182,7 +190,7 @@ word(s) will be searched for via `eww-search-prefix'."
               (expand-file-name file))))
-(defun eww-render (status url &optional point)
+(defun eww-render (status url &optional point buffer)
   (let ((redirect (plist-get status :redirect)))
     (when redirect
       (setq url redirect)))
@@ -199,8 +207,10 @@ word(s) will be searched for via `eww-search-prefix'."
         (data-buffer (current-buffer)))
-       (progn
-          (setq eww-current-title "")
+       (let ((eww-current-buffer (or buffer
+                                     eww-current-buffer)))
+         (with-current-buffer eww-current-buffer
+           (setq eww-current-title ""))
            ((and eww-use-external-browser-for-content-type
                  (string-match-p eww-use-external-browser-for-content-type
@@ -258,10 +268,11 @@ word(s) will be searched for via `eww-search-prefix'."
         (or document
              'base (list (cons 'href url))
-             (libxml-parse-html-region (point) (point-max))))))
-    (setq eww-current-source (buffer-substring (point) (point-max)))
+             (libxml-parse-html-region (point) (point-max)))))
+       (source (buffer-substring (point) (point-max))))
-    (setq eww-current-dom document)
+    (setq eww-current-dom document
+         eww-current-source source)
     (let ((inhibit-read-only t)
          (after-change-functions nil)
          (shr-width nil)
@@ -381,8 +392,12 @@ word(s) will be searched for via `eww-search-prefix'."
       (shr-put-image data nil))
     (goto-char (point-min))))
-(defun eww-setup-buffer ()
-  (switch-to-buffer (get-buffer-create "*eww*"))
+(defun eww-setup-buffer (&optional buffer)
+  (set-buffer
+   (cond ((not buffer)      (or eww-current-buffer
+                               (get-buffer-create eww-buffer-name)))
+        ((bufferp buffer)  buffer)
+        (t (generate-new-buffer (or buffer eww-buffer-name)))))
   (let ((inhibit-read-only t))
@@ -401,7 +416,7 @@ word(s) will be searched for via `eww-search-prefix'."
         (source eww-current-source))
     (with-current-buffer buf
       (delete-region (point-min) (point-max))
-      (insert (or eww-current-source "no source"))
+      (insert (or source "no source"))
       (goto-char (point-min))
       (when (fboundp 'html-mode)
@@ -479,6 +494,7 @@ word(s) will be searched for via `eww-search-prefix'."
   (setq-local eww-current-dom nil)
   (setq-local eww-current-source nil)
   (setq-local eww-current-title "")
+  (setq-local eww-current-buffer (current-buffer))
   (setq-local browse-url-browser-function 'eww-browse-url)
   (setq-local after-change-functions 'eww-process-text-input)
   (setq-local eww-history nil)
@@ -567,7 +583,7 @@ appears in a <link> or <a> tag."
   "Reload the current page."
   (url-retrieve eww-current-url 'eww-render
-               (list eww-current-url (point))))
+               (list eww-current-url (point) eww-current-buffer)))
 ;; Form support.

reply via email to

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