From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Phil Hagelberg Newsgroups: gmane.emacs.devel Subject: Hyperlinks in *vc-change-log* Date: Wed, 09 Apr 2008 09:29:18 -0700 Message-ID: <87fxtvng9t.fsf@hagelb.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1207758629 11105 80.91.229.12 (9 Apr 2008 16:30:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Apr 2008 16:30:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 09 18:30:59 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JjdCJ-0007Wz-8R for ged-emacs-devel@m.gmane.org; Wed, 09 Apr 2008 18:30:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjdBf-0008Sy-Oc for ged-emacs-devel@m.gmane.org; Wed, 09 Apr 2008 12:30:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JjdAr-00085Z-4Y for emacs-devel@gnu.org; Wed, 09 Apr 2008 12:29:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JjdAq-00084y-Az for emacs-devel@gnu.org; Wed, 09 Apr 2008 12:29:24 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjdAp-00084m-R7 for emacs-devel@gnu.org; Wed, 09 Apr 2008 12:29:23 -0400 Original-Received: from sd-green-bigip-74.dreamhost.com ([208.97.132.74] helo=spunkymail-a13.g.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JjdAp-0004YU-BM for emacs-devel@gnu.org; Wed, 09 Apr 2008 12:29:23 -0400 Original-Received: from dynabook (dsl081-164-175.sea1.dsl.speakeasy.net [64.81.164.175]) by spunkymail-a13.g.dreamhost.com (Postfix) with ESMTP id 4C17C129B3C for ; Wed, 9 Apr 2008 09:29:20 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:94798 Archived-At: I've written up some code that I find quite useful for working with VC. The code below adds buttons to each commit entry in *vc-change-log* buffers, essentially making them hyperlinks to the revision mentioned using vc-find-revision. I think with a bit of work this could be incorporated into Emacs if people think it would be useful and appropriate. There are a few caveats first: * The button actions use closures and thus require the cl library. As I understand it, this dependency would have to be removed for it to be included in Emacs. I consider this to be somewhat disappointing as it will add complexity to the code, but I respect this choice of the maintainers. * It only supports three VC backends: SVN, CVS, and Git. This is simply because I don't have much experience with other VC systems; it would be trivial to add support for more by adding appropriate entries to vc-button-regexp-alist to match what a commit looks like in each backend. * Right now it only works with *vc-change-log* buffers that correspond to a single file. I am not sure what the action makes sense for buffers that correspond to a fileset; I have mostly used VC logs in the context of single files. * It currently uses hooks. If it were incorporated into Emacs, it could probably be added directly to an existing function. Anyhow, the code is included below. Feedback would be appreciated. I've tested it in Emacs built from a week or two ago with Git, CVS, and SVN projects, but I'm sure it could benefit from more testing and feedback. Even if it is not incorporated into Emacs, I think it's useful on its own. Thanks, Phil Hagelberg http://technomancy.us (require 'cl) (defvar vc-button-regexp-alist '((Git . "^commit +\\([0-9a-f]\\{40\\}\\)$") (SVN . "^r\\([0-9]+\\) ") (CVS . "revision \\([0-9]+.[0-9]+\\)")) "An alist pairing VC backends to regexps describing what commits look like.") (defun vc-log-make-buttons () "Make each reference to a commit in the current buffer act as a hyperlink." (let* ((buffer-read-only nil) (file (buffer-file-name vc-parent-buffer)) (button-regexp (assocref (vc-backend (list file)) vc-button-regexp-alist))) (save-excursion (beginning-of-buffer) (while (search-forward-regexp button-regexp nil t) (lexical-let ((cl-file file) ;; closure time! (revision (match-string 1))) (make-text-button (match-beginning 1) (match-end 1) 'action (lambda (arg) (interactive) (switch-to-buffer (vc-find-revision cl-file revision))))))))) (add-hook 'log-view-mode-hook 'vc-log-make-buttons)