From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/88329 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.gnus.general Subject: Re: Command for browsing article URLs? Date: Fri, 11 Jan 2019 12:38:11 -0800 Message-ID: <87fttzc4lo.fsf@ericabrahamsen.net> References: <878szwwdjw.fsf@ericabrahamsen.net> <87a7k8wg9k.fsf@ericabrahamsen.net> <87wonbts5s.fsf@ucl.ac.uk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1547239039 16711 195.159.176.226 (11 Jan 2019 20:37:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 11 Jan 2019 20:37:19 +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+M36538@lists.math.uh.edu Fri Jan 11 21:37:15 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 1gi3YJ-0004Dq-8Z for ding-account@gmane.org; Fri, 11 Jan 2019 21:37:15 +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 1gi3ZX-0006CG-TN; Fri, 11 Jan 2019 14:38:31 -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 1gi3ZS-00069Y-2R for ding@lists.math.uh.edu; Fri, 11 Jan 2019 14:38:26 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1gi3ZQ-0000Yo-Cv for ding@lists.math.uh.edu; Fri, 11 Jan 2019 14:38:25 -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 1gi3ZL-0004IZ-RR for ding@gnus.org; Fri, 11 Jan 2019 21:38:21 +0100 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gi3XD-0002eE-QQ for ding@gnus.org; Fri, 11 Jan 2019 21:36:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 86 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:IlKpywJbNx0T5P+9LC3IO8UFS10= 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: Eric S Fraga writes: > Hi Eric, > > I tried your gnus-article-browse-url and I get the following error: > > sort: Wrong type argument: stringp, ((# nntp+news.gwene.org:gmane.linux.debian.user*> [...] 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:88329 Archived-At: Eric S Fraga writes: > Hi Eric, > > I tried your gnus-article-browse-url and I get the following error: > > sort: Wrong type argument: stringp, ((# nntp+news.gwene.org:gmane.linux.debian.user*> . # *Article nntp+news.gwene.org:gmane.linux.debian.user*>) # 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)) "") ;; 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