Gnus development mailing list
 help / color / mirror / Atom feed
* hackernews & gnus-summary-browse-url
@ 2022-03-07 21:44 Sam Steingold
  2022-03-07 23:40 ` Eric Abrahamsen
  0 siblings, 1 reply; 13+ messages in thread
From: Sam Steingold @ 2022-03-07 21:44 UTC (permalink / raw)
  To: ding

Hi,
I read gwene.com.ycombinator.news where each article is 2 words:

--8<---------------cut here---------------start------------->8---
Comments 

Link
--8<---------------cut here---------------end--------------->8---

both are links.

"w" (gnus-summary-browse-url) opens one of then ("Link" by default)
while I would rather open _both_.

What are my options?

1. Modify `gnus-summary-browseurl' so that when the prefix arg is a
number, it opens all the urls returned by `gnus-collect-urls'.
(The ordinary C-u prefix is used for selecting
`browse-url-secondary-browser-function').
-- drawback: unlikely to be welcomed in the trunk

2. Hit "w" twice: "w RET cmd-TAB w TAB TAB RET"
-- drawback: too many keystrokes

3. Make `gnus-collect-urls-primary-text' have value "Comments" when in
the YN group (using `gnus-summary-prepare-hook'?)
This way "w RET" will give me comments and the comments always have a
link to the article.
-- drawback: I get just the comments and have to click again to get the article

2*3. Hit "w TAB TAB RET"
yuk

Ideally, the *Article* buffer should not be shown at all, but this is a bonus...

Please note that this is only relevant to one single group (which has
extra high volume, so efficiency is needed).

Suggestions are welcome.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://www.peaceandtolerance.org/ http://think-israel.org
I don't know how many problems I have because math is one of them.



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-07 21:44 hackernews & gnus-summary-browse-url Sam Steingold
@ 2022-03-07 23:40 ` Eric Abrahamsen
  2022-03-08 15:05   ` Sam Steingold
  0 siblings, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2022-03-07 23:40 UTC (permalink / raw)
  To: ding

Sam Steingold <sds@gnu.org> writes:

> Hi,
> I read gwene.com.ycombinator.news where each article is 2 words:
>
> Comments 
>
> Link
>
> both are links.

Opening hackernews links was exactly why I wrote
`gnus-summary-browse-url' in the first place :)

> "w" (gnus-summary-browse-url) opens one of then ("Link" by default)
> while I would rather open _both_.
>
> What are my options?

Set `gnus-collect-urls-primary-text' to nil.



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-07 23:40 ` Eric Abrahamsen
@ 2022-03-08 15:05   ` Sam Steingold
  2022-03-08 15:23     ` Lars Ingebrigtsen
  2022-03-08 16:35     ` dick
  0 siblings, 2 replies; 13+ messages in thread
From: Sam Steingold @ 2022-03-08 15:05 UTC (permalink / raw)
  To: ding

> * Eric Abrahamsen <revp@revpnoenunzfra.arg> [2022-03-07 15:40:31 -0800]:
>
>> "w" (gnus-summary-browse-url) opens one of then ("Link" by default)
>> while I would rather open _both_.
>>
>> What are my options?
>
> Set `gnus-collect-urls-primary-text' to nil.

Nah, this just affects the _default_ for "w".
It does not let me open _both_ URLs in _one_ keystroke.
It also screws up the rest of gnus, where I _do_ want
`gnus-collect-urls-primary-text' to be "Link".

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://thereligionofpeace.com https://mideasttruth.com https://ij.org/
Things that cannot be programmed in assembler have to be soldered.



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 15:05   ` Sam Steingold
@ 2022-03-08 15:23     ` Lars Ingebrigtsen
  2022-03-08 15:56       ` Eric Abrahamsen
  2022-03-08 20:50       ` Sam Steingold
  2022-03-08 16:35     ` dick
  1 sibling, 2 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-08 15:23 UTC (permalink / raw)
  To: Sam Steingold; +Cc: ding

Sam Steingold <sds@gnu.org> writes:

> Nah, this just affects the _default_ for "w".
> It does not let me open _both_ URLs in _one_ keystroke.
> It also screws up the rest of gnus, where I _do_ want
> `gnus-collect-urls-primary-text' to be "Link".

I use:

(require 'gnus-sum)
(define-key gnus-summary-mode-map
  "w" (lambda ()
	(interactive)
	(let (urls target)
	  (gnus-summary-select-article)
	  (gnus-with-article-buffer
	    (article-goto-body)
	    ;; Back up a char, in case body starts with a button.
	    (backward-char)
	    (setq urls (gnus-collect-urls))
	    (setq target (car urls))
	    (if target
		(funcall browse-url-secondary-browser-function target)
	      (message "No URLs found."))))))

Alter to open both (car urls) and (car (last urls)).

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


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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 15:23     ` Lars Ingebrigtsen
@ 2022-03-08 15:56       ` Eric Abrahamsen
  2022-03-08 15:58         ` Lars Ingebrigtsen
  2022-03-08 20:50       ` Sam Steingold
  1 sibling, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2022-03-08 15:56 UTC (permalink / raw)
  To: ding

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Sam Steingold <sds@gnu.org> writes:
>
>> Nah, this just affects the _default_ for "w".
>> It does not let me open _both_ URLs in _one_ keystroke.
>> It also screws up the rest of gnus, where I _do_ want
>> `gnus-collect-urls-primary-text' to be "Link".
>
> I use:
>
> (require 'gnus-sum)
> (define-key gnus-summary-mode-map
>   "w" (lambda ()
> 	(interactive)
> 	(let (urls target)
> 	  (gnus-summary-select-article)
> 	  (gnus-with-article-buffer
> 	    (article-goto-body)
> 	    ;; Back up a char, in case body starts with a button.
> 	    (backward-char)
> 	    (setq urls (gnus-collect-urls))
> 	    (setq target (car urls))
> 	    (if target
> 		(funcall browse-url-secondary-browser-function target)
> 	      (message "No URLs found."))))))
>
> Alter to open both (car urls) and (car (last urls)).

Isn't that just about what `gnus-summary-browse-url' does anyway?



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 15:56       ` Eric Abrahamsen
@ 2022-03-08 15:58         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-08 15:58 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Isn't that just about what `gnus-summary-browse-url' does anyway?

Yes.  But the example code should be trivial to alter to do what he
wants.

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


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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 15:05   ` Sam Steingold
  2022-03-08 15:23     ` Lars Ingebrigtsen
@ 2022-03-08 16:35     ` dick
  1 sibling, 0 replies; 13+ messages in thread
From: dick @ 2022-03-08 16:35 UTC (permalink / raw)
  To: Sam Steingold; +Cc: ding

Not exactly what you want, but close enough:

(add-hook
 'gnus-summary-mode-hook
 (lambda ()
   (require 'url-http)
   (defvar url-http-end-of-headers)
   (when (equal (gnus-group-real-name gnus-newsgroup-name)
                "gwene.com.ycombinator.news")
     (make-local-variable 'gnus-article-prepare-hook)
     (add-to-list
      'gnus-article-prepare-hook
      (lambda ()
        (when (and (buffer-live-p (get-buffer gnus-original-article-buffer))
                   (buffer-live-p (get-buffer gnus-article-buffer)))
          (with-current-buffer gnus-original-article-buffer
            (when-let ((found (re-search-forward
                               "\"\\([^\"]+\\)\">Comments"
                               nil t))
                       (url (match-string 1))
                       (resbuf (url-retrieve-synchronously url t nil 5)))
	      (unwind-protect
		  (with-current-buffer gnus-article-buffer
		    (let ((inhibit-read-only t))
                      (message-goto-body)
                      (save-excursion (delete-region (point) (point-max)))
		      (shr-insert-document
		       (with-current-buffer resbuf
			 (libxml-parse-html-region (1+ url-http-end-of-headers)
						   (point-max))))))
		(kill-buffer resbuf))))))))))


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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 15:23     ` Lars Ingebrigtsen
  2022-03-08 15:56       ` Eric Abrahamsen
@ 2022-03-08 20:50       ` Sam Steingold
  2022-03-09 12:04         ` Lars Ingebrigtsen
  1 sibling, 1 reply; 13+ messages in thread
From: Sam Steingold @ 2022-03-08 20:50 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: ding

> * Lars Ingebrigtsen <ynefv@tahf.bet> [2022-03-08 16:23:58 +0100]:
>
> Sam Steingold <sds@gnu.org> writes:
>
>> Nah, this just affects the _default_ for "w".
>> It does not let me open _both_ URLs in _one_ keystroke.
>> It also screws up the rest of gnus, where I _do_ want
>> `gnus-collect-urls-primary-text' to be "Link".
>
> I use:
>
> (require 'gnus-sum)
> (define-key gnus-summary-mode-map
>   "w" (lambda ()
> 	(interactive)
> 	(let (urls target)
> 	  (gnus-summary-select-article)
> 	  (gnus-with-article-buffer
> 	    (article-goto-body)
> 	    ;; Back up a char, in case body starts with a button.
> 	    (backward-char)
> 	    (setq urls (gnus-collect-urls))
> 	    (setq target (car urls))
> 	    (if target
> 		(funcall browse-url-secondary-browser-function target)
> 	      (message "No URLs found."))))))
>
> Alter to open both (car urls) and (car (last urls)).

If you use it yourself, would you mind if I apply this patch?

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 1be5a48068..09170ff8ac 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2010,6 +2010,7 @@ :keymap
   "s" #'gnus-summary-isearch-article
   "TAB" #'gnus-summary-button-forward
   "<backtab>" #'gnus-summary-button-backward
+  "v" #'gnus-summary-browse-all-urls
   "w" #'gnus-summary-browse-url
   "t" #'gnus-summary-toggle-header
   "g" #'gnus-summary-show-article
@@ -2196,6 +2197,7 @@ :keymap
         "s" #'gnus-summary-isearch-article
         "TAB" #'gnus-summary-button-forward
         "<backtab>" #'gnus-summary-button-backward
+        "v" #'gnus-summary-browse-all-urls
         "w" #'gnus-summary-browse-url
         "P" #'gnus-summary-print-article
         "S" #'gnus-sticky-article
@@ -9445,6 +9447,16 @@ gnus-collect-urls
       (push primary urls))
     (delete-dups urls)))
 
+(defun gnus-collect-urls-from-article ()
+  "Select the article and return the list of URLs in it.
+See 'gnus-collect-urls'."
+  (gnus-summary-select-article)
+  (gnus-with-article-buffer
+    (article-goto-body)
+    ;; Back up a char, in case body starts with a button.
+    (backward-char)
+    (gnus-collect-urls)))
+
 (defun gnus-shorten-url (url max)
   "Return an excerpt from URL not exceeding MAX characters."
   (if (<= (length url) max)
@@ -9456,37 +9468,38 @@ gnus-shorten-url
                            (concat "#" target)))))
       (concat host (string-truncate-left rest (- max (length host)))))))
 
-(defun gnus-summary-browse-url (&optional external)
+(defun gnus-summary-browse-url (&optional _external)
   "Scan the current article body for links, and offer to browse them.
 
 Links are opened using `browse-url' unless a prefix argument is
-given: Then `browse-url-secondary-browser-function' is used instead.
+given: then `browse-url-secondary-browser-function' 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" gnus-summary-mode)
-  (let (urls target)
-    (gnus-summary-select-article)
-    (gnus-with-article-buffer
-      (article-goto-body)
-      ;; Back up a char, in case body starts with a button.
-      (backward-char)
-      (setq urls (gnus-collect-urls))
-      (setq target
-	    (cond ((= (length urls) 1)
-		   (car urls))
-		  ((> (length urls) 1)
-		   (completing-read
-		    (format-prompt "URL to browse"
-				   (gnus-shorten-url (car urls) 40))
-		    urls nil t nil nil (car urls)))))
-      (if target
-	  (if external
-	      (funcall browse-url-secondary-browser-function target)
-	    (browse-url target))
-	(message "No URLs found.")))))
+  (let* ((urls (gnus-collect-urls-from-article))
+         (target
+	  (cond ((= (length urls) 1)
+		 (car urls))
+		((> (length urls) 1)
+		 (completing-read
+		  (format-prompt "URL to browse"
+				 (gnus-shorten-url (car urls) 40))
+		  urls nil t nil nil (car urls))))))
+    (if target
+	(browse-url-button-open-url target)
+      (message "No URLs found."))))
+
+(defun gnus-summary-browse-all-urls (&optional _external)
+  "Scan the current article body for links, and browse them.
+
+Links are opened using `browse-url' unless a prefix argument is
+given: then `browse-url-secondary-browser-function' is used instead."
+  (interactive "P" gnus-summary-mode)
+  (dolist (url (gnus-collect-urls-from-article))
+    (browse-url-button-open-url url)))
 
 (defun gnus-summary-isearch-article (&optional regexp-p)
   "Do incremental search forward on the current article.
--8<---------------cut here---------------end--------------->8---




-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://www.peaceandtolerance.org/ https://thereligionofpeace.com
Yellow wine is called "white" because it is made out of green grapes.


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

* Re: hackernews & gnus-summary-browse-url
  2022-03-08 20:50       ` Sam Steingold
@ 2022-03-09 12:04         ` Lars Ingebrigtsen
  2022-03-09 19:41           ` Sam Steingold
  0 siblings, 1 reply; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-09 12:04 UTC (permalink / raw)
  To: Sam Steingold; +Cc: ding

Sam Steingold <sds@gnu.org> writes:

> If you use it yourself, would you mind if I apply this patch?

[...]

> +  "v" #'gnus-summary-browse-all-urls

I'm not sure that's generally useful enough to have as its own
command -- people will want to open different subsets of URLs in these
cases, and you kinda have to write some code for that.

[...]

> -(defun gnus-summary-browse-url (&optional external)
> +(defun gnus-summary-browse-url (&optional _external)
>    "Scan the current article body for links, and offer to browse them.
>
>  Links are opened using `browse-url' unless a prefix argument is
> -given: Then `browse-url-secondary-browser-function' is used instead.
> +given: then `browse-url-secondary-browser-function' is used instead.

And why are you removing the EXTERNAL logic?



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-09 12:04         ` Lars Ingebrigtsen
@ 2022-03-09 19:41           ` Sam Steingold
  2022-03-09 19:50             ` Eric Abrahamsen
  2022-03-12 17:38             ` Lars Ingebrigtsen
  0 siblings, 2 replies; 13+ messages in thread
From: Sam Steingold @ 2022-03-09 19:41 UTC (permalink / raw)
  To: ding

> * Lars Ingebrigtsen <ynefv@tahf.bet> [2022-03-09 13:04:29 +0100]:
>
> Sam Steingold <sds@gnu.org> writes:
>
>> If you use it yourself, would you mind if I apply this patch?
>
> [...]
>
>> +  "v" #'gnus-summary-browse-all-urls
>
> I'm not sure that's generally useful enough to have as its own
> command -- people will want to open different subsets of URLs in these
> cases, and you kinda have to write some code for that.

Right, but sometimes you want to open _all_ URLs, and this is a simple
way.
I can add bells and whistles (e.g., open _matching_ URLs), but that's an
overkill for now.

>> -(defun gnus-summary-browse-url (&optional external)
>> +(defun gnus-summary-browse-url (&optional _external)
>>    "Scan the current article body for links, and offer to browse them.
>>
>>  Links are opened using `browse-url' unless a prefix argument is
>> -given: Then `browse-url-secondary-browser-function' is used instead.
>> +given: then `browse-url-secondary-browser-function' is used instead.
>
> And why are you removing the EXTERNAL logic?

I am NOT!
I am merely moving this logic to browse-url-button-open-url where it has
been since it has been introduced!

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://jij.org https://memri.org https://www.dhimmitude.org
There are two ways to win an argument with a woman.  Neither works.



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-09 19:41           ` Sam Steingold
@ 2022-03-09 19:50             ` Eric Abrahamsen
  2022-03-09 21:20               ` Sam Steingold
  2022-03-12 17:38             ` Lars Ingebrigtsen
  1 sibling, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2022-03-09 19:50 UTC (permalink / raw)
  To: ding

Sam Steingold <sds@gnu.org> writes:

>> * Lars Ingebrigtsen <ynefv@tahf.bet> [2022-03-09 13:04:29 +0100]:
>>
>> Sam Steingold <sds@gnu.org> writes:
>>
>>> If you use it yourself, would you mind if I apply this patch?
>>
>> [...]
>>
>>> +  "v" #'gnus-summary-browse-all-urls
>>
>> I'm not sure that's generally useful enough to have as its own
>> command -- people will want to open different subsets of URLs in these
>> cases, and you kinda have to write some code for that.
>
> Right, but sometimes you want to open _all_ URLs, and this is a simple
> way.
> I can add bells and whistles (e.g., open _matching_ URLs), but that's an
> overkill for now.

It's so easy to write a wrapper around `gnus-collect-urls' I can't help
thinking this would be better off as a personal function that behaves
just the way you (personally) want it to...



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-09 19:50             ` Eric Abrahamsen
@ 2022-03-09 21:20               ` Sam Steingold
  0 siblings, 0 replies; 13+ messages in thread
From: Sam Steingold @ 2022-03-09 21:20 UTC (permalink / raw)
  To: ding

> * Eric Abrahamsen <revp@revpnoenunzfra.arg> [2022-03-09 11:50:45 -0800]:
>
> Sam Steingold <sds@gnu.org> writes:
>
>> I can add bells and whistles (e.g., open _matching_ URLs), but that's an
>> overkill for now.
>
> It's so easy to write a wrapper around `gnus-collect-urls' I can't help
> thinking this would be better off as a personal function that behaves
> just the way you (personally) want it to...

Thanks, that's what I said too.

-- 
Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://jij.org https://ffii.org https://mideasttruth.com https://iris.org.il
Life is a sexually transmitted disease with 100% mortality.



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

* Re: hackernews & gnus-summary-browse-url
  2022-03-09 19:41           ` Sam Steingold
  2022-03-09 19:50             ` Eric Abrahamsen
@ 2022-03-12 17:38             ` Lars Ingebrigtsen
  1 sibling, 0 replies; 13+ messages in thread
From: Lars Ingebrigtsen @ 2022-03-12 17:38 UTC (permalink / raw)
  To: Sam Steingold; +Cc: ding

Sam Steingold <sds@gnu.org> writes:

> Right, but sometimes you want to open _all_ URLs, and this is a simple
> way.
> I can add bells and whistles (e.g., open _matching_ URLs), but that's an
> overkill for now.

Like I said, I think what people want here has such a wide range of
possibilities that it's better of they just write some simple code.

> I am NOT!
> I am merely moving this logic to browse-url-button-open-url where it has
> been since it has been introduced!

Ah, I'd forgotten that `browse-url-button-open-url' has a really weird
calling convention -- it just responds to `browse-url-button-open-url'
no matter how it's called.  Probably due to the button machinery making
it difficult to have a more traditional interface?



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

end of thread, other threads:[~2022-03-12 17:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 21:44 hackernews & gnus-summary-browse-url Sam Steingold
2022-03-07 23:40 ` Eric Abrahamsen
2022-03-08 15:05   ` Sam Steingold
2022-03-08 15:23     ` Lars Ingebrigtsen
2022-03-08 15:56       ` Eric Abrahamsen
2022-03-08 15:58         ` Lars Ingebrigtsen
2022-03-08 20:50       ` Sam Steingold
2022-03-09 12:04         ` Lars Ingebrigtsen
2022-03-09 19:41           ` Sam Steingold
2022-03-09 19:50             ` Eric Abrahamsen
2022-03-09 21:20               ` Sam Steingold
2022-03-12 17:38             ` Lars Ingebrigtsen
2022-03-08 16:35     ` dick

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 NNTP newsgroup(s).