aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLin Sun2023-08-16 01:00:07 +0000
committerEli Zaretskii2023-08-20 11:46:36 +0300
commitbef68b7bbe3d1f1a27c292161cd7e5c7c95cc6eb (patch)
tree16146626229c1526bfc1de366edb95953de4253e
parent6fb1d4bb1a9b32f64253bfb5180faf9700feab30 (diff)
downloademacs-bef68b7bbe3d1f1a27c292161cd7e5c7c95cc6eb.tar.gz
emacs-bef68b7bbe3d1f1a27c292161cd7e5c7c95cc6eb.zip
Allow fetching URL at point without switching to it
* lisp/net/eww.el (eww-open-in-new-buffer): Stay on current buffer when invoked with prefix argument. (Bug#65346)
-rw-r--r--doc/misc/eww.texi3
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/net/eww.el49
3 files changed, 38 insertions, 19 deletions
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index b67624af9f8..2181355a57e 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -137,7 +137,8 @@ URL at point in a new EWW buffer, akin to opening a link in a new
137``tab'' in other browsers. When @code{global-tab-line-mode} is 137``tab'' in other browsers. When @code{global-tab-line-mode} is
138enabled, this buffer is displayed in the tab on the window tab line. 138enabled, this buffer is displayed in the tab on the window tab line.
139When @code{tab-bar-mode} is enabled, a new tab is created on the frame 139When @code{tab-bar-mode} is enabled, a new tab is created on the frame
140tab bar. 140tab bar. If the prefix key @kbd{C-u} is avaliable, it will stay on
141current buffer.
141 142
142@findex eww-readable 143@findex eww-readable
143@kindex R 144@kindex R
diff --git a/etc/NEWS b/etc/NEWS
index aa19c785ff1..b859140f174 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -460,6 +460,11 @@ the kill ring. Alternate links are optional metadata that HTML pages
460use for linking to their alternative representations, such as 460use for linking to their alternative representations, such as
461translated versions or associated RSS feeds. 461translated versions or associated RSS feeds.
462 462
463+++
464*** 'eww-open-in-new-buffer' support prefix key "C-u" to stay current buffer.
465The command accept the prefix key "C-u" to open the url in a new
466buffer but stay in current buffer, won't jump to the new buffer.
467
463** go-ts-mode 468** go-ts-mode
464 469
465+++ 470+++
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index cb73926f462..f2ed60f1724 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -542,24 +542,37 @@ for the search engine used."
542 (call-interactively #'eww))) 542 (call-interactively #'eww)))
543 (call-interactively #'eww))) 543 (call-interactively #'eww)))
544 544
545(defun eww-open-in-new-buffer () 545(defun eww--open-url-in-new-buffer (url)
546 "Fetch link at point in a new EWW buffer." 546 "Open the URL in a new EWW buffer."
547 (interactive) 547 ;; clone useful to keep history, but
548 (let ((url (eww-suggested-uris))) 548 ;; should not clone from non-eww buffer
549 (if (null url) (user-error "No link at point") 549 (with-current-buffer
550 (when (or (eq eww-browse-url-new-window-is-tab t) 550 (if (eq major-mode 'eww-mode) (clone-buffer)
551 (and (eq eww-browse-url-new-window-is-tab 'tab-bar) 551 (generate-new-buffer "*eww*"))
552 tab-bar-mode)) 552 (unless (equal url (eww-current-url))
553 (let ((tab-bar-new-tab-choice t)) 553 (eww-mode)
554 (tab-new))) 554 (eww (if (consp url) (car url) url)))))
555 ;; clone useful to keep history, but 555
556 ;; should not clone from non-eww buffer 556(defun eww-open-in-new-buffer (&optional no-select url)
557 (with-current-buffer 557 "Fetch URL in a new EWW buffer.
558 (if (eq major-mode 'eww-mode) (clone-buffer) 558
559 (generate-new-buffer "*eww*")) 559If the NO-SELECT is not `nil', the forcus will stay on current buffer.
560 (unless (equal url (eww-current-url)) 560
561 (eww-mode) 561If the URL is `nil', it will try `eww-suggested-uris' under current cursor."
562 (eww (if (consp url) (car url) url))))))) 562 (interactive "P")
563 (if-let ((url (or url (eww-suggested-uris))))
564 (if (or (eq eww-browse-url-new-window-is-tab t)
565 (and (eq eww-browse-url-new-window-is-tab 'tab-bar)
566 tab-bar-mode))
567 (let ((tab-bar-new-tab-choice t))
568 (tab-new)
569 (eww--open-url-in-new-buffer url)
570 (when no-select
571 (tab-bar-switch-to-prev-tab)))
572 (if no-select
573 (save-window-excursion (eww--open-url-in-new-buffer url))
574 (eww--open-url-in-new-buffer url)))
575 (user-error "No link at point")))
563 576
564(defun eww-html-p (content-type) 577(defun eww-html-p (content-type)
565 "Return non-nil if CONTENT-TYPE designates an HTML content type. 578 "Return non-nil if CONTENT-TYPE designates an HTML content type.