emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 55cb14b: New command gnus-summary-browse-url


From: Eric Abrahamsen
Subject: [Emacs-diffs] master 55cb14b: New command gnus-summary-browse-url
Date: Sun, 23 Jun 2019 13:05:49 -0400 (EDT)

branch: master
commit 55cb14bfa036991183a3895506a87536befbb9ca
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    New command gnus-summary-browse-url
    
    * lisp/gnus/gnus-sum.el (gnus-summary-browse-url): New command for
      browsing URLs from the article buffer from the summary buffer.
      (gnus-summary-mode-map): Bind to "w".
      (gnus-summary-article-map): And to "A w".
    * doc/misc/gnus.texi (Article Commands): Document.
---
 doc/misc/gnus.texi    | 11 +++++++++++
 lisp/gnus/gnus-sum.el | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index ba3a0e9..28f000c 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10154,6 +10154,17 @@ partial article, and want to see the complete article 
instead, then
 the @kbd{A C} command (@code{gnus-summary-show-complete-article}) will
 do so.
 
+@item w
+@itemx A w
+@kindex w @r{(Summary)}
+@kindex A w @r{(Summary)}
+@cindex web
+@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.
+
 @end table
 
 
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 8fdb766..621ba3e 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1983,6 +1983,7 @@ increase the score of each group you read."
   "s" gnus-summary-isearch-article
   "\t" gnus-summary-widget-forward
   [backtab] gnus-summary-widget-backward
+  "w" gnus-summary-browse-url
   "t" gnus-summary-toggle-header
   "g" gnus-summary-show-article
   "l" gnus-summary-goto-last-article
@@ -2149,6 +2150,7 @@ increase the score of each group you read."
   "s" gnus-summary-isearch-article
   "\t" gnus-summary-widget-forward
   [backtab] gnus-summary-widget-backward
+  "w" gnus-summary-browse-url
   "P" gnus-summary-print-article
   "S" gnus-sticky-article
   "M" gnus-mailing-list-insinuate
@@ -9432,6 +9434,44 @@ With optional ARG, move across that many fields."
       (goto-char (point-max)))
     (widget-backward arg)))
 
+(defun gnus-summary-browse-url (arg)
+  "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."
+  (interactive "P")
+  (let (pt 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))
+      (setq pt (point))
+      (while (progn (widget-forward 1)
+                   ;; `widget-forward' wraps around to top of
+                   ;; buffer.
+                   (> (point) pt))
+       (setq pt (point))
+       (when-let ((u (or (get-text-property (point) 'shr-url)
+                         (get-text-property (point) 'gnus-string))))
+         (when (string-match-p "\\`[[:alpha:]]+://" u)
+           (push u urls))))
+      (setq target
+           (cond ((= (length urls) 1)
+                  (car urls))
+                 ((> (length urls) 1)
+                  (completing-read
+                   "URL to browse: "
+                   (setq urls (nreverse (delete-dups urls)))
+                   nil t))))
+      (if target
+         (browse-url target)
+       (message "No URLs found.")))))
+
 (defun gnus-summary-isearch-article (&optional regexp-p)
   "Do incremental search forward on the current article.
 If REGEXP-P (the prefix) is non-nil, do regexp isearch."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]