From dd47aa509a7f7d7548e4c048e42e7dc32a12fbe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0=2E=20G=C3=B6ktu=C4=9F=20Kayaalp?= Date: Thu, 7 Feb 2019 14:33:08 +0300 Subject: [PATCH] Support not reusing *eww* buffer when navigating from a non-eww one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/net/eww.el (eww-reuse-buffer): New defcustom. * lisp/net/eww.el (eww): Use the above to decide whether to use ‘get-buffer-create’ or ‘generate-new-buffer’. * doc/misc/eww.texi (Basics): * etc/NEWS: Document the new feature. --- doc/misc/eww.texi | 8 +++++++- etc/NEWS | 6 ++++++ lisp/net/eww.el | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index b299ea1fb7..cc96909ab3 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -98,10 +98,16 @@ Basics (@code{eww-copy-page-url}) will copy the current URL to the kill ring. @findex eww-open-in-new-buffer +@vindex eww-reuse-buffer @kindex M-RET The @kbd{M-@key{RET}} command (@code{eww-open-in-new-buffer}) opens the URL at point in a new EWW buffer, akin to opening a link in a new -``tab'' in other browsers. +``tab'' in other browsers. If you want this same behavior when +following links or running @code{eww} in a buffer that is not in +@code{eww-mode}, set @code{eww-reuse-buffer} to @code{nil}. Normal +navigation within an @code{eww-mode} buffer will not be affected, but +running @kbd{M-x eww} or following a URI with @code{browse-url} family +of functions will result in new eww buffers. @findex eww-readable @kindex R diff --git a/etc/NEWS b/etc/NEWS index 72a6b385a8..5dc4c8b8b2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -652,6 +652,12 @@ has been executed. If set, shr will not render tags with attribute 'aria-hidden="true"'. This attribute is meant to tell screen readers to ignore a tag. ++++ +*** New option 'eww-reuse-buffer'. +If set (default), eww will reuse the "*eww*" buffer when called from a +non-eww buffer. If not, it will generate a new buffer and use it +instead. + ** Htmlfontify *** The functions 'hfy-color', 'hfy-color-vals' and diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 3b7d9d5c2f..2ac4c606de 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -153,6 +153,12 @@ eww-form-checkbox-symbol (const "☐") ; Unicode BALLOT BOX string)) +(defcustom eww-reuse-buffer t + "Reuse the *eww* buffer when not in an `eww-mode' buffer." + :version "27.1" + :group 'eww + :type 'boolean) + (defface eww-form-submit '((((type x w32 ns) (class color)) ; Like default mode line :box (:line-width 2 :style released-button) @@ -250,7 +256,12 @@ eww-suggested-uris (defun eww (url) "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'." +word(s) will be searched for via `eww-search-prefix'. + +When the current buffer is not in `eww-mode', if +`eww-reuse-buffer' is non-nil, the *eww* buffer will be reused if +available, otherwise generated; if set to nil instead, a new +buffer will be used in case *eww* is already in use." (interactive (let* ((uris (eww-suggested-uris)) (prompt (concat "Enter URL or keywords" @@ -261,7 +272,9 @@ eww (pop-to-buffer-same-window (if (eq major-mode 'eww-mode) (current-buffer) - (get-buffer-create "*eww*"))) + (funcall + (if eww-reuse-buffer #'get-buffer-create #'generate-new-buffer) + "*eww*"))) (eww-setup-buffer) ;; Check whether the domain only uses "Highly Restricted" Unicode ;; IDNA characters. If not, transform to punycode to indicate that -- 2.20.1