From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: ding@gnus.org
Subject: Re: Command for browsing article URLs?
Date: Fri, 11 Jan 2019 12:38:11 -0800 [thread overview]
Message-ID: <87fttzc4lo.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87wonbts5s.fsf@ucl.ac.uk>
Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> Hi Eric,
>
> I tried your gnus-article-browse-url and I get the following error:
>
> sort: Wrong type argument: stringp, ((#<marker at 627 in *Article
> nntp+news.gwene.org:gmane.linux.debian.user*> . #<marker at 927 in
> *Article nntp+news.gwene.org:gmane.linux.debian.user*>) #<marker at 623
> in *Article nntp+news.gwene.org:gmane.linux.debian.user*>)
>
> Not tried any serious debugging yet as I'm busy with work. In any case,
> the only reason for sort to complain, that I can see, is that somehow
> ivy (which I use) is confused, given that you use completing-read. Any
> suggestions welcome.
Thanks, that was helpful! When you have a moment, please try this
updated version.
I'm thinking it might be better named "gnus-article-click-button", since
that's pretty much what it does now.
#+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 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))))
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))))
(with-eval-after-load "gnus-sum"
(define-key gnus-summary-mime-map (kbd "l") #'gnus-article-browse-url))
#+end_src
next prev parent reply other threads:[~2019-01-11 20:38 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
2019-01-10 22:46 ` Eric Abrahamsen
2019-01-11 10:17 ` Eric S Fraga
2019-01-11 20:38 ` Eric Abrahamsen [this message]
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=87fttzc4lo.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=ding@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.
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).