Created
November 14, 2012 11:32
-
-
Save preavy/4071648 to your computer and use it in GitHub Desktop.
A very simple Emacs minor mode to browse a Subversion repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun svn-repo-open (s) | |
| "Open a buffer to browse a Subversion repository." | |
| (interactive "sRepo: ") | |
| (switch-to-buffer "svn-repo") | |
| (svn-repo-mode) | |
| (shell-command (concat "svn ls " (shell-quote-argument s)) "svn-repo") | |
| (goto-char (point-min)) | |
| (if (equal "/" (substring s (- (length s) 1) (length s))) | |
| (insert (concat s "\n\n")) | |
| (insert (concat s "/\n\n")))) | |
| (defun svn-repo-browse () | |
| "Browse to the SVN folder at point in svn-repo buffer." | |
| (interactive) | |
| (let (currentFolder rootFolder) | |
| (setq currentFolder (buffer-substring-no-properties (line-beginning-position) (line-end-position))) | |
| (goto-char (point-min)) | |
| (setq rootFolder (buffer-substring-no-properties (line-beginning-position) (line-end-position))) | |
| (svn-repo-open (concat rootFolder currentFolder)))) | |
| (defun svn-repo-up () | |
| "Browse to the parent of the current SVN folder." | |
| (interactive) | |
| (let (rootFolder rootFolderPieces) | |
| (goto-char (point-min)) | |
| (setq rootFolder (buffer-substring-no-properties (line-beginning-position) (line-end-position))) | |
| (setq rootFolderPieces (split-string rootFolder "/" nil)) | |
| (svn-repo-open (mapconcat 'identity (butlast(butlast rootFolderPieces)) "/")))) | |
| (define-minor-mode svn-repo-mode | |
| "Toggle svn-repo mode." | |
| ;; The initial value. | |
| nil | |
| ;; The indicator for the mode line. | |
| " SVN-Repo" | |
| ;; The minor mode bindings. | |
| '( | |
| (("\^M") . svn-repo-browse) | |
| ((kbd "^") . svn-repo-up) | |
| ((kbd "n") . next-line) | |
| ((kbd "p") . previous-line) | |
| )) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wasn't able to find anything in PSVN which allowed me to have a quick peek at the contents of a Subversion repo, so I came up with this. Which has also been an elisp learning exercise for me.
To use it, save it as repo.el and add something like this to your init.el
When you launch it with my keybinding (or M-x svn-repo-open) enter something like "svn://myrepo". Then a buffer called "svn-repo" will open. You can move up and down with n and p, hit enter to go into a folder, and use ^ to go up a folder.
I used a minor mode because I couldn't figure out how else to associate my keybindings with my one special buffer. But you must launch this thing with M-x svn-repo-open rather than by switching on the minor mode.
Incidentally I was getting warnings back from SVN until I found the following at http://www.dgp.toronto.edu/~ghali/emacs.html
; svn issues a warning ("cannot set LC_CTYPE locale") if LANG is not set.
(setenv "LANG" "C