]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow fetching URL at point without switching to it
authorLin Sun <sunlin7@hotmail.com>
Wed, 16 Aug 2023 01:00:07 +0000 (01:00 +0000)
committerEli Zaretskii <eliz@gnu.org>
Sun, 20 Aug 2023 08:46:36 +0000 (11:46 +0300)
* lisp/net/eww.el (eww-open-in-new-buffer):  Stay on current
buffer when invoked with prefix argument.  (Bug#65346)

doc/misc/eww.texi
etc/NEWS
lisp/net/eww.el

index b67624af9f863e46a9b9e66b964a05f4952e9105..2181355a57e49f3de1b06c9e1f14edafd87ea36c 100644 (file)
@@ -137,7 +137,8 @@ URL at point in a new EWW buffer, akin to opening a link in a new
 ``tab'' in other browsers.  When @code{global-tab-line-mode} is
 enabled, this buffer is displayed in the tab on the window tab line.
 When @code{tab-bar-mode} is enabled, a new tab is created on the frame
-tab bar.
+tab bar.  If the prefix key @kbd{C-u} is avaliable, it will stay on
+current buffer.
 
 @findex eww-readable
 @kindex R
index aa19c785ff15f8805ef766a6d00c614d8eb9653d..b859140f174bb1373cd2253e15c4ac0b4f555796 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -460,6 +460,11 @@ the kill ring.  Alternate links are optional metadata that HTML pages
 use for linking to their alternative representations, such as
 translated versions or associated RSS feeds.
 
++++
+*** 'eww-open-in-new-buffer' support prefix key "C-u" to stay current buffer.
+The command accept the prefix key "C-u" to open the url in a new
+buffer but stay in current buffer, won't jump to the new buffer.
+
 ** go-ts-mode
 
 +++
index cb73926f462ff5c999dfdb71d61b402412cccaae..f2ed60f1724209e6fe31066edadbfed75b4bcc73 100644 (file)
@@ -542,24 +542,37 @@ for the search engine used."
           (call-interactively #'eww)))
     (call-interactively #'eww)))
 
-(defun eww-open-in-new-buffer ()
-  "Fetch link at point in a new EWW buffer."
-  (interactive)
-  (let ((url (eww-suggested-uris)))
-    (if (null url) (user-error "No link at point")
-      (when (or (eq eww-browse-url-new-window-is-tab t)
-                (and (eq eww-browse-url-new-window-is-tab 'tab-bar)
-                     tab-bar-mode))
-        (let ((tab-bar-new-tab-choice t))
-          (tab-new)))
-      ;; clone useful to keep history, but
-      ;; should not clone from non-eww buffer
-      (with-current-buffer
-          (if (eq major-mode 'eww-mode) (clone-buffer)
-            (generate-new-buffer "*eww*"))
-        (unless (equal url (eww-current-url))
-          (eww-mode)
-          (eww (if (consp url) (car url) url)))))))
+(defun eww--open-url-in-new-buffer (url)
+  "Open the URL in a new EWW buffer."
+  ;; clone useful to keep history, but
+  ;; should not clone from non-eww buffer
+  (with-current-buffer
+      (if (eq major-mode 'eww-mode) (clone-buffer)
+        (generate-new-buffer "*eww*"))
+    (unless (equal url (eww-current-url))
+      (eww-mode)
+      (eww (if (consp url) (car url) url)))))
+
+(defun eww-open-in-new-buffer (&optional no-select url)
+  "Fetch URL in a new EWW buffer.
+
+If the NO-SELECT is not `nil', the forcus will stay on current buffer.
+
+If the URL is `nil', it will try `eww-suggested-uris' under current cursor."
+  (interactive "P")
+  (if-let ((url (or url (eww-suggested-uris))))
+      (if (or (eq eww-browse-url-new-window-is-tab t)
+              (and (eq eww-browse-url-new-window-is-tab 'tab-bar)
+                   tab-bar-mode))
+          (let ((tab-bar-new-tab-choice t))
+            (tab-new)
+            (eww--open-url-in-new-buffer url)
+            (when no-select
+              (tab-bar-switch-to-prev-tab)))
+        (if no-select
+            (save-window-excursion (eww--open-url-in-new-buffer url))
+          (eww--open-url-in-new-buffer url)))
+    (user-error "No link at point")))
 
 (defun eww-html-p (content-type)
   "Return non-nil if CONTENT-TYPE designates an HTML content type.