@cindex url
@findex gnus-summary-browse-url
Scan the article buffer for links, and offer them to the user for
-browsing with @code{browse-url}. By default, only scan the article
-body; with a prefix arg, also scan the article headers.
+browsing with @code{browse-url}. With a prefix argument, browse with
+@code{shr-external-browser} instead.
@end table
(require 'gnus-util)
(require 'gmm-utils)
(require 'mm-decode)
+(require 'shr)
+(require 'url)
(require 'nnoo)
(eval-when-compile
(require 'subr-x))
(push primary urls))
(delete-dups urls)))
-(defun gnus-summary-browse-url (arg)
+(defun gnus-shorten-url (url max)
+ "Return an excerpt from URL."
+ (if (<= (length url) max)
+ url
+ (let ((parsed (url-generic-parse-url url)))
+ (concat (url-host parsed)
+ "..."
+ (substring (url-filename parsed)
+ (- (length (url-filename parsed))
+ (max (- max (length (url-host parsed))) 0)))))))
+
+(defun gnus-summary-browse-url (&optional external)
"Scan the current article body for links, and offer to browse them.
-With prefix ARG, also collect links from message headers.
-Links are opened using `browse-url'. If only one link is found,
-browse that directly, otherwise use completion to select a link.
-The first link marked in the article text with
-`gnus-collect-urls-primary-text' is the default."
+Links are opened using `browse-url' unless a prefix argument is
+given: Then `shr-external-browser' is used instead.
+
+If only one link is found, browse that directly, otherwise use
+completion to select a link. The first link marked in the
+article text with `gnus-collect-urls-primary-text' is the
+default."
(interactive "P")
(let (urls target)
(gnus-summary-select-article)
(gnus-configure-windows 'article)
(gnus-with-article-buffer
- (if arg
- (goto-char (point-min))
- (article-goto-body)
- ;; Back up a char, in case body starts with a widget.
- (backward-char))
+ (article-goto-body)
+ ;; Back up a char, in case body starts with a widget.
+ (backward-char)
(setq urls (gnus-collect-urls))
(setq target
(cond ((= (length urls) 1)
(car urls))
((> (length urls) 1)
- (completing-read "URL to browse: " urls nil t (car urls)))))
+ (completing-read (format "URL to browse (default %s): "
+ (gnus-shorten-url (car urls) 40))
+ urls nil t nil nil
+ (car urls)))))
(if target
- (browse-url target)
+ (if external
+ (funcall shr-external-browser target)
+ (browse-url target))
(message "No URLs found.")))))
(defun gnus-summary-isearch-article (&optional regexp-p)