From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: 34052@debbugs.gnu.org
Subject: bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button)
Date: Wed, 30 Jan 2019 13:31:31 -0800 [thread overview]
Message-ID: <87ef8tn87g.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <handler.34052.B.154733083721114.ack@debbugs.gnu.org> (GNU bug Tracking System's message of "Sat, 12 Jan 2019 22:08:02 +0000")
[-- Attachment #1: Type: text/plain, Size: 128 bytes --]
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.
Eric
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-command-gnus-summary-press-button.patch --]
[-- Type: text/x-patch, Size: 4669 bytes --]
From 6f9e518bccee479a11114a128bdafb95f80539b7 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Sat, 12 Jan 2019 13:44:23 -0800
Subject: [PATCH] New command gnus-summary-press-button
* lisp/gnus/gnus-sum.el (gnus-summary-press-button): Summary buffer
command to press a button in the article buffer. Uses completion to
choose one of the buttons.
* doc/misc/gnus.texi (Article Commands): Document.
---
doc/misc/gnus.texi | 11 +++++++
lisp/gnus/gnus-sum.el | 70 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 2862264312..de7291b2a9 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -10156,6 +10156,17 @@ Article Commands
the @kbd{A C} command (@code{gnus-summary-show-complete-article}) will
do so.
+@item A l
+@cindex buttons
+@findex gnus-summary-press-button
+@kindex A l @r{(Summary)}
+Press one of the button widgets in the article buffer. This behaves
+as if the user had navigated into the article buffer and pressed
+@key{RET} on a widget. If there is more than one button widget, the
+button text is used for completion. With a prefix arg, allow
+selection of buttons in the message headers, in addition to the
+message body.
+
@end table
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index 911bf89f23..d3e3ff1927 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -2101,6 +2101,7 @@ gnus-article-commands-menu
"g" gnus-summary-show-article
"s" gnus-summary-isearch-article
"\t" gnus-summary-widget-forward
+ "l" gnus-summary-press-button
[backtab] gnus-summary-widget-backward
"P" gnus-summary-print-article
"S" gnus-sticky-article
@@ -9368,6 +9369,75 @@ gnus-summary-widget-backward
(goto-char (point-max)))
(widget-backward arg))
+(defun gnus-summary-press-button (arg)
+ "Scan the current article body for buttons, and offer to press them.
+With prefix ARG, also collect buttons from message headers.
+
+Buttons are pressed using `widget-button-press'. If only one
+button is found, press that directly, otherwise use completion to
+select a button."
+ (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 buttons 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>")
+ ;; 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) buttons)))
+ (setq target
+ (assoc (cond ((= (length buttons) 1)
+ (caar buttons))
+ ((> (length buttons) 1)
+ (completing-read
+ "URL to browse: "
+ (setq buttons (nreverse (delete-dups buttons)))
+ nil t)))
+ buttons))
+ (if target
+ (funcall-interactively #'widget-button-press (1+ (cdr target)))
+ (message "No buttons 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))))
+
(defun gnus-summary-isearch-article (&optional regexp-p)
"Do incremental search forward on the current article.
If REGEXP-P (the prefix) is non-nil, do regexp isearch."
--
2.20.1
next prev parent reply other threads:[~2019-01-30 21:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-12 21:59 bug#34052: 27.0.50; New command gnus-summary-press-button Eric Abrahamsen
[not found] ` <handler.34052.B.154733083721114.ack@debbugs.gnu.org>
2019-01-30 21:31 ` Eric Abrahamsen [this message]
2019-06-22 13:10 ` bug#34052: Acknowledgement (27.0.50; New command gnus-summary-press-button) Lars Ingebrigtsen
2019-06-22 16:38 ` Eric Abrahamsen
2019-06-23 12:16 ` Lars Ingebrigtsen
2019-06-23 15:30 ` Eric Abrahamsen
2019-06-23 15:32 ` Lars Ingebrigtsen
2019-06-23 15:59 ` Eric Abrahamsen
2019-06-23 16:17 ` Lars Ingebrigtsen
2019-06-23 16:37 ` Eric Abrahamsen
2019-06-23 16:50 ` Lars Ingebrigtsen
2019-06-23 17:06 ` Eric Abrahamsen
2019-06-23 17:09 ` Lars Ingebrigtsen
2019-06-23 17:31 ` Eric Abrahamsen
2019-06-23 17:07 ` Eric Abrahamsen
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=87ef8tn87g.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=34052@debbugs.gnu.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.