root/lang/vim/misc/svn_file_comment.vim @ 12318

Revision 4665, 1.9 kB (checked in by mattn, 5 years ago)

lang/vim/misc/svn_file_comment.vim:
thanks for drry's previous commit.
windowsでも動くように修正。

Line 
1"=============================================================================
2" File: svn_file_comment.vim
3" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
4" Last Change: Wed, 16 Jan 2008
5" Version: 0.1
6"-----------------------------------------------------------------------------
7" when editing comment for 'svn commit',
8"  it append svn comment like following
9"
10"   root/path/to/dir/docs,
11"   root/path/to/dir/docs/file1.txt,
12"   root/path/to/dir/docs/file2.txt,
13"   root/path/to/dir/docs/file3.txt:
14"   <= cursor
15"   --This line, and those below, will be ignored--
16"   A    docs
17"   A    docs/file1.txt
18"   A    docs/file2.txt
19"   A    docs/file3.txt
20"-----------------------------------------------------------------------------
21
22function! AppendCommitFiles()
23  let lstart = search("^--", "n")
24  let lend = line("$")
25  if line(".") > 1 || lstart != 2
26    return
27  endif
28  if has("windows") && !has("win32unix")
29    let oldlang=$LANG
30    let $LANG="C"
31    let lines=system("svn info")
32    let $LANG=oldlang
33  else
34    let lines=system("LANG=C svn info")
35  endif
36  let url=substitute(lines, '.*\nURL: \([^\x0A]*\).*', '\1', '')
37  let root=substitute(lines, '.*\nRepository Root: \([^\x0A]*\).*', '\1', '')
38  if match(url, root) != 0
39    return
40  endif
41  let basedir=substitute(strpart(url, strlen(root)), '^\/*', '', '')
42  let lcur = lstart
43  let lines = ""
44  let mx = '^[ADMR_][M ][U ]\s\+\([^$]\+\)$'
45  while lcur <= lend
46    let line = getline(lcur)
47    if line =~ mx
48      let lines .= basedir."/".substitute(line, mx, '\1', '')."\<NL>"
49    endif
50    let lcur = lcur + 1
51  endwhile
52  let lines = substitute(lines, '\n.', ',&', 'g')
53  let lines = substitute(lines, '\n$', ':&', '')
54  call cursor(0)
55  let value = getreg("a")
56  let type = getregtype("a")
57  call setreg("a", lines, "c")
58  execute 'normal! "ap'
59  call setreg("a", value, type)
60  silent! /^$
61endfunction
62autocmd FileType svn call AppendCommitFiles()
Note: See TracBrowser for help on using the browser.