Gnus development mailing list
 help / color / mirror / Atom feed
From: Eric S Fraga <e.fraga@ucl.ac.uk>
To: ding@gnus.org
Subject: Re: Command for browsing article URLs?
Date: Thu, 31 Jan 2019 08:38:58 +0000	[thread overview]
Message-ID: <xuu6imy5mdb1.fsf@ucl.ac.uk> (raw)
In-Reply-To: <87r2culzju.fsf@ericabrahamsen.net>

On Wednesday, 30 Jan 2019 at 11:23, Eric Abrahamsen wrote:
> Not at all, thanks for testing. I'll probably add this as it is, then,
> and fix further bugs as they arise. 

I modified your code. If the target is an http link, I explicitly ask to
browse the url instead of activating the widget. I found that doing the
latter would simply create a new buffer and not display it (I use eww
for browsing the web).  I probably should have used funcall but I'm not
sure when one would or would not use such... I have much to learn about
elisp.

Alternatively, it may be that the final bit of your code could be
adjusted as it may be that we should check for article as well as
summary buffers?  Sometimes, I will invoke the url browsing when viewing
just the article buffer, especially on a small device.

#+begin_src emacs-lisp
  (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-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>")
                             ;; What is this, exactly?
                             (`(((,(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
           (let ((url (car target)) )
             (if (string-match "^http" url)
                 (browse-url url)
               (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

-- 
Eric S Fraga via Emacs 27.0.50 & org 9.2 on Debian 9.6




  reply	other threads:[~2019-01-31  8: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
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 [this message]
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=xuu6imy5mdb1.fsf@ucl.ac.uk \
    --to=e.fraga@ucl.ac.uk \
    --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).