From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#12396: 24.2.50; [PATCH] extend usability of gnus-read-ephemeral-emacs-bug-group Date: Sun, 09 Sep 2012 18:00:56 +0200 Message-ID: <87d31vtccn.fsf@rosalinde.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1347206499 31740 80.91.229.3 (9 Sep 2012 16:01:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Sep 2012 16:01:39 +0000 (UTC) To: 12396@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 09 18:01:41 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TAjx7-00015q-5l for geb-bug-gnu-emacs@m.gmane.org; Sun, 09 Sep 2012 18:01:41 +0200 Original-Received: from localhost ([::1]:52658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAjx3-0002cQ-VI for geb-bug-gnu-emacs@m.gmane.org; Sun, 09 Sep 2012 12:01:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAjx0-0002cA-Aw for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAjwy-0006xC-LW for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:34 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAjwy-0006x8-ID for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:32 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TAjxR-00007i-UO for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:02:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Sep 2012 16:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12396 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.1347206502443 (code B ref -1); Sun, 09 Sep 2012 16:02:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Sep 2012 16:01:42 +0000 Original-Received: from localhost ([127.0.0.1]:50437 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TAjx7-000075-6h for submit@debbugs.gnu.org; Sun, 09 Sep 2012 12:01:41 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56634) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TAjx4-00006x-1c for submit@debbugs.gnu.org; Sun, 09 Sep 2012 12:01:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAjwY-0006nD-LV for submit@debbugs.gnu.org; Sun, 09 Sep 2012 12:01:08 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:33991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAjwY-0006n9-I2 for submit@debbugs.gnu.org; Sun, 09 Sep 2012 12:01:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAjwW-0002bC-T9 for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAjwU-0006mG-DF for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:04 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:58644) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1TAjwU-0006lu-2y for bug-gnu-emacs@gnu.org; Sun, 09 Sep 2012 12:01:02 -0400 Original-Received: (qmail invoked by alias); 09 Sep 2012 16:00:58 -0000 Original-Received: from i59F5698F.versanet.de (EHLO rosalinde.fritz.box) [89.245.105.143] by mail.gmx.net (mp069) with SMTP; 09 Sep 2012 18:00:58 +0200 X-Authenticated: #20778731 X-Provags-ID: V01U2FsdGVkX1+OeQ9z4YmOLS7UW5urlPvzFBynh5UOQNWFhR9ovC aksJImNoc8OSE4 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:64007 Archived-At: --=-=-= Content-Type: text/plain This is a feature request accompanied by a possible implementation. When reading (with Gnus) Emacs mailing lists or news groups that have bug references in the subject line, typing `M-x gnus-read-ephemeral-emacs-bug-group' is a nice way to browse the whole bug thread by opening it as an temporary group. However, this command offers the bug number in the subject as default in the minibuffer prompt only if point is on the number, which usually means having to navigate to it. It would be more convenient if the bug number in the current line in the Group buffer were offered as default regardless of where point is in the line. The first patch (against bzr trunk revision 109955) below does this. It makes a number in the subject line the default if it is preceded by "bug" or "Bug", possibly with a space, `#' or `=' in between (the latter to grab the bug number in a URL to the Emacs bugtracker, which is clickable but calls a web browser via browse-url). In addition, since the subject line sometimes contains more than one bug number, this patch allows selecting which one (counting from the left) to offer as default, by typing a numerical prefix argument; with no prefix argument the default is the leftmost bug number. Furthermore, it would be convenient to use gnus-read-ephemeral-emacs-bug-group if you don't already having Gnus loaded, e.g. when visiting an Emacs ChangeLog, so the patch adds an autoload cookie to this command to enable doing this. For ChangeLogs there is already bug-reference.el, which uses browse-url; it would be nice to have the option of using gnus-read-ephemeral-emacs-bug-group to follow bug references by clicking the bug reference links in the ChangeLog file (as an alternative to calling it with `M-x'). So the second patch below does this by adding a suitable user option which is used in bug-reference-push-button. This approach could be generalized by replacing gnus-get-emacs-bug-number by a function that also recognizes other bug or issue numbers, maybe along the lines of bug-reference-bug-regexp, and making bug-reference-push-button act appropriately; but since I've only used gnus-read-ephemeral-emacs-bug-group and could test it, I leave this as a todo. (However, I don't think browse-url itself should be extended to allow calling g-r-e-e-b-g by clicking a URL like the one mentioned in the first paragraph above, since browse-url is intended to call a web browser, and that's what I think users expect when they click relevant links, and the presence of a bug number in a URL is a special case. But with bug-reference-push-button, the point is to follow a bug reference, and since g-r-e-e-b-g also exists for this purpose, it seems reasonable to allow calling it by clicking these links.) --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Description: Patch for gnus-group.el === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2012-09-07 04:07:00 +0000 +++ lisp/gnus/ChangeLog 2012-09-09 15:24:48 +0000 @@ -1,3 +1,9 @@ +2012-09-09 Stephen Berman + + * gnus-group.el (gnus-get-emacs-bug-number): New function. + (gnus-read-ephemeral-emacs-bug-group): Use it; change function's + signature and interactive spec accordingly. Add autoload cookie. + 2012-09-07 Chong Yidong * gnus-util.el === modified file 'lisp/gnus/gnus-group.el' --- lisp/gnus/gnus-group.el 2012-09-07 04:07:00 +0000 +++ lisp/gnus/gnus-group.el 2012-09-09 15:24:45 +0000 @@ -2498,21 +2498,54 @@ (defvar debbugs-gnu-bug-number) ; debbugs-gnu -(defun gnus-read-ephemeral-emacs-bug-group (ids &optional window-conf) - "Browse Emacs bugs IDS as an ephemeral group." - (interactive (list (string-to-number - (read-string "Enter bug number: " - (thing-at-point 'word) nil)))) - (unless (listp ids) - (setq ids (list ids))) - (gnus-read-ephemeral-bug-group - ids - (cdr (assoc 'emacs gnus-bug-group-download-format-alist)) - window-conf) - (when (fboundp 'debbugs-gnu-summary-mode) - (with-current-buffer (window-buffer (selected-window)) - (debbugs-gnu-summary-mode 1) - (set (make-local-variable 'debbugs-gnu-bug-number) (car ids))))) +(defun gnus-get-emacs-bug-number (&optional n) + "Return an Emacs bug number in this line, if any. +If point is on a recognizable bug number, return it; otherwise, +if argument N is a positive integer, return the Nth bug number in +this line, counting from the left, or nil if there is no Nth bug +number." + (save-excursion + ;; Get the number if point is anywhere within a string like "bug#1234", + ;; "Bug#1234", bug #1234", "Bug #1234", bug 1234", "Bug 1234" as well as + ;; "http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11735" + (when (or (string= (thing-at-point 'word) "Bug") + (string= (thing-at-point 'word) "bug")) + (forward-word) + (skip-chars-forward " #=")) + (let* ((str (thing-at-point 'word)) + (num (if str (string-to-number str)))) + (if (and num (not (zerop num))) + num + ;; Otherwise look for the Nth bug number on + ;; this line. + (let ((case-fold-search t)) + (goto-char (line-beginning-position)) + (when (re-search-forward "bug ?[#=]? ?\\([0-9]+\\)" + (line-end-position) t n) + (string-to-number (match-string 1)))))))) + +;;;###autoload +(defun gnus-read-ephemeral-emacs-bug-group (&optional n window-conf) + "Browse an Emacs bug report thread as an ephemeral group. +If point is on a recognizable bug number, offer it as default; +otherwise, offer the first, or with numerical prefix argument N, +the Nth bug number in this line, counting from the left. If +there is no bug number in this line, or too few, prompt for a +number without offering a default." + (interactive "P") + (let ((ids (read-number "Enter bug number: " + (gnus-get-emacs-bug-number + (if (and (integerp n) (> n 1)) n 1))))) + (unless (listp ids) + (setq ids (list ids))) + (gnus-read-ephemeral-bug-group + ids + (cdr (assoc 'emacs gnus-bug-group-download-format-alist)) + window-conf) + (when (fboundp 'debbugs-gnu-summary-mode) + (with-current-buffer (window-buffer (selected-window)) + (debbugs-gnu-summary-mode 1) + (set (make-local-variable 'debbugs-gnu-bug-number) (car ids)))))) (defun gnus-group-jump-to-group (group &optional prompt) "Jump to newsgroup GROUP. --=-=-= Content-Type: text/plain Content-Disposition: inline Content-Description: Patch for bug-reference.el === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-09-09 11:03:37 +0000 +++ lisp/ChangeLog 2012-09-09 15:28:28 +0000 @@ -1,3 +1,9 @@ +2012-09-09 Stephen Berman + + * progmodes/bug-reference.el (bug-reference-push-button-action): + New defcustom to allow using gnus-read-ephemeral-emacs-bug-group. + (bug-reference-push-button): Use it. + 2012-09-09 Alan Mackenzie * progmodes/cc-engine.el (c-state-cache-init): Initialise === modified file 'lisp/progmodes/bug-reference.el' --- lisp/progmodes/bug-reference.el 2012-08-22 06:47:00 +0000 +++ lisp/progmodes/bug-reference.el 2012-09-09 15:28:25 +0000 @@ -76,6 +76,12 @@ :safe 'stringp :group 'bug-reference) +(defcustom bug-reference-push-button-action 'url + "List of choices for visiting the bug referenced in the button." + :type '(radio (const :tag "Visit the bug's URL in a browser" url) + (const :tag "Visit the bug thread in Gnus" gnus)) + :group 'bug-reference) + (defun bug-reference-set-overlay-properties () "Set properties of bug reference overlays." (put 'bug-reference 'evaporate t) @@ -121,7 +127,11 @@ ;; Taken from button.el. (defun bug-reference-push-button (&optional pos _use-mouse-action) - "Open URL corresponding to the bug reference at POS." + "Take appropriate action on the bug reference at POS. +The action depends on the value of the user option +`bug-reference-push-button-action': either visit the bug's URL in +a browser or visit the bug thread in Gnus (N.B.: the latter only +works for references to the Emacs bugtracker)." (interactive (list (if (integerp last-command-event) (point) last-command-event))) (if (and (not (integerp pos)) (eventp pos)) @@ -130,11 +140,14 @@ (with-current-buffer (window-buffer (posn-window posn)) (bug-reference-push-button (posn-point posn) t))) ;; POS is just normal position. - (dolist (o (overlays-at pos)) - ;; It should only be possible to have one URL overlay. - (let ((url (overlay-get o 'bug-reference-url))) - (when url - (browse-url url)))))) + (cond ((eq bug-reference-push-button-action 'url) + (dolist (o (overlays-at pos)) + ;; It should only be possible to have one URL overlay. + (let ((url (overlay-get o 'bug-reference-url))) + (when url + (browse-url url))))) + ((eq bug-reference-push-button-action 'gnus) + (gnus-read-ephemeral-emacs-bug-group))))) ;;;###autoload (define-minor-mode bug-reference-mode --=-=-=--