From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button) Date: Sat, 22 Jun 2019 09:38:49 -0700 Message-ID: <87mui9y3qe.fsf@ericabrahamsen.net> References: <87tvidbkre.fsf@ericabrahamsen.net> <87ef8tn87g.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="76032"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 34052@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 22 18:40:30 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hej3z-000JcL-SD for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Jun 2019 18:40:28 +0200 Original-Received: from localhost ([::1]:41732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hej3y-00079D-EL for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Jun 2019 12:40:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50658) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hej3f-000795-D8 for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2019 12:40:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hej3b-00009i-Gc for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2019 12:40:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hej3Z-0008Ux-PH for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2019 12:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hej3Z-0006AK-KI for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2019 12:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Jun 2019 16:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34052 X-GNU-PR-Package: emacs Original-Received: via spool by 34052-submit@debbugs.gnu.org id=B34052.156122154923625 (code B ref 34052); Sat, 22 Jun 2019 16:40:01 +0000 Original-Received: (at 34052) by debbugs.gnu.org; 22 Jun 2019 16:39:09 +0000 Original-Received: from localhost ([127.0.0.1]:52462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hej2i-00068y-LH for submit@debbugs.gnu.org; Sat, 22 Jun 2019 12:39:08 -0400 Original-Received: from ericabrahamsen.net ([52.70.2.18]:39564 helo=mail.ericabrahamsen.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hej2g-00068c-Qh for 34052@debbugs.gnu.org; Sat, 22 Jun 2019 12:39:07 -0400 Original-Received: from localhost (unknown [172.92.212.120]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 92FD3FA648; Sat, 22 Jun 2019 16:39:00 +0000 (UTC) In-Reply-To: (Lars Ingebrigtsen's message of "Sat, 22 Jun 2019 15:10:38 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:161042 Archived-At: Lars Ingebrigtsen writes: > Eric Abrahamsen writes: > >> Here's a new (lightly user-tested) version of the command. I guess if >> there's no objection I'll push this in a few days. > > *taps calendar* Ahem... > Looks good to me, but as I said over on the ding mailing list: > >> +@item A l > > I think this is such a useful command that we should bind it to `w' > instead. Or some other unused single key keystroke. No objection here. >> + (if target >> + (funcall-interactively #'widget-button-press (1+ (cdr target))) > > And I didn't quite get why you're not just using browse-url directly > here, which seems less fragile and more controllable. I think once I was using widget-forward to collect buttons, it seemed natural to be able to handle all the types of buttons, not just URLs. For instance, I'd like to be able to start composing messages to mailto: buttons. Then the only reliable way to "do" what the button does was to press it. Later Eric Fraga posted a variant that checked if the URL was a http URL, and used `browse-url' directly in that case. The whole function could be a lot simpler if we only collected http links. Though I'd still like to compose messages to email addresses... I'm posting the most recent version of the function below. Another bad thing is does is tries to manage window state, returning the summary/article config to what it was before clicking links, and I think that should be removed -- it's fragile, and none of the other summary/article commands do that. Anyway, let me know what you think about the button vs link issue... #+begin_src elisp (defun gnus-summary-press-button (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)))) (wc (current-window-configuration)) 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) "") ;; Sometimes this is also a "so-and-so wrote" quote. (`(((,(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 (funcall-interactively #'widget-button-press (1+ (cdr target))) (message "No URLs found."))) ;; Now what? If pressing the button changed our window layout, do ;; nothing. Otherwise, if the article wasn't opened to begin ;; with, close it after we follow the link. (unless (equal wc (current-window-configuration)) (gnus-summary-expand-window opened)))) #+end_src