Subject: Re: bug#12396: 24.2.50; [PATCH] extend usability of gnus-read-ephemeral-emacs-bug-group

From: Stephen Berman <[email-masked]>
Date: Mon, 10 Sep 2012 23:02:18 +0200

I discovered that the definition of gnus-get-emacs-bug-number in my
patch was deficient, so, in hopes that this feature may still make it
into Emacs, here is an improved definition (though the bit about bug
number 0 is probably dispensible).  I'll be happy to provide an updated
patch if desired.

Steve Berman

(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", or
    ;; similar strings with a capital "B" or with a space before or after "#",
    ;; or without "#", as well as strings like
    ;; "http://debbugs.gnu.org/cgi/bugreport.cgi?bug=1234".
    (when (or (eq (char-after) ?#) (eq (char-before) ?#)
	      (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)))
	   (case-fold-search t))
      (if (and num
	       ;; If bug number 0 is allowed (though it isn't in the Emacs
	       ;; bugtracker), it requires special handling, since
	       ;; string-to-number also returns 0 if str is alphabetical.
	       (or (string= "0" str) (not (zerop num)))
	       ;; Make sure this is a bug number, not just any number.
	       (beginning-of-thing 'word) (looking-back "bug ?[#=]? ?"))
	  num
	;; Otherwise look for the Nth bug number on this line.
	(goto-char (line-beginning-position))
	(when (re-search-forward "bug ?[#=]? ?\\([0-9]+\\)"
				 (line-end-position) t n)
	    (string-to-number (match-string 1)))))))