annotate vim/bundle/lawrencium/plugin/lawrencium.vim @ 56:0dbb1fd60f71

Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 08 Dec 2011 12:30:50 -0800
parents 05fd225bd1a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 " lawrencium.vim - A Mercurial wrapper
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com>
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 " Version: 0.1
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
5 " Globals {{{
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
6
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
7 if !exists('g:lawrencium_debug')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
8 let g:lawrencium_debug = 0
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
9 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
10
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
12 finish
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 let g:loaded_lawrencium = 1
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 if !exists('g:lawrencium_hg_executable')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 let g:lawrencium_hg_executable = 'hg'
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 if !exists('g:lawrencium_trace')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 let g:lawrencium_trace = 0
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
24 if g:lawrencium_debug
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
25 echom "Loaded Lawrencium."
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
26 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
27
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
28 " }}}
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
29
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 " Utility {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
32 " Strips the ending slash in a path.
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 function! s:stripslash(path)
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
34 return fnamemodify(a:path, ':s?[/\\]$??')
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
37 " Normalizes the slashes in a path.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
38 function! s:normalizepath(path)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
39 if exists('+shellslash') && &shellslash
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
40 return substitute(a:path, '\\', '/', '')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
41 elseif has('win32')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
42 return substitute(a:path, '/', '\\', '')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
43 else
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
44 return a:path
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
45 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
46 endfunction
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
47
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
48 " Prints a message if debug tracing is enabled.
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 function! s:trace(message)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 if g:lawrencium_trace
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 let l:message = "lawrencium: " . a:message
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
52 echom l:message
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
56 " Throw a Lawrencium exception message.
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 function! s:throw(message)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 let v:errmsg = "lawrencium: " . a:message
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 throw v:errmsg
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
62 " Finds the repository root given a path inside that repository.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
63 " Throw an error if not repository is found.
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 function! s:find_repo_root(path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 let l:path = s:stripslash(a:path)
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
66 let l:previous_path = ""
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
67 while l:path != l:previous_path
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 if isdirectory(l:path . '/.hg/store')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 return simplify(fnamemodify(l:path, ':p'))
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 endif
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
71 let l:previous_path = l:path
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 let l:path = fnamemodify(l:path, ':h')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 endwhile
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 call s:throw("No Mercurial repository found above: " . a:path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 " Mercurial Repository {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 " Let's define a Mercurial repo 'class' using prototype-based object-oriented
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 " programming.
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 "
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 " The prototype dictionary.
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 let s:HgRepo = {}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 " Constructor
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 function! s:HgRepo.New(path) abort
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 let l:newRepo = copy(self)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 let l:newRepo.root_dir = s:find_repo_root(a:path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 return l:newRepo
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 " Gets a full path given a repo-relative path
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 function! s:HgRepo.GetFullPath(path) abort
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
97 let l:root_dir = self.root_dir
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
98 if a:path =~# '^[/\\]'
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
99 let l:root_dir = s:stripslash(l:root_dir)
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 endif
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
101 return l:root_dir . a:path
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
102 endfunction
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
103
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
104 " Gets a list of files matching a root-relative pattern.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
105 " If a flag is passed and is TRUE, a slash will be appended to all
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
106 " directories.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
107 function! s:HgRepo.Glob(pattern, ...) abort
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
108 let l:root_dir = self.root_dir
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
109 if (a:pattern =~# '^[/\\]')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
110 let l:root_dir = s:stripslash(l:root_dir)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
111 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
112 let l:matches = split(glob(l:root_dir . a:pattern), '\n')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
113 if a:0 && a:1
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
114 for l:idx in range(len(l:matches))
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
115 if !filereadable(l:matches[l:idx])
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
116 let l:matches[l:idx] = l:matches[l:idx] . '/'
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
117 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
118 endfor
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
119 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
120 let l:strip_len = len(l:root_dir)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
121 call map(l:matches, 'v:val[l:strip_len : -1]')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
122 return l:matches
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 " Runs a Mercurial command in the repo
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 function! s:HgRepo.RunCommand(command, ...) abort
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
127 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir))
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(a:000, ' ')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 call s:trace("Running Mercurial command: " . l:hg_command)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 return system(l:hg_command)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 " Repo cache map
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 let s:buffer_repos = {}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 " Get a cached repo
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 function! s:hg_repo(...) abort
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138 " Use the given path, or the mercurial directory of the current buffer.
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 if a:0 == 0
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 if exists('b:mercurial_dir')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 let l:path = b:mercurial_dir
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142 else
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 let l:path = s:find_repo_root(expand('%:p'))
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145 else
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146 let l:path = a:1
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
147 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
148 " Find a cache repo instance, or make a new one.
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
149 if has_key(s:buffer_repos, l:path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
150 return get(s:buffer_repos, l:path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151 else
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 let l:repo = s:HgRepo.New(l:path)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 let s:buffer_repos[l:path] = l:repo
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 return l:repo
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
155 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157
52
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
158 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo.
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
159 " If the file is not in a Mercurial repo, just exit silently.
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
160 function! s:setup_buffer_commands() abort
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
161 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...")
52
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
162 let l:do_setup = 1
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
163 if exists('b:mercurial_dir')
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
164 if b:mercurial_dir =~# '/^\s*$/'
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
165 unlet b:mercurial_dir
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
166 else
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
167 let l:do_setup = 0
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
168 endif
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
169 endif
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
170 try
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
171 let l:repo = s:hg_repo()
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
172 catch /^lawrencium\:/
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
173 return
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
174 endtry
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
175 let b:mercurial_dir = l:repo.root_dir
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
176 if exists('b:mercurial_dir') && l:do_setup
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
177 call s:trace("Setting Mercurial commands for buffer '" . bufname('%'))
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
178 call s:trace(" with repo : " . expand(b:mercurial_dir))
52
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
179 silent doautocmd User Lawrencium
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
180 endif
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
181 endfunction
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
182
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 augroup lawrencium_detect
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 autocmd!
52
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
185 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands()
05fd225bd1a0 Fixed detect autocmds.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
186 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 augroup end
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
191 " Commands {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
192
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 let s:main_commands = []
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 function! s:AddMainCommand(command) abort
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 let s:main_commands += [a:command]
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 function! s:DefineMainCommands()
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
200 for l:command in s:main_commands
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
201 execute 'command! -buffer ' . l:command
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 endfor
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 augroup lawrencium_main
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 autocmd!
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 autocmd User Lawrencium call s:DefineMainCommands()
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 augroup end
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 " HgExecute {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 function! s:HgExecute(...) abort
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 let l:repo = s:hg_repo()
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 echo call(l:repo.RunCommand, a:000, l:repo)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 call s:AddMainCommand("-nargs=* Hg :execute s:HgExecute(<f-args>)")
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223 " HgStatus {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 function! s:HgStatus() abort
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 echo s:hg_repo().RunCommand('status')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 call s:AddMainCommand("HgStatus :execute s:HgStatus()")
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 " Hgcd, Hglcd {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
236 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
237 call map(l:matches, 's:normalizepath(v:val)')
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 return l:matches
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
246 " Hgedit {{{
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
247
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
248 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
249 let l:matches = s:hg_repo().Glob(a:ArgLead . '*', 1)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
250 call map(l:matches, 's:normalizepath(v:val)')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
251 return l:matches
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
252 endfunction
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
253
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
254 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :edit<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
255
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
256 " }}}
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
257
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258 " Autoload Functions {{{
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
259
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
260 " Prints a summary of the current repo (if any) that's appropriate for
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
261 " displaying on the status line.
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262 function! lawrencium#statusline(...)
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 if !exists('b:mercurial_dir')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264 return ''
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265 endif
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 let l:summary = s:hg_repo().RunCommand('summary')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 let l:parent_rev = matchstr(l:summary, 'parent\: \d+\:[0-9a-f]+')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 let l:branch = matchstr(l:summary, 'branch\: [\d\w\-_\.]+')
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 return l:branch . ', ' . l:parent_rev
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 endfunction
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271
56
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
272 " Rescans the current buffer for setting up Mercurial commands.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
273 " Passing '1' as the parameter enables debug traces temporarily.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
274 function! lawrencium#rescan(...)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
275 if exists('b:mercurial_dir')
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
276 unlet b:mercurial_dir
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
277 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
278 if a:0 && a:1
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
279 let l:trace_backup = g:lawrencium_trace
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
280 let g:lawrencium_trace = 1
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
281 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
282 call s:setup_buffer_commands()
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
283 if a:0 && a:1
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
284 let g:lawrencium_trace = l:trace_backup
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
285 endif
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
286 endfunction
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
287
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
288 " Enables/disables the debug trace.
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
289 function! lawrencium#debugtrace(...)
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
290 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1))
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
291 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.")
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
292 endfunction
0dbb1fd60f71 Debugging features, better auto-complete, and a bug fix in the hg-repo detection code.
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
293
51
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 " }}}
a6bc310e7015 First version of lawrencium plugin.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295