unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Hyperlinks in *vc-change-log*
@ 2008-04-09 16:29 Phil Hagelberg
  2008-04-09 17:43 ` Lennart Borgman (gmail)
  2008-04-09 19:59 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Phil Hagelberg @ 2008-04-09 16:29 UTC (permalink / raw)
  To: emacs-devel


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)




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-04-15 22:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-09 16:29 Hyperlinks in *vc-change-log* Phil Hagelberg
2008-04-09 17:43 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).