diff options
| author | Lars Ingebrigtsen | 2019-07-25 20:11:33 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-07-25 20:11:33 +0200 |
| commit | 7f0b69e8ed4ea0fd03ac779d8c6af809f991d357 (patch) | |
| tree | 18dcd1b88bfbc6cdb4d6798b0aa3f77df62f4d1f | |
| parent | bb2115fd5514497ce3dc94368388cdb82e17bb76 (diff) | |
| download | emacs-7f0b69e8ed4ea0fd03ac779d8c6af809f991d357.tar.gz emacs-7f0b69e8ed4ea0fd03ac779d8c6af809f991d357.zip | |
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.
| -rw-r--r-- | doc/misc/gnus.texi | 4 | ||||
| -rw-r--r-- | lisp/gnus/gnus-sum.el | 44 |
2 files changed, 33 insertions, 15 deletions
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi index f688e84e7e8..cc6873cfcb4 100644 --- a/doc/misc/gnus.texi +++ b/doc/misc/gnus.texi | |||
| @@ -10163,8 +10163,8 @@ do so. | |||
| 10163 | @cindex url | 10163 | @cindex url |
| 10164 | @findex gnus-summary-browse-url | 10164 | @findex gnus-summary-browse-url |
| 10165 | Scan the article buffer for links, and offer them to the user for | 10165 | Scan the article buffer for links, and offer them to the user for |
| 10166 | browsing with @code{browse-url}. By default, only scan the article | 10166 | browsing with @code{browse-url}. With a prefix argument, browse with |
| 10167 | body; with a prefix arg, also scan the article headers. | 10167 | @code{shr-external-browser} instead. |
| 10168 | 10168 | ||
| 10169 | @end table | 10169 | @end table |
| 10170 | 10170 | ||
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 @@ | |||
| 67 | (require 'gnus-util) | 67 | (require 'gnus-util) |
| 68 | (require 'gmm-utils) | 68 | (require 'gmm-utils) |
| 69 | (require 'mm-decode) | 69 | (require 'mm-decode) |
| 70 | (require 'shr) | ||
| 71 | (require 'url) | ||
| 70 | (require 'nnoo) | 72 | (require 'nnoo) |
| 71 | (eval-when-compile | 73 | (eval-when-compile |
| 72 | (require 'subr-x)) | 74 | (require 'subr-x)) |
| @@ -9461,32 +9463,48 @@ The 1st element is the widget named by `gnus-collect-urls-primary-text'." | |||
| 9461 | (push primary urls)) | 9463 | (push primary urls)) |
| 9462 | (delete-dups urls))) | 9464 | (delete-dups urls))) |
| 9463 | 9465 | ||
| 9464 | (defun gnus-summary-browse-url (arg) | 9466 | (defun gnus-shorten-url (url max) |
| 9467 | "Return an excerpt from URL." | ||
| 9468 | (if (<= (length url) max) | ||
| 9469 | url | ||
| 9470 | (let ((parsed (url-generic-parse-url url))) | ||
| 9471 | (concat (url-host parsed) | ||
| 9472 | "..." | ||
| 9473 | (substring (url-filename parsed) | ||
| 9474 | (- (length (url-filename parsed)) | ||
| 9475 | (max (- max (length (url-host parsed))) 0))))))) | ||
| 9476 | |||
| 9477 | (defun gnus-summary-browse-url (&optional external) | ||
| 9465 | "Scan the current article body for links, and offer to browse them. | 9478 | "Scan the current article body for links, and offer to browse them. |
| 9466 | With prefix ARG, also collect links from message headers. | ||
| 9467 | 9479 | ||
| 9468 | Links are opened using `browse-url'. If only one link is found, | 9480 | Links are opened using `browse-url' unless a prefix argument is |
| 9469 | browse that directly, otherwise use completion to select a link. | 9481 | given: Then `shr-external-browser' is used instead. |
| 9470 | The first link marked in the article text with | 9482 | |
| 9471 | `gnus-collect-urls-primary-text' is the default." | 9483 | If only one link is found, browse that directly, otherwise use |
| 9484 | completion to select a link. The first link marked in the | ||
| 9485 | article text with `gnus-collect-urls-primary-text' is the | ||
| 9486 | default." | ||
| 9472 | (interactive "P") | 9487 | (interactive "P") |
| 9473 | (let (urls target) | 9488 | (let (urls target) |
| 9474 | (gnus-summary-select-article) | 9489 | (gnus-summary-select-article) |
| 9475 | (gnus-configure-windows 'article) | 9490 | (gnus-configure-windows 'article) |
| 9476 | (gnus-with-article-buffer | 9491 | (gnus-with-article-buffer |
| 9477 | (if arg | 9492 | (article-goto-body) |
| 9478 | (goto-char (point-min)) | 9493 | ;; Back up a char, in case body starts with a widget. |
| 9479 | (article-goto-body) | 9494 | (backward-char) |
| 9480 | ;; Back up a char, in case body starts with a widget. | ||
| 9481 | (backward-char)) | ||
| 9482 | (setq urls (gnus-collect-urls)) | 9495 | (setq urls (gnus-collect-urls)) |
| 9483 | (setq target | 9496 | (setq target |
| 9484 | (cond ((= (length urls) 1) | 9497 | (cond ((= (length urls) 1) |
| 9485 | (car urls)) | 9498 | (car urls)) |
| 9486 | ((> (length urls) 1) | 9499 | ((> (length urls) 1) |
| 9487 | (completing-read "URL to browse: " urls nil t (car urls))))) | 9500 | (completing-read (format "URL to browse (default %s): " |
| 9501 | (gnus-shorten-url (car urls) 40)) | ||
| 9502 | urls nil t nil nil | ||
| 9503 | (car urls))))) | ||
| 9488 | (if target | 9504 | (if target |
| 9489 | (browse-url target) | 9505 | (if external |
| 9506 | (funcall shr-external-browser target) | ||
| 9507 | (browse-url target)) | ||
| 9490 | (message "No URLs found."))))) | 9508 | (message "No URLs found."))))) |
| 9491 | 9509 | ||
| 9492 | (defun gnus-summary-isearch-article (&optional regexp-p) | 9510 | (defun gnus-summary-isearch-article (&optional regexp-p) |