all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 34052@debbugs.gnu.org
Subject: bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
Date: Sun, 23 Jun 2019 08:30:24 -0700	[thread overview]
Message-ID: <87zhm8uxnz.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <m34l4gv6n7.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 23 Jun 2019 14:16:28 +0200")

[-- Attachment #1: Type: text/plain, Size: 2000 bytes --]


On 06/23/19 14:16 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I think once I was using widget-forward to collect buttons, it seemed
>> natural to be able to handle all the types of buttons, not just URLs.
>> For instance, I'd like to be able to start composing messages to mailto:
>> buttons.
>
> Hm...  I think that sounds less useful, really.  In 99.9% of the cases,
> you don't want to hit anything but the URLs, I think, and "polluting"
> the list of URLs with mailto: stuff would make the feature more
> cumbersome to use, in my opinion.
>
>> Then the only reliable way to "do" what the button does was to
>> press it. Later Eric Fraga posted a variant that checked if the URL was
>> a http URL, and used `browse-url' directly in that case. The whole
>> function could be a lot simpler if we only collected http links. Though
>> I'd still like to compose messages to email addresses...
>
> If we want to have a "collect mailto: addresses" thing, that could be a
> separate command.
>
>> I'm posting the most recent version of the function below. Another bad
>> thing is does is tries to manage window state, returning the
>> summary/article config to what it was before clicking links, and I think
>> that should be removed -- it's fragile, and none of the other
>> summary/article commands do that.
>
> Yeah, good point.

Okay, all sounds good. Here's a proper commit, with docs. I've bound it
to both "w" and "A w".

My only problem is, right now I'm getting URLs out of the buttons like
so:

(or (get-text-property (point) 'shr-url)
    (get-text-property (point) 'gnus-string))

In my experiments, I've only found http URLs from 'gnus-string not
'shr-url, and the 'gnus-string values also include things like email
addresses. (I just noticed that having the `url-handler-mode' minor mode
enabled breaks `browse-url's ability to browse mailto: links.)

I could just filter URLs out based on a "http" prefix, but it still
feels a bit limited. WDYT?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-gnus-summary-browse-url.patch --]
[-- Type: text/x-patch, Size: 3458 bytes --]

From 4bdb41c7aa25a063334e758e5a2728fcf27be42b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sun, 23 Jun 2019 08:09:23 -0700
Subject: [PATCH] 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 | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index ba3a0e9b2e..28f000c489 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10154,6 +10154,17 @@ Article Commands
 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 8fdb766584..20921878eb 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1983,6 +1983,7 @@ gnus-article-commands-menu
   "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 @@ gnus-article-commands-menu
   "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,43 @@ gnus-summary-widget-backward
       (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))))
+	  (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."
-- 
2.22.0


  reply	other threads:[~2019-06-23 15:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-12 21:59 bug#34052: 27.0.50; New command gnus-summary-press-button Eric Abrahamsen
     [not found] ` <handler.34052.B.154733083721114.ack@debbugs.gnu.org>
2019-01-30 21:31   ` bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button) Eric Abrahamsen
2019-06-22 13:10     ` Lars Ingebrigtsen
2019-06-22 16:38       ` Eric Abrahamsen
2019-06-23 12:16         ` Lars Ingebrigtsen
2019-06-23 15:30           ` Eric Abrahamsen [this message]
2019-06-23 15:32             ` Lars Ingebrigtsen
2019-06-23 15:59               ` Eric Abrahamsen
2019-06-23 16:17                 ` Lars Ingebrigtsen
2019-06-23 16:37                   ` Eric Abrahamsen
2019-06-23 16:50                     ` Lars Ingebrigtsen
2019-06-23 17:06                       ` Eric Abrahamsen
2019-06-23 17:09                         ` Lars Ingebrigtsen
2019-06-23 17:31                           ` Eric Abrahamsen
2019-06-23 17:07                       ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zhm8uxnz.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=34052@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.