* All-in-one examine command of CVS/SVN/Git in Emacs
公司在用CVS,自己平时用Git,偶尔还要用SVN,cvs的examine我bind到了C-x v e上,
也用习惯了,就想何不写个统一的command来调用
cvs-examine/svn-status/magit-status。想法比较简单:
- 查看当前目录下有没有CVS/, 如果有则call cvs-examine;
- 查看当前目录下有没有.svn/, 如果有则call svn-status;
- 查看当前目录是否在git repo中,如果是则call magit-status
- 上面条件都不成立,则让用户选择要使用的vcs tool与目录 (用one-key实现)
- 如果有prefix arg,则直接让用户选择,不自动检测
于是有了下面的简单command:
<pre LANG=”lisp”>
(require ‘psvn)
(require ‘magit)
(require ‘one-key)
(defvar one-key-vcs-alist nil
“`One-Key’ menu list for VCS.”)
(setq one-key-vcs-alist
‘(((“c” . “CVS”) . cvs-examine)
((“s” . “SVN”) . svn-examine)
((“g” . “Git”) . magit-status)))
(defun one-key-menu-vcs ()
“`One-Key’ menu for VCS”
(interactive)
(one-key-menu “EMMS” one-key-vcs-alist t))
(defun zwl-vcs-examine ()
“Examine directory using a VCS (Version Control System) tool.
If current directory contains CVS/, using cvs;
If current directory contains .svn/, using svn;
If current directory is in magit directory, using magit;
otherwise pop a one-key and let user choose which command will be used.”
(interactive)
(if current-prefix-arg
(call-interactively ‘one-key-menu-vcs)
(cond
((file-exists-p “CVS/”) (call-interactively ‘cvs-examine))
((file-exists-p “.svn/”) (call-interactively ‘svn-examine))
((magit-get-top-dir default-directory) (call-interactively ‘magit-status))
(t (call-interactively ‘one-key-menu-vcs)))))
(define-key global-map “\C-xve” ‘zwl-vcs-examine)
</pre>
- “C-x v e “, 自动检测所需要的vcs工具
- “C-u C-x v e”, 让用户选择所需要的vcs工具
最后推荐一下One-Key, 很好用的工具。All-in-one examine command of CVS/SVN/Git in Emacs
公司在用CVS,自己平时用Git,偶尔还要用SVN,cvs的examine我bind到了C-x v e上,也用习惯了,就想何不写个统一的command来调用 cvs-examine/svn-status/magit-status。想法比较简单:
- 查看当前目录下有没有CVS/, 如果有则call cvs-examine;
- 查看当前目录下有没有.svn/, 如果有则call svn-status;
- 查看当前目录是否在git repo中,如果是则call magit-status
- 上面条件都不成立,则让用户选择要使用的vcs tool与目录 (用OneKey实现)
- 如果有prefix arg,则直接让用户选择,不自动检测
于是有了下面的简单command:
(require 'psvn)
(require 'magit)
(require 'one-key)
(defvar one-key-vcs-alist nil
"`One-Key' menu list for VCS.")
(setq one-key-vcs-alist
'((("c" . "CVS") . cvs-examine)
(("s" . "SVN") . svn-examine)
(("g" . "Git") . magit-status)))
(defun one-key-menu-vcs ()
"`One-Key' menu for VCS"
(interactive)
(one-key-menu "EMMS" one-key-vcs-alist t))
(defun zwl-vcs-examine ()
"Examine directory using a VCS (Version Control System) tool.
If current directory contains CVS/, using cvs;
If current directory contains .svn/, using svn;
If current directory is in magit directory, using magit;
otherwise pop a one-key and let user choose which command will be used."
(interactive)
(if current-prefix-arg
(call-interactively 'one-key-menu-vcs)
(cond
((file-exists-p "CVS/") (call-interactively 'cvs-examine))
((file-exists-p ".svn/") (call-interactively 'svn-examine))
((magit-get-top-dir default-directory) (call-interactively 'magit-status))
(t (call-interactively 'one-key-menu-vcs)))))
(define-key global-map "\C-xve" 'zwl-vcs-examine)
- “C-x v e “, 自动检测所需要的vcs工具
- “C-u C-x v e”, 让用户选择所需要的vcs工具
最后推荐一下OneKey, 很好用的工具。