bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#31808: [PATCH] customize how to display eww buffer.


From: Yuya Minami
Subject: bug#31808: [PATCH] customize how to display eww buffer.
Date: Wed, 13 Jun 2018 16:53:47 +0900

Currently `eww` function using `pop-to-buffer-same-window` to display
eww buffer.
This changes make customizable how to display eww buffer.
And using `with-current-buffer` to prevent functions that depend on
the current buffer being eww-mode from being executed in other
major-mode buffer.
---
 lisp/net/eww.el | 59 +++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 97fdabd72b..a97d22ae2d 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -153,6 +153,11 @@ eww-form-checkbox-symbol
                  (const "☐")            ; Unicode BALLOT BOX
                  string))
 
+(defcustom eww-display-buffer-function 'pop-to-buffer-same-window
+  "Function used to display eww buffer in `eww'."
+  :group 'eww
+  :type 'function)
+
 (defface eww-form-submit
   '((((type x w32 ns) (class color))   ; Like default mode line
      :box (:line-width 2 :style released-button)
@@ -257,33 +262,33 @@ eww
                          (if uris (format " (default %s)" (car uris)) "")
                          ": ")))
      (list (read-string prompt nil 'eww-prompt-history uris))))
-  (setq url (eww--dwim-expand-url url))
-  (pop-to-buffer-same-window
-   (if (eq major-mode 'eww-mode)
-       (current-buffer)
-     (get-buffer-create "*eww*")))
-  (eww-setup-buffer)
-  ;; Check whether the domain only uses "Highly Restricted" Unicode
-  ;; IDNA characters.  If not, transform to punycode to indicate that
-  ;; there may be funny business going on.
-  (let ((parsed (url-generic-parse-url url)))
-    (when (url-host parsed)
-      (unless (puny-highly-restrictive-domain-p (url-host parsed))
-        (setf (url-host parsed) (puny-encode-domain (url-host parsed)))))
-    ;; When the URL is on the form "http://a/../../../g";, chop off all
-    ;; the leading "/.."s.
-    (when (url-filename parsed)
-      (while (string-match "\\`/[.][.]/" (url-filename parsed))
-        (setf (url-filename parsed) (substring (url-filename parsed) 3))))
-    (setq url (url-recreate-url parsed)))
-  (plist-put eww-data :url url)
-  (plist-put eww-data :title "")
-  (eww-update-header-line-format)
-  (let ((inhibit-read-only t))
-    (insert (format "Loading %s..." url))
-    (goto-char (point-min)))
-  (url-retrieve url 'eww-render
-                (list url nil (current-buffer))))
+  (let ((buffer (if (eq major-mode 'eww-mode)
+                    (current-buffer)
+                  (get-buffer-create "*eww*"))))
+    (funcall eww-display-buffer-function buffer)
+    (with-current-buffer buffer
+      (eww-setup-buffer)
+      ;; Check whether the domain only uses "Highly Restricted" Unicode
+      ;; IDNA characters.  If not, transform to punycode to indicate that
+      ;; there may be funny business going on.
+      (let* ((expanded (eww--dwim-expand-url url))
+             (parsed (url-generic-parse-url expanded)))
+        (when (url-host parsed)
+          (unless (puny-highly-restrictive-domain-p (url-host parsed))
+            (setf (url-host parsed) (puny-encode-domain (url-host parsed)))))
+        ;; When the URL is on the form "http://a/../../../g";, chop off all
+        ;; the leading "/.."s.
+        (when (url-filename parsed)
+          (while (string-match "\\`/[.][.]/" (url-filename parsed))
+            (setf (url-filename parsed) (substring (url-filename parsed) 3))))
+        (setq url (url-recreate-url parsed)))
+      (plist-put eww-data :url url)
+      (plist-put eww-data :title "")
+      (eww-update-header-line-format)
+      (let ((inhibit-read-only t))
+        (insert (format "Loading %s..." url))
+        (goto-char (point-min)))
+      (url-retrieve url 'eww-render (list url nil buffer)))))
 
 (defun eww--dwim-expand-url (url)
   (setq url (string-trim url))
-- 
2.17.1







reply via email to

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