Gnus development mailing list
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Haider Rizvi <harizvi@gmail.com>
Cc: ding@gnus.org
Subject: Re: Command for browsing article URLs?
Date: Thu, 10 Jan 2019 09:53:43 -0800	[thread overview]
Message-ID: <87a7k8wg9k.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <whyigtvijjcwm.fsf@hrizvi-wsm4.internal.salesforce.com> (Haider Rizvi's message of "Tue, 08 Jan 2019 10:07:53 -0700")

Haider Rizvi <harizvi@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I'd like to have a command, call it `gnus-article-browse-url', which
>> collects all the links/URLs in the article body, and then offers to
>> browse one of them (choosing with completion). Bound to "K l",
>> naturally.
>
> I use two functions along these lines but not exactly what you asked
> for.
>
> 1. ace-link-gnus: I've it bound to M-o for some historical reason. In
> typical ace-fashion, it highlights all urls in the article and you use
> a key to browse the url in your browser.
>
> 2. my-gnus-browse function: Based on the newsgroup name, it calls
> various functions to find parent url for this article from the article
> headers. For example, gwene/gmane add a Archived-at header to point to
> the original article. I had various mailing lists that I found it useful for. 
>
> Let me know if you want to see the latter. 

Okay, here's what I've got so far. It seems to work fine, except on
links in the article headers (eg the List-Subscribe header contains a
"mailto:" link). It's weird because if I click that link with the mouse,
or move point to it and hit "<RET>", it works fine. But if I
programmatically call `widget-button-press' (which is all "<RET>" is
doing), nothing happens.

Also, I have no idea what the difference between 'gnus-string and
'gnus-data text properties is: 'gnus-data in particular seems pretty
complicated.

Haider, is this something you've encountered (and maybe solved)?

Thanks,
Eric

#+begin_src elisp

(defun gnus-article-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 via `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)))
	pt urls target)
    (unless (and opened
		 ;; We might have opened an article, but then moved to
		 ;; a different summary line.
		 (= gnus-current-article (gnus-summary-article-number)))
      (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 (or (get-text-property (point) 'gnus-string)
			  (get-text-property (point) 'gnus-data)
			  (get-text-property (point) 'shr-url))))
	  (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
	  (widget-button-press (1+ (cdr target)))
	(message "No URLs found.")))
    (gnus-summary-expand-window opened)))

(with-eval-after-load "gnus-sum"
(define-key gnus-summary-mime-map (kbd "l") #'gnus-article-browse-url))
#+end_src



  parent reply	other threads:[~2019-01-10 17:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 18:03 Eric Abrahamsen
2019-01-07 20:15 ` Eric S Fraga
2019-01-07 21:53   ` Eric Abrahamsen
2019-01-08 17:07 ` Haider Rizvi
2019-01-08 20:53   ` Eric Abrahamsen
2019-01-10 18:47     ` Haider Rizvi
2019-01-10 22:27       ` Eric Abrahamsen
2019-01-10 17:53   ` Eric Abrahamsen [this message]
2019-01-10 22:46     ` Eric Abrahamsen
2019-01-11 10:17     ` Eric S Fraga
2019-01-11 20:38       ` Eric Abrahamsen
2019-01-18  9:24         ` Eric S Fraga
2019-01-18  9:32         ` Eric S Fraga
2019-01-18 18:04           ` Eric Abrahamsen
2019-01-19 11:08             ` Eric S Fraga
2019-01-21 18:03               ` Eric Abrahamsen
2019-01-22 23:45                 ` Eric Abrahamsen
2019-01-30  8:13                   ` Eric S Fraga
2019-01-30 19:23                     ` Eric Abrahamsen
2019-01-31  8:38                       ` Eric S Fraga
2019-01-31 17:18                         ` Eric Abrahamsen
2019-01-31 17:25                           ` Eric S Fraga
2019-01-31 17:49                             ` Eric Abrahamsen
2019-01-31 18:31                               ` Eric S Fraga
2019-06-22 10:30         ` Lars Ingebrigtsen
2019-01-22 20:50 ` Clemens Schüller
2019-01-22 20:59   ` Eric Abrahamsen
2019-02-10  8:55     ` Clemens Schüller

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=87a7k8wg9k.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=ding@gnus.org \
    --cc=harizvi@gmail.com \
    /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.
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).