[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Tom Tromey
Subject: changelog-url.el
Date: 23 Mar 2007 00:52:55 -0600
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

I wrote this the other day and I thought other folks might find it

This code searches through a ChangeLog file for things that look like
references to an entry in a bug database.  When it finds one, it
buttonizes it so that (middle-) clicking on it will open the bug using

To use:

  (load "changelog-url")  ; or autoload changelog-url-buttonize
  (add-hook 'change-log-mode-hook #'changelog-url-buttonize)

To work you must define changelog-url-format.  This is a format that
turns a bug number (represented as a string) to a URL, e.g.:

  (setq changelog-url-format "";)

The idea is to set this per ChangeLog somehow, e.g. using dirvars or a
file-local variable.  (If dirvars or the like were standard, projects
could arrange this by putting some lisp in their cvs repository...)

This requires the button package, which is in Emacs 22.

If you are using package.el, you can get this package from ELPA.  Just
M-x package-list-packages, "r" to re-fetch the archive contents, and
then install it.


;; changelog-url.el --- buttonize PRs in ChangeLog.

;; Copyright (C) 2007 Tom Tromey <address@hidden>

;; Author: Tom Tromey <address@hidden>
;; Created: 21 Mar 2007
;; Keywords: tools

;; This file is not (yet) part of GNU Emacs.
;; However, it is distributed under the same license.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Change Log:

;; 21 Mar 2007 - created

;;; Commentary:

;; This turns references to bugs in a ChangeLog buffer into clickable
;; links to the bug system.

;;; ToDo:

;; should buttonize URLs as well.

(defconst changelog-bug-pattern "\\([Bb]ug #\\|PR [a-z-]+/\\)\\([0-9]+\\)"
  "Pattern to match bug system references.")

;; E.g., "";
(defvar changelog-url-format nil
  "Format used to turn a bug number into a URL.
The bug number is supplied as a string, so this should have a single %s.
There is no default setting for this, it must be set per ChangeLog.")

(defun changelog-url-buttonize ()
  (when changelog-url-format
      (goto-char (point-min))
      (while (re-search-forward changelog-bug-pattern nil t)
        (let* ((start (match-beginning 0))
               (end (match-end 0))
               (number (buffer-substring-no-properties (match-beginning 2)
                                                       (match-end 2)))
               (url (format changelog-url-format number)))
          (make-button start end
                       'changelog-url url
                       'help-echo (concat "Visit bug at " url)
                       'action (lambda (button &rest ignore)
                                 (let ((url (button-get button
                                   (browse-url url)))))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]