diff options
| author | Lars Ingebrigtsen <larsi@gnus.org> | 2019-07-25 20:11:33 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen <larsi@gnus.org> | 2019-07-25 20:11:33 +0200 |
| commit | 7f0b69e8ed4ea0fd03ac779d8c6af809f991d357 (patch) | |
| tree | 18dcd1b88bfbc6cdb4d6798b0aa3f77df62f4d1f /lisp/gnus/gnus-sum.el | |
| parent | bb2115fd5514497ce3dc94368388cdb82e17bb76 (diff) | |
| download | emacs-7f0b69e8ed4ea0fd03ac779d8c6af809f991d357.tar.gz | |
Make `C-u w' in the Gnus Summary buffer open externally
* doc/misc/gnus.texi (Article Commands): Document new behaviour.
* lisp/gnus/gnus-sum.el (gnus-shorten-url): New function.
(gnus-summary-browse-url): Change function to make `C-u' use the
external browser (as Gnus does when you hit URLs manually). Don't
use an initial input.
Diffstat (limited to 'lisp/gnus/gnus-sum.el')
| -rw-r--r-- | lisp/gnus/gnus-sum.el | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el index 06d3db81257..ec807bd4789 100644 --- a/lisp/gnus/gnus-sum.el +++ b/lisp/gnus/gnus-sum.el @@ -67,6 +67,8 @@ (require 'gnus-util) (require 'gmm-utils) (require 'mm-decode) +(require 'shr) +(require 'url) (require 'nnoo) (eval-when-compile (require 'subr-x)) @@ -9461,32 +9463,48 @@ The 1st element is the widget named by `gnus-collect-urls-primary-text'." (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) |
