all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Phil Hagelberg <phil@hagelb.org>
To: emacs-devel@gnu.org
Subject: Hyperlinks in *vc-change-log*
Date: Wed, 09 Apr 2008 09:29:18 -0700	[thread overview]
Message-ID: <87fxtvng9t.fsf@hagelb.org> (raw)


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)




             reply	other threads:[~2008-04-09 16:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-09 16:29 Phil Hagelberg [this message]
2008-04-09 17:43 ` Hyperlinks in *vc-change-log* Lennart Borgman (gmail)
2008-04-09 19:59 ` Stefan Monnier
2008-04-10  7:37   ` Dan Nicolaescu
2008-04-11  5:48   ` Phil Hagelberg
2008-04-11 16:36     ` Stefan Monnier
2008-04-12  6:44       ` Phil Hagelberg
2008-04-13 17:33     ` Thien-Thi Nguyen
2008-04-15 22:33     ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fxtvng9t.fsf@hagelb.org \
    --to=phil@hagelb.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.