[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hyperlinks in *vc-change-log*
From: |
Phil Hagelberg |
Subject: |
Hyperlinks in *vc-change-log* |
Date: |
Wed, 09 Apr 2008 09:29:18 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
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)
- Hyperlinks in *vc-change-log*,
Phil Hagelberg <=