diff options
| author | Lin Sun | 2023-08-16 01:00:07 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2023-08-20 11:46:36 +0300 |
| commit | bef68b7bbe3d1f1a27c292161cd7e5c7c95cc6eb (patch) | |
| tree | 16146626229c1526bfc1de366edb95953de4253e | |
| parent | 6fb1d4bb1a9b32f64253bfb5180faf9700feab30 (diff) | |
| download | emacs-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.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/net/eww.el | 49 |
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 |
| 138 | enabled, this buffer is displayed in the tab on the window tab line. | 138 | enabled, this buffer is displayed in the tab on the window tab line. |
| 139 | When @code{tab-bar-mode} is enabled, a new tab is created on the frame | 139 | When @code{tab-bar-mode} is enabled, a new tab is created on the frame |
| 140 | tab bar. | 140 | tab bar. If the prefix key @kbd{C-u} is avaliable, it will stay on |
| 141 | current buffer. | ||
| 141 | 142 | ||
| 142 | @findex eww-readable | 143 | @findex eww-readable |
| 143 | @kindex R | 144 | @kindex R |
| @@ -460,6 +460,11 @@ the kill ring. Alternate links are optional metadata that HTML pages | |||
| 460 | use for linking to their alternative representations, such as | 460 | use for linking to their alternative representations, such as |
| 461 | translated versions or associated RSS feeds. | 461 | translated versions or associated RSS feeds. |
| 462 | 462 | ||
| 463 | +++ | ||
| 464 | *** 'eww-open-in-new-buffer' support prefix key "C-u" to stay current buffer. | ||
| 465 | The command accept the prefix key "C-u" to open the url in a new | ||
| 466 | buffer 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*")) | 559 | If the NO-SELECT is not `nil', the forcus will stay on current buffer. |
| 560 | (unless (equal url (eww-current-url)) | 560 | |
| 561 | (eww-mode) | 561 | If 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. |