From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/88346 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eric S Fraga Newsgroups: gmane.emacs.gnus.general Subject: Re: Command for browsing article URLs? Date: Thu, 31 Jan 2019 08:38:58 +0000 Organization: On the Interweb somewhere Message-ID: References: <878szwwdjw.fsf@ericabrahamsen.net> <87a7k8wg9k.fsf@ericabrahamsen.net> <87wonbts5s.fsf@ucl.ac.uk> <87fttzc4lo.fsf@ericabrahamsen.net> <87sgxpzvsr.fsf@ericabrahamsen.net> <87r2d8c3az.fsf@ucl.ac.uk> <874la1yjjo.fsf@ericabrahamsen.net> <87pnso9rzp.fsf@ericabrahamsen.net> <87sgxak1gz.fsf@ucl.ac.uk> <87r2culzju.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="91394"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: ding@gnus.org Original-X-From: ding-owner+M36555@lists.math.uh.edu Thu Jan 31 09:40:09 2019 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from lists1.math.uh.edu ([129.7.128.208]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gp7tJ-000NZq-9U for ding-account@gmane.org; Thu, 31 Jan 2019 09:40:09 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by lists1.math.uh.edu with smtp (Exim 4.91) (envelope-from ) id 1gp7sW-0004c5-Kg; Thu, 31 Jan 2019 02:39:20 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by lists1.math.uh.edu with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1gp7sQ-0004ZK-Aq for ding@lists.math.uh.edu; Thu, 31 Jan 2019 02:39:14 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gp7sO-0001vU-8k for ding@lists.math.uh.edu; Thu, 31 Jan 2019 02:39:14 -0600 Original-Received: from [195.159.176.226] (helo=blaine.gmane.org) by quimby.gnus.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gp7sG-0004VO-Nb for ding@gnus.org; Thu, 31 Jan 2019 09:39:10 +0100 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1gp7sG-000MZT-B1 for ding@gnus.org; Thu, 31 Jan 2019 09:39:04 +0100 X-Injected-Via-Gmane: http://gmane.org/ X-Url: http://twitter.com/ericsfraga/ Cancel-Lock: sha1:3aHhheavMLOCbl8NotrIB2CTdc0= List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:88346 Archived-At: 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) "") ;; 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