From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/88332 Path: news.gmane.org!.POSTED!not-for-mail From: Eric S Fraga Newsgroups: gmane.emacs.gnus.general Subject: Re: Command for browsing article URLs? Date: Fri, 18 Jan 2019 09:24:11 +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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1547803391 8670 195.159.176.226 (18 Jan 2019 09:23:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 18 Jan 2019 09:23:11 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: ding@gnus.org Original-X-From: ding-owner+M36541@lists.math.uh.edu Fri Jan 18 10:23:07 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 esmtp (Exim 4.84_2) (envelope-from ) id 1gkQMj-00024p-V3 for ding-account@gmane.org; Fri, 18 Jan 2019 10:23:06 +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 1gkQO7-0000mW-LY; Fri, 18 Jan 2019 03:24:31 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by lists1.math.uh.edu with esmtps (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.91) (envelope-from ) id 1gkQO0-0000jq-Nl for ding@lists.math.uh.edu; Fri, 18 Jan 2019 03:24:24 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1gkQNy-000579-CT for ding@lists.math.uh.edu; Fri, 18 Jan 2019 03:24:24 -0600 Original-Received: from [195.159.176.226] (helo=blaine.gmane.org) by quimby.gnus.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1gkQNu-0007FH-RR for ding@gnus.org; Fri, 18 Jan 2019 10:24:20 +0100 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gkQLm-0000st-SH for ding@gnus.org; Fri, 18 Jan 2019 10:22:06 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 77 Original-X-Complaints-To: usenet@blaine.gmane.org X-Url: http://twitter.com/ericsfraga/ Cancel-Lock: sha1:tIf6Mn1/OcF9aJ4Qcgc3YVUAAN0= X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: On Friday, 11 Jan 2019 at 12:38, Eric Abrahamsen wrote: > Thanks, that was helpful! When you have a moment, please try this > updated version. Been very busy with work but will try this out today. > > 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 [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS X-Spam-Score: -1.1 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:88332 Archived-At: On Friday, 11 Jan 2019 at 12:38, Eric Abrahamsen wrote: > Thanks, that was helpful! When you have a moment, please try this > updated version. Been very busy with work but will try this out today. > > 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)) > "") > ;; 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 > -- Eric S Fraga via Emacs 27.0.50 & org 9.1.13 on Debian 9.6