unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34052: 27.0.50; New command gnus-summary-press-button
@ 2019-01-12 21:59 Eric Abrahamsen
       [not found] ` <handler.34052.B.154733083721114.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-01-12 21:59 UTC (permalink / raw)
  To: 34052

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

The attached patch adds a new Gnus summary buffer command, that clicks a
link in the article buffer. Technically, it calls `widget-button-press'
on one of the widgets in the article buffer, offering completion if
there's more than one. I'm not sure I've handled all the possible values
of the 'gnus-data text property, but more would be easy to add.

Basically this just lets you follow a link without actually moving point
or the mouse into the article buffer.


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

From 3f85945b445fe5871fe14b0b5f4a337ac3e64b9b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sat, 12 Jan 2019 13:44:23 -0800
Subject: [PATCH] New command gnus-summary-press-button

* lisp/gnus/gnus-sum.el (gnus-summary-press-button): Summary buffer
  command to press a button in the article buffer. Uses completion to
  choose one of the buttons.
* doc/misc/gnus.texi (Article Commands): Document.
---
 doc/misc/gnus.texi    | 11 ++++++++
 lisp/gnus/gnus-sum.el | 63 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 2862264312..de7291b2a9 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10156,6 +10156,17 @@ Article Commands
 the @kbd{A C} command (@code{gnus-summary-show-complete-article}) will
 do so.
 
+@item A l
+@cindex buttons
+@findex gnus-summary-press-button
+@kindex A l @r{(Summary)}
+Press one of the button widgets in the article buffer.  This behaves
+as if the user had navigated into the article buffer and pressed
+@key{RET} on a widget.  If there is more than one button widget, the
+button text is used for completion.  With a prefix arg, allow
+selection of buttons in the message headers, in addition to the
+message body.
+
 @end table
 
 
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 911bf89f23..d765c67492 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2101,6 +2101,7 @@ gnus-article-commands-menu
   "g" gnus-summary-show-article
   "s" gnus-summary-isearch-article
   "\t" gnus-summary-widget-forward
+  "l" gnus-summary-press-button
   [backtab] gnus-summary-widget-backward
   "P" gnus-summary-print-article
   "S" gnus-sticky-article
@@ -9368,6 +9369,68 @@ gnus-summary-widget-backward
     (goto-char (point-max)))
   (widget-backward arg))
 
+(defun gnus-summary-press-button (arg)
+  "From the *Summary* buffer, \"press\" an article button.
+With prefix ARG, offer buttons in the message headers as well as
+body.
+
+If only one button is found, press that directly, otherwise use
+completion to select a button.  Buttons are pressed using
+`widget-button-press'."
+  (interactive "P")
+  (let ((opened (and (gnus-buffer-live-p gnus-article-buffer)
+		     (get-buffer-window gnus-article-buffer t)
+		     ;; We might have opened an article, but then moved to
+		     ;; a different summary line.
+		     (= gnus-current-article (gnus-summary-article-number))))
+	pt urls target)
+    (unless opened
+      (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)
+		    (> (point) pt))
+	(setq pt (point))
+	(when-let ((u (cond
+		       ((get-text-property (point) 'shr-url))
+		       ((get-text-property (point) 'gnus-string))
+		       ((let ((dat (get-text-property (point) 'gnus-data)))
+			  (pcase dat
+			    ('nil nil)
+			    ((and (pred (stringp) (pred (string= ">"))))
+			     (buffer-substring (line-beginning-position)
+					       (line-end-position)))
+			    ;; Does a marker always signify the
+			    ;; signature?  We may never know.
+			    ((pred (markerp))
+			     "<signature>")
+			    ;; There are more weird cases, add as
+			    ;; necessary.
+			    (_ dat)))))))
+	  (push (cons u pt) urls)))
+      (setq target
+	    (assoc (cond ((= (length urls) 1)
+			  (caar urls))
+			 ((> (length urls) 1)
+			  (completing-read "URL to browse: "
+					   (delete-dups urls) nil t)))
+		   urls))
+      (if target
+	  (funcall-interactively #'widget-button-press (1+ (cdr target)))
+	(message "No URLs found.")))
+    ;; Now what?  If we're not in the *Summary* buffer anymore (i.e.,
+    ;; pressing the button created a new buffer), do nothing.
+    ;; Otherwise, if the article wasn't opened to begin with, close it
+    ;; after we follow the link.
+    (when (get-buffer-window gnus-summary-buffer)
+      (gnus-summary-expand-window opened))))
+
 (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.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
       [not found] ` <handler.34052.B.154733083721114.ack@debbugs.gnu.org>
@ 2019-01-30 21:31   ` Eric Abrahamsen
  2019-06-22 13:10     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-01-30 21:31 UTC (permalink / raw)
  To: 34052

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

Here's a new (lightly user-tested) version of the command. I guess if
there's no objection I'll push this in a few days.

Eric


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

From 6f9e518bccee479a11114a128bdafb95f80539b7 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sat, 12 Jan 2019 13:44:23 -0800
Subject: [PATCH] New command gnus-summary-press-button

* lisp/gnus/gnus-sum.el (gnus-summary-press-button): Summary buffer
  command to press a button in the article buffer. Uses completion to
  choose one of the buttons.
* doc/misc/gnus.texi (Article Commands): Document.
---
 doc/misc/gnus.texi    | 11 +++++++
 lisp/gnus/gnus-sum.el | 70 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 2862264312..de7291b2a9 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10156,6 +10156,17 @@ Article Commands
 the @kbd{A C} command (@code{gnus-summary-show-complete-article}) will
 do so.
 
+@item A l
+@cindex buttons
+@findex gnus-summary-press-button
+@kindex A l @r{(Summary)}
+Press one of the button widgets in the article buffer.  This behaves
+as if the user had navigated into the article buffer and pressed
+@key{RET} on a widget.  If there is more than one button widget, the
+button text is used for completion.  With a prefix arg, allow
+selection of buttons in the message headers, in addition to the
+message body.
+
 @end table
 
 
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 911bf89f23..d3e3ff1927 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2101,6 +2101,7 @@ gnus-article-commands-menu
   "g" gnus-summary-show-article
   "s" gnus-summary-isearch-article
   "\t" gnus-summary-widget-forward
+  "l" gnus-summary-press-button
   [backtab] gnus-summary-widget-backward
   "P" gnus-summary-print-article
   "S" gnus-sticky-article
@@ -9368,6 +9369,75 @@ gnus-summary-widget-backward
     (goto-char (point-max)))
   (widget-backward arg))
 
+(defun gnus-summary-press-button (arg)
+  "Scan the current article body for buttons, and offer to press them.
+With prefix ARG, also collect buttons from message headers.
+
+Buttons are pressed using `widget-button-press'.  If only one
+button is found, press that directly, otherwise use completion to
+select a button."
+  (interactive "P")
+  (let ((opened (and (gnus-buffer-live-p gnus-article-buffer)
+		     (get-buffer-window gnus-article-buffer t)
+		     ;; We might have opened an article, but then moved to
+		     ;; a different summary line.
+		     (= gnus-current-article (gnus-summary-article-number))))
+	pt buttons target)
+    (unless opened
+      (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)
+		    (> (point) pt))
+	(setq pt (point))
+	(when-let ((u (cond
+		       ((get-text-property (point) 'shr-url))
+		       ((get-text-property (point) 'gnus-string))
+		       ((let ((dat (get-text-property (point) 'gnus-data)))
+			  (pcase dat
+			    ('nil nil)
+			    ((and (pred stringp) (pred (string-match-p "^>")))
+			     ;; This is a "so-and-so wrote:" quote.
+			     (buffer-substring-no-properties
+			      (line-beginning-position) (line-end-position)))
+			    ;; Does a marker always signify the
+			    ;; signature?  We may never know.
+			    ((pred markerp)
+			     "<signature>")
+			    ;; Sometimes this is also a "so-and-so wrote" quote.
+			    (`(((,(and (pred markerp) start) .
+				 ,(and (pred markerp) end)))
+			       _)
+			     (buffer-substring-no-properties start end))
+			    ;; There are more weird cases, add as
+			    ;; necessary.
+			    ((pred stringp) dat)))))))
+	  (push (cons u pt) buttons)))
+      (setq target
+	    (assoc (cond ((= (length buttons) 1)
+			  (caar buttons))
+			 ((> (length buttons) 1)
+			  (completing-read
+			   "URL to browse: "
+			   (setq buttons (nreverse (delete-dups buttons)))
+			   nil t)))
+		   buttons))
+      (if target
+	  (funcall-interactively #'widget-button-press (1+ (cdr target)))
+	(message "No buttons found.")))
+    ;; Now what?  If we're not in the *Summary* buffer anymore (i.e.,
+    ;; pressing the button created a new buffer), do nothing.
+    ;; Otherwise, if the article wasn't opened to begin with, close it
+    ;; after we follow the link.
+    (when (get-buffer-window gnus-summary-buffer)
+      (gnus-summary-expand-window opened))))
+
 (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.20.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-22 13:10 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Here's a new (lightly user-tested) version of the command. I guess if
> there's no objection I'll push this in a few days.

*taps calendar*

Looks good to me, but as I said over on the ding mailing list:

> +@item A l

I think this is such a useful command that we should bind it to `w'
instead.  Or some other unused single key keystroke.

> +      (if target
> +	  (funcall-interactively #'widget-button-press (1+ (cdr target)))

And I didn't quite get why you're not just using browse-url directly
here, which seems less fragile and more controllable.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-22 13:10     ` Lars Ingebrigtsen
@ 2019-06-22 16:38       ` Eric Abrahamsen
  2019-06-23 12:16         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-22 16:38 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Here's a new (lightly user-tested) version of the command. I guess if
>> there's no objection I'll push this in a few days.
>
> *taps calendar*

Ahem...

> Looks good to me, but as I said over on the ding mailing list:
>
>> +@item A l
>
> I think this is such a useful command that we should bind it to `w'
> instead.  Or some other unused single key keystroke.

No objection here.

>> + (if target
>> + (funcall-interactively #'widget-button-press (1+ (cdr target)))
>
> And I didn't quite get why you're not just using browse-url directly
> here, which seems less fragile and more controllable.

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. 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...

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.

Anyway, let me know what you think about the button vs link issue...

#+begin_src elisp
(defun gnus-summary-press-button (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 `widget-button-press'.  If only one link
is found, browse that directly, otherwise use completion to
select a link."
  (interactive "P")
  (let ((opened (and (gnus-buffer-live-p gnus-article-buffer)
		     (get-buffer-window gnus-article-buffer t)
		     ;; We might have opened an article, but then moved to
		     ;; a different summary line.
		     (= gnus-current-article (gnus-summary-article-number))))
	(wc (current-window-configuration))
	pt urls target)
    (unless opened
      (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)
		    (> (point) pt))
	(setq pt (point))
	(when-let ((u (cond
		       ((get-text-property (point) 'shr-url))
		       ((get-text-property (point) 'gnus-string))
		       ((let ((dat (get-text-property (point) 'gnus-data)))
			  (pcase dat
			    ('nil nil)
			    ((and (pred stringp) (pred (string-match-p "^>")))
			     ;; This is a "so-and-so wrote:" quote.
			     (buffer-substring-no-properties
			      (line-beginning-position) (line-end-position)))
			    ;; Does a marker always signify the
			    ;; signature?  We may never know.
			    ((pred markerp)
			     "<signature>")
			    ;; Sometimes this is also a "so-and-so wrote" quote.
			    (`(((,(and (pred markerp) start) .
				 ,(and (pred markerp) end))) _)
			     (buffer-substring-no-properties start end))
			    ;; There are more weird cases, add as
			    ;; necessary.
			    ((pred stringp) dat)))))))
	  (push (cons u pt) urls)))
      (setq target
	    (assoc (cond ((= (length urls) 1)
			  (caar urls))
			 ((> (length urls) 1)
			  (completing-read "URL to browse: "
					   (setq urls (nreverse (delete-dups urls)))
					   nil t)))
		   urls))
      (if target
	  (funcall-interactively #'widget-button-press (1+ (cdr target)))
	(message "No URLs found.")))
    ;; Now what?  If pressing the button changed our window layout, do
    ;; nothing.  Otherwise, if the article wasn't opened to begin
    ;; with, close it after we follow the link.
    (unless (equal wc (current-window-configuration))
      (gnus-summary-expand-window opened))))
#+end_src





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-22 16:38       ` Eric Abrahamsen
@ 2019-06-23 12:16         ` Lars Ingebrigtsen
  2019-06-23 15:30           ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 12:16 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

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.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 12:16         ` Lars Ingebrigtsen
@ 2019-06-23 15:30           ` Eric Abrahamsen
  2019-06-23 15:32             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 15:30 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052

[-- 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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 15:30           ` Eric Abrahamsen
@ 2019-06-23 15:32             ` Lars Ingebrigtsen
  2019-06-23 15:59               ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 15:32 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

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

I think explicitly filtering out some URL schemes instead would be nice,
because you want file: and data: and ftp: to work, perhaps...

So just filter out the mailto: ones?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 15:32             ` Lars Ingebrigtsen
@ 2019-06-23 15:59               ` Eric Abrahamsen
  2019-06-23 16:17                 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 15:59 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I could just filter URLs out based on a "http" prefix, but it still
>> feels a bit limited. WDYT?
>
> I think explicitly filtering out some URL schemes instead would be nice,
> because you want file: and data: and ftp: to work, perhaps...
>
> So just filter out the mailto: ones?

The problem is, there are 'gnus-string properties that just look like
"larsi@gnus.org", ie no scheme at all. I suppose we could just drop
anything that doesn't look like "`[a-z]+://"...





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 15:59               ` Eric Abrahamsen
@ 2019-06-23 16:17                 ` Lars Ingebrigtsen
  2019-06-23 16:37                   ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 16:17 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> The problem is, there are 'gnus-string properties that just look like
> "larsi@gnus.org", ie no scheme at all. I suppose we could just drop
> anything that doesn't look like "`[a-z]+://"...

Oh, I didn't quite get what you were saying about `gnus-string' and
`shr-url'.

In my Gnus buffers, the URLs all have `shr-url' on them:

(text-property-search-forward 'gnus-string)
=> nil

in an HTML article that has links...

(text-property-search-forward 'shr-url)
=> #s(prop-match 202 206 "http://9gag.com/gag/av8Kj8n")

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 16:17                 ` Lars Ingebrigtsen
@ 2019-06-23 16:37                   ` Eric Abrahamsen
  2019-06-23 16:50                     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 16:37 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052


On 06/23/19 18:17 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> The problem is, there are 'gnus-string properties that just look like
>> "larsi@gnus.org", ie no scheme at all. I suppose we could just drop
>> anything that doesn't look like "`[a-z]+://"...
>
> Oh, I didn't quite get what you were saying about `gnus-string' and
> `shr-url'.
>
> In my Gnus buffers, the URLs all have `shr-url' on them:
>
> (text-property-search-forward 'gnus-string)
> => nil
>
> in an HTML article that has links...
>
> (text-property-search-forward 'shr-url)
> => #s(prop-match 202 206 "http://9gag.com/gag/av8Kj8n")

Yeah, I'm just viewing the plain text. We'll want to support both plain
and html versions, so I think scanning for both properties is still
desirable. What do you think about just dropping scheme-less URLs?





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  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:07                       ` Eric Abrahamsen
  0 siblings, 2 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 16:50 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Yeah, I'm just viewing the plain text. We'll want to support both plain
> and html versions, so I think scanning for both properties is still
> desirable. 

Oh, yeah, plain text...

> What do you think about just dropping scheme-less URLs?

Yup; sounds good.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  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:07                       ` Eric Abrahamsen
  1 sibling, 1 reply; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 17:06 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Yeah, I'm just viewing the plain text. We'll want to support both plain
>> and html versions, so I think scanning for both properties is still
>> desirable. 
>
> Oh, yeah, plain text...
>
>> What do you think about just dropping scheme-less URLs?
>
> Yup; sounds good.

Done and pushed.

Thanks!
Eric





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 16:50                     ` Lars Ingebrigtsen
  2019-06-23 17:06                       ` Eric Abrahamsen
@ 2019-06-23 17:07                       ` Eric Abrahamsen
  1 sibling, 0 replies; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 17:07 UTC (permalink / raw)
  To: 34052-done

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Yeah, I'm just viewing the plain text. We'll want to support both plain
>> and html versions, so I think scanning for both properties is still
>> desirable. 
>
> Oh, yeah, plain text...
>
>> What do you think about just dropping scheme-less URLs?
>
> Yup; sounds good.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 17:06                       ` Eric Abrahamsen
@ 2019-06-23 17:09                         ` Lars Ingebrigtsen
  2019-06-23 17:31                           ` Eric Abrahamsen
  0 siblings, 1 reply; 15+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 17:09 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: 34052

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Done and pushed.

Great!  This probably warrants a NEWS entry, too.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 15+ messages in thread

* bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
  2019-06-23 17:09                         ` Lars Ingebrigtsen
@ 2019-06-23 17:31                           ` Eric Abrahamsen
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Abrahamsen @ 2019-06-23 17:31 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 34052


On 06/23/19 19:09 PM, Lars Ingebrigtsen wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Done and pushed.
>
> Great!  This probably warrants a NEWS entry, too.

Aha. That's in as well.





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-06-23 17:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).