Mercurial > vim-lawrencium
annotate plugin/lawrencium.vim @ 16:724f6db3baa2
Don't show `hg commit` output if there's nothing to show.
Fixed a regexp for `hg status`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 13 Dec 2011 17:17:03 -0800 |
parents | f02e37f395ae |
children | 5c6c605d0660 |
rev | line source |
---|---|
0 | 1 " lawrencium.vim - A Mercurial wrapper |
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com> | |
3 " Version: 0.1 | |
4 | |
5 " Globals {{{ | |
6 | |
7 if !exists('g:lawrencium_debug') | |
8 let g:lawrencium_debug = 0 | |
9 endif | |
10 | |
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug | |
12 finish | |
13 endif | |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
14 if (exists('g:loaded_lawrencium') && g:lawrencium_debug) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
15 echom "Reloaded Lawrencium." |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
16 endif |
0 | 17 let g:loaded_lawrencium = 1 |
18 | |
19 if !exists('g:lawrencium_hg_executable') | |
20 let g:lawrencium_hg_executable = 'hg' | |
21 endif | |
22 | |
23 if !exists('g:lawrencium_trace') | |
24 let g:lawrencium_trace = 0 | |
25 endif | |
26 | |
27 " }}} | |
28 | |
29 " Utility {{{ | |
30 | |
31 " Strips the ending slash in a path. | |
32 function! s:stripslash(path) | |
33 return fnamemodify(a:path, ':s?[/\\]$??') | |
34 endfunction | |
35 | |
36 " Normalizes the slashes in a path. | |
37 function! s:normalizepath(path) | |
38 if exists('+shellslash') && &shellslash | |
39 return substitute(a:path, '\\', '/', '') | |
40 elseif has('win32') | |
41 return substitute(a:path, '/', '\\', '') | |
42 else | |
43 return a:path | |
44 endif | |
45 endfunction | |
46 | |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
47 " Like tempname() but with some control over the filename. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
48 function! s:tempname(name, ...) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
49 let l:path = tempname() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
50 let l:result = fnamemodify(l:path, ':h') . '/' . a:name . fnamemodify(l:path, ':t') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
51 if a:0 > 0 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
52 let l:result = l:result . a:1 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
53 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
54 return l:result |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
55 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
56 |
0 | 57 " Prints a message if debug tracing is enabled. |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
58 function! s:trace(message, ...) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
59 if g:lawrencium_trace || (a:0 && a:1) |
0 | 60 let l:message = "lawrencium: " . a:message |
61 echom l:message | |
62 endif | |
63 endfunction | |
64 | |
65 " Throw a Lawrencium exception message. | |
66 function! s:throw(message) | |
67 let v:errmsg = "lawrencium: " . a:message | |
68 throw v:errmsg | |
69 endfunction | |
70 | |
71 " Finds the repository root given a path inside that repository. | |
72 " Throw an error if not repository is found. | |
73 function! s:find_repo_root(path) | |
74 let l:path = s:stripslash(a:path) | |
75 let l:previous_path = "" | |
76 while l:path != l:previous_path | |
77 if isdirectory(l:path . '/.hg/store') | |
78 return simplify(fnamemodify(l:path, ':p')) | |
79 endif | |
80 let l:previous_path = l:path | |
81 let l:path = fnamemodify(l:path, ':h') | |
82 endwhile | |
83 call s:throw("No Mercurial repository found above: " . a:path) | |
84 endfunction | |
85 | |
86 " }}} | |
87 | |
88 " Mercurial Repository {{{ | |
89 | |
90 " Let's define a Mercurial repo 'class' using prototype-based object-oriented | |
91 " programming. | |
92 " | |
93 " The prototype dictionary. | |
94 let s:HgRepo = {} | |
95 | |
96 " Constructor | |
97 function! s:HgRepo.New(path) abort | |
98 let l:newRepo = copy(self) | |
99 let l:newRepo.root_dir = s:find_repo_root(a:path) | |
100 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir) | |
101 return l:newRepo | |
102 endfunction | |
103 | |
104 " Gets a full path given a repo-relative path | |
105 function! s:HgRepo.GetFullPath(path) abort | |
106 let l:root_dir = self.root_dir | |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
107 if a:path =~# '\v^[/\\]' |
0 | 108 let l:root_dir = s:stripslash(l:root_dir) |
109 endif | |
110 return l:root_dir . a:path | |
111 endfunction | |
112 | |
113 " Gets a list of files matching a root-relative pattern. | |
114 " If a flag is passed and is TRUE, a slash will be appended to all | |
115 " directories. | |
116 function! s:HgRepo.Glob(pattern, ...) abort | |
117 let l:root_dir = self.root_dir | |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
118 if (a:pattern =~# '\v^[/\\]') |
0 | 119 let l:root_dir = s:stripslash(l:root_dir) |
120 endif | |
121 let l:matches = split(glob(l:root_dir . a:pattern), '\n') | |
122 if a:0 && a:1 | |
123 for l:idx in range(len(l:matches)) | |
124 if !filereadable(l:matches[l:idx]) | |
125 let l:matches[l:idx] = l:matches[l:idx] . '/' | |
126 endif | |
127 endfor | |
128 endif | |
129 let l:strip_len = len(l:root_dir) | |
130 call map(l:matches, 'v:val[l:strip_len : -1]') | |
131 return l:matches | |
132 endfunction | |
133 | |
134 " Runs a Mercurial command in the repo | |
135 function! s:HgRepo.RunCommand(command, ...) abort | |
136 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) | |
137 let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(a:000, ' ') | |
138 call s:trace("Running Mercurial command: " . l:hg_command) | |
139 return system(l:hg_command) | |
140 endfunction | |
141 | |
142 " Repo cache map | |
143 let s:buffer_repos = {} | |
144 | |
145 " Get a cached repo | |
146 function! s:hg_repo(...) abort | |
147 " Use the given path, or the mercurial directory of the current buffer. | |
148 if a:0 == 0 | |
149 if exists('b:mercurial_dir') | |
150 let l:path = b:mercurial_dir | |
151 else | |
152 let l:path = s:find_repo_root(expand('%:p')) | |
153 endif | |
154 else | |
155 let l:path = a:1 | |
156 endif | |
157 " Find a cache repo instance, or make a new one. | |
158 if has_key(s:buffer_repos, l:path) | |
159 return get(s:buffer_repos, l:path) | |
160 else | |
161 let l:repo = s:HgRepo.New(l:path) | |
162 let s:buffer_repos[l:path] = l:repo | |
163 return l:repo | |
164 endif | |
165 endfunction | |
166 | |
167 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo. | |
168 " If the file is not in a Mercurial repo, just exit silently. | |
169 function! s:setup_buffer_commands() abort | |
170 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...") | |
171 let l:do_setup = 1 | |
172 if exists('b:mercurial_dir') | |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
173 if b:mercurial_dir =~# '\v^\s*$' |
0 | 174 unlet b:mercurial_dir |
175 else | |
176 let l:do_setup = 0 | |
177 endif | |
178 endif | |
179 try | |
180 let l:repo = s:hg_repo() | |
181 catch /^lawrencium\:/ | |
182 return | |
183 endtry | |
184 let b:mercurial_dir = l:repo.root_dir | |
185 if exists('b:mercurial_dir') && l:do_setup | |
186 call s:trace("Setting Mercurial commands for buffer '" . bufname('%')) | |
187 call s:trace(" with repo : " . expand(b:mercurial_dir)) | |
188 silent doautocmd User Lawrencium | |
189 endif | |
190 endfunction | |
191 | |
192 augroup lawrencium_detect | |
193 autocmd! | |
194 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() | |
195 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif | |
196 augroup end | |
197 | |
198 " }}} | |
199 | |
14 | 200 " Buffer Commands Management {{{ |
0 | 201 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
202 " Store the commands for Lawrencium-enabled buffers so that we can add them in |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
203 " batch when we need to. |
0 | 204 let s:main_commands = [] |
205 | |
206 function! s:AddMainCommand(command) abort | |
207 let s:main_commands += [a:command] | |
208 endfunction | |
209 | |
210 function! s:DefineMainCommands() | |
211 for l:command in s:main_commands | |
212 execute 'command! -buffer ' . l:command | |
213 endfor | |
214 endfunction | |
215 | |
216 augroup lawrencium_main | |
217 autocmd! | |
218 autocmd User Lawrencium call s:DefineMainCommands() | |
219 augroup end | |
220 | |
14 | 221 " }}} |
222 | |
223 " Commands Auto-Complete {{{ | |
224 | |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
225 " Auto-complete function for commands that take repo-relative file paths. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
226 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
227 let l:matches = s:hg_repo().Glob(a:ArgLead . '*', 1) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
228 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
229 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
230 endfunction |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
231 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
232 " Auto-complete function for commands that take repo-relative directory paths. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
233 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
234 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
235 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
236 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
237 endfunction |
0 | 238 |
14 | 239 " }}} |
240 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
241 " Hg {{{ |
0 | 242 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
243 function! s:Hg(bang, ...) abort |
0 | 244 let l:repo = s:hg_repo() |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
245 let l:output = call(l:repo.RunCommand, a:000, l:repo) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
246 if a:bang |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
247 " Open the output of the command in a temp file. |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
248 let l:temp_file = s:tempname('hg-output-', '.txt') |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
249 execute 'pedit ' . l:temp_file |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
250 wincmd p |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
251 call append(0, l:output) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
252 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
253 " Just print out the output of the command. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
254 echo l:output |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
255 endif |
0 | 256 endfunction |
257 | |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
258 " Include the generated HG usage file. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
259 let s:usage_file = expand("<sfile>:h:h") . "/resources/hg_usage.vim" |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
260 if filereadable(s:usage_file) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
261 execute "source " . s:usage_file |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
262 else |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
263 echoerr "Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium." |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
264 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
265 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
266 function! s:CompleteHg(ArgLead, CmdLine, CursorPos) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
267 " Don't do anything if the usage file was not sourced. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
268 if !exists('g:lawrencium_hg_commands') || !exists('g:lawrencium_hg_options') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
269 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
270 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
271 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
272 " a:ArgLead seems to be the number 0 when completing a minus '-'. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
273 " Gotta find out why... |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
274 let l:arglead = a:ArgLead |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
275 if type(a:ArgLead) == type(0) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
276 let l:arglead = '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
277 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
278 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
279 " Try completing a global option, before any command name. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
280 if a:CmdLine =~# '\v^Hg(\s+\-[a-zA-Z0-9\-_]*)+$' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
281 return filter(copy(g:lawrencium_hg_options), "v:val[0:strlen(l:arglead)-1] ==# l:arglead") |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
282 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
283 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
284 " Try completing a command (note that there could be global options before |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
285 " the command name). |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
286 if a:CmdLine =~# '\v^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*[a-zA-Z]+$' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
287 echom " - matched command" |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
288 return filter(keys(g:lawrencium_hg_commands), "v:val[0:strlen(l:arglead)-1] ==# l:arglead") |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
289 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
290 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
291 " Try completing a command's options. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
292 let l:cmd = matchstr(a:CmdLine, '\v(^Hg\s+(\-[a-zA-Z0-9\-_]+\s+)*)@<=[a-zA-Z]+') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
293 if strlen(l:cmd) > 0 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
294 echom " - matched command option for " . l:cmd . " with : " . l:arglead |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
295 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
296 if strlen(l:cmd) > 0 && l:arglead[0] ==# '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
297 if has_key(g:lawrencium_hg_commands, l:cmd) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
298 " Return both command options and global options together. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
299 let l:copts = filter(copy(g:lawrencium_hg_commands[l:cmd]), "v:val[0:strlen(l:arglead)-1] ==# l:arglead") |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
300 let l:gopts = filter(copy(g:lawrencium_hg_options), "v:val[0:strlen(l:arglead)-1] ==# l:arglead") |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
301 return l:copts + l:gopts |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
302 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
303 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
304 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
305 " Just auto-complete with filenames unless it's an option. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
306 if l:arglead[0] ==# '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
307 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
308 else |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
309 return s:ListRepoFiles(a:ArgLead, a:CmdLine, a:CursorPos) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
310 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
311 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
312 call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :execute s:Hg(<bang>0, <f-args>)") |
0 | 313 |
314 " }}} | |
315 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
316 " Hgstatus {{{ |
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
317 |
0 | 318 function! s:HgStatus() abort |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
319 " Get the repo and the `hg status` output. |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
320 let l:repo = s:hg_repo() |
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
321 let l:status_text = l:repo.RunCommand('status') |
16
724f6db3baa2
Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
322 if l:status_text ==# '\v%^\s*%$' |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
323 echo "Nothing modified." |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
324 endif |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
325 |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
326 " Open a new temp buffer in the preview window, jump to it, |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
327 " and paste the `hg status` output in there. |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
328 let l:temp_file = s:tempname('hg-status-', '.txt') |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
329 let l:preview_height = &previewheight |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
330 let l:status_lines = split(l:status_text, '\n') |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
331 execute "setlocal previewheight=" . (len(l:status_lines) + 1) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
332 execute "pedit " . l:temp_file |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
333 wincmd p |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
334 call append(0, l:status_lines) |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
335 " Make it a nice size. |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
336 execute "setlocal previewheight=" . l:preview_height |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
337 " Make sure it's deleted when we exit the window. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
338 setlocal bufhidden=delete |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
339 |
7
adc267e2f0f4
Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
340 " Setup the buffer correctly: readonly, and with the correct repo linked |
adc267e2f0f4
Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
341 " to it. |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
342 let b:mercurial_dir = l:repo.root_dir |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
343 setlocal buftype=nofile |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
344 setlocal nomodified |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
345 setlocal nomodifiable |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
346 setlocal readonly |
7
adc267e2f0f4
Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
6
diff
changeset
|
347 setlocal syntax=hgstatus |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
348 |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
349 " Add some handy mappings. |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
350 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr> |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
351 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.','Wbe')<cr> |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
352 nnoremap <buffer> <silent> <cr> :execute <SID>HgStatus_FileEdit()<cr> |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
353 nnoremap <buffer> <silent> <C-D> :execute <SID>HgStatus_FileDiff(0)<cr> |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
354 nnoremap <buffer> <silent> <C-V> :execute <SID>HgStatus_FileDiff(1)<cr> |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
355 nnoremap <buffer> <silent> <C-A> :execute <SID>HgStatus_FileAdd()<cr> |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
356 nnoremap <buffer> <silent> <C-R> :execute <SID>HgStatus_Refresh()<cr> |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
357 nnoremap <buffer> <silent> q :bdelete<cr> |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
358 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
359 " Make sure the file is deleted with the buffer. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
360 autocmd BufDelete <buffer> call s:HgStatus_CleanUp(expand('<afile>:p')) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
361 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
362 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
363 function! s:HgStatus_CleanUp(path) abort |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
364 " If the `hg status` output has been saved to disk (e.g. because of a |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
365 " refresh we did), let's delete it. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
366 if filewritable(a:path) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
367 call s:trace("Cleaning up status log: " . a:path) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
368 call delete(a:path) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
369 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
370 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
371 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
372 function! s:HgStatus_Refresh() abort |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
373 " Get the repo and the `hg status` output. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
374 let l:repo = s:hg_repo() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
375 let l:status_text = l:repo.RunCommand('status') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
376 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
377 " Replace the contents of the current buffer with it, and refresh. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
378 echo "Writing to " . expand('%:p') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
379 let l:path = expand('%:p') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
380 let l:status_lines = split(l:status_text, '\n') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
381 call writefile(l:status_lines, l:path) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
382 edit |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
383 endfunction |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
384 |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
385 function! s:HgStatus_FileEdit() abort |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
386 " Get the path of the file the cursor is on. |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
387 let l:filename = s:HgStatus_GetSelectedPath() |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
388 |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
389 " Go back to the previous window and open the file there, or open an |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
390 " existing buffer. |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
391 wincmd p |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
392 if bufexists(l:filename) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
393 execute 'buffer ' . l:filename |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
394 else |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
395 execute 'edit ' . l:filename |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
396 endif |
0 | 397 endfunction |
398 | |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
399 function! s:HgStatus_FileAdd() abort |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
400 " Get the path of the file the cursor is on, and its status. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
401 let l:filename = s:HgStatus_GetSelectedPath() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
402 let l:status = s:HgStatus_GetSelectedStatus() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
403 if l:status !=# '?' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
404 echoerr "Not an untracked file: " . l:filename |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
405 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
406 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
407 " Add the file. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
408 let l:repo = s:hg_repo() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
409 call l:repo.RunCommand('add', l:filename) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
410 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
411 " Refresh the status window. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
412 call s:HgStatus_Refresh() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
413 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
414 |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
415 function! s:HgStatus_FileDiff(vertical) abort |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
416 " Get the path of the file the cursor is on. |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
417 let l:filename = s:HgStatus_GetSelectedPath() |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
418 |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
419 " Go back to the previous window and call HgDiff. |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
420 wincmd p |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
421 call s:HgDiff(l:filename, a:vertical) |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
422 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
423 |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
424 function! s:HgStatus_GetSelectedPath() abort |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
425 let l:repo = s:hg_repo() |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
426 let l:line = getline('.') |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
427 " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
428 " look-aheads and look-behinds. See for yourself: |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
429 let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*') |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
430 let l:filename = l:repo.GetFullPath(l:filename) |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
431 return l:filename |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
432 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
433 |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
434 function! s:HgStatus_GetSelectedStatus() abort |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
435 let l:line = getline('.') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
436 return matchstr(l:line, '\v^[MARC\!\?I ]') |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
437 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
438 |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
439 call s:AddMainCommand("Hgstatus :execute s:HgStatus()") |
0 | 440 |
441 " }}} | |
442 | |
443 " Hgcd, Hglcd {{{ | |
444 | |
445 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
446 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
447 | |
448 " }}} | |
449 | |
450 " Hgedit {{{ | |
451 | |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
452 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :edit<bang> `=s:hg_repo().GetFullPath(<q-args>)`") |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
453 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
454 " }}} |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
455 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
456 " Hgdiff {{{ |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
457 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
458 function! s:HgDiff(filename, vertical, ...) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
459 " Default revisions to diff: the working directory (special Lawrencium |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
460 " hard-coded syntax) and the parent of the working directory (using |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
461 " Mercurial's revsets syntax). |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
462 let l:rev1 = 'lawrencium#_wdir_' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
463 let l:rev2 = 'p1()' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
464 if a:0 == 1 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
465 let l:rev2 = a:1 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
466 elseif a:0 == 2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
467 let l:rev1 = a:1 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
468 let l:rev2 = a:2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
469 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
470 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
471 " Get the current repo, and expand the given filename in case it contains |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
472 " fancy filename modifiers. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
473 let l:repo = s:hg_repo() |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
474 let l:path = expand(a:filename) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
475 call s:trace("Diff'ing '".l:rev1."' and '".l:rev2."' on file: ".l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
476 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
477 " We'll keep a list of buffers in this diff, so when one exits, the |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
478 " others' 'diff' flag is turned off. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
479 let l:diff_buffers = [] |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
480 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
481 " Get the first file and open it. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
482 if l:rev1 == 'lawrencium#_wdir_' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
483 if bufexists(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
484 execute 'buffer ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
485 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
486 execute 'edit ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
487 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
488 " Make it part of the diff group. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
489 diffthis |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
490 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
491 let l:temp_file = tempname() |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
492 call l:repo.RunCommand('cat', '-r', '"'.l:rev1.'"', '-o', l:temp_file, l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
493 execute 'edit ' . fnameescape(l:temp_file) |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
494 " Make it part of the diff group. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
495 diffthis |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
496 " Remember the repo it belongs to. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
497 let b:mercurial_dir = l:repo.root_dir |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
498 " Make sure it's deleted when we move away from it. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
499 setlocal bufhidden=delete |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
500 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
501 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
502 " Get the second file and open it too. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
503 let l:diffsplit = 'diffsplit' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
504 if a:vertical |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
505 let l:diffsplit = 'vertical diffsplit' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
506 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
507 if l:rev2 == 'lawrencium#_wdir_' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
508 execute l:diffsplit . ' ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
509 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
510 let l:temp_file = tempname() |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
511 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', l:temp_file, l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
512 execute l:diffsplit . ' ' . fnameescape(l:temp_file) |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
513 " Remember the repo it belongs to. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
514 let b:mercurial_dir = l:repo.root_dir |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
515 " Make sure it's deleted when we move away from it. |
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
516 setlocal bufhidden=delete |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
517 endif |
0 | 518 endfunction |
519 | |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
520 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiff :execute s:HgDiff('%:p', 0, <f-args>)") |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
521 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiff :execute s:HgDiff('%:p', 1, <f-args>)") |
0 | 522 |
523 " }}} | |
524 | |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
525 " Hgcommit {{{ |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
526 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
527 function! s:HgCommit(bang, vertical) abort |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
528 " Get the repo we'll be committing into. |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
529 let l:repo = s:hg_repo() |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
530 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
531 " Open a commit message file. |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
532 let l:commit_path = s:tempname('hg-editor-', '.txt') |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
533 let l:split = a:vertical ? 'vsplit' : 'split' |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
534 execute l:split . ' ' . l:commit_path |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
535 call append(0, ['', '']) |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
536 call append(2, split(s:HgCommit_GenerateMessage(l:repo), '\n')) |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
537 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
538 " Setup the auto-command that will actually commit on write/exit, |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
539 " and make the buffer delete itself on exit. |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
540 let b:mercurial_dir = l:repo.root_dir |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
541 setlocal bufhidden=delete |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
542 setlocal syntax=hgcommit |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
543 if a:bang |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
544 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 0) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
545 else |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
546 autocmd BufDelete <buffer> call s:HgCommit_Execute(expand('<afile>:p'), 1) |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
547 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
548 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
549 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
550 let s:hg_status_messages = { |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
551 \'M': 'modified', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
552 \'A': 'added', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
553 \'R': 'removed', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
554 \'C': 'clean', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
555 \'!': 'missing', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
556 \'?': 'not tracked', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
557 \'I': 'ignored', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
558 \' ': '', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
559 \} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
560 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
561 function! s:HgCommit_GenerateMessage(repo) abort |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
562 let l:msg = "HG: Enter commit message. Lines beginning with 'HG:' are removed.\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
563 let l:msg .= "HG: Leave message empty to abort commit.\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
564 let l:msg .= "HG: Write and quit buffer to proceed.\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
565 let l:msg .= "HG: --\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
566 let l:msg .= "HG: user: " . split(a:repo.RunCommand('showconfig ui.username'), '\n')[0] . "\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
567 let l:msg .= "HG: branch '" . split(a:repo.RunCommand('branch'), '\n')[0] . "'\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
568 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
569 let l:status_lines = split(a:repo.RunCommand('status'), "\n") |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
570 for l:line in l:status_lines |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
571 if l:line ==# '' |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
572 continue |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
573 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
574 let l:type = matchstr(l:line, '\v^[MARC\!\?I ]') |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
575 let l:path = l:line[2:] |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
576 let l:msg .= "HG: " . s:hg_status_messages[l:type] . ' ' . l:path . "\n" |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
577 endfor |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
578 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
579 return l:msg |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
580 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
581 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
582 function! s:HgCommit_Execute(log_file, show_output) abort |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
583 " Check if the user actually saved a commit message. |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
584 if !filereadable(a:log_file) |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
585 call s:trace("Commit message was not saved... abort commit.", 1) |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
586 return |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
587 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
588 |
12
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
589 call s:trace("Committing with log file: " . a:log_file) |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
590 |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
591 " Clean up all the 'HG:' lines from the commit message. |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
592 let l:lines = readfile(a:log_file) |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
593 call filter(l:lines, "v:val !~# '\\v^HG:'") |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
594 call writefile(l:lines, a:log_file) |
a7bf37a97a1b
Clean the 'HG:' lines from the commit message (apparently 'hg commit' doesn't do it with -o).
Ludovic Chabant <ludovic@chabant.com>
parents:
11
diff
changeset
|
595 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
596 " Get the repo and commit with the given message. |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
597 let l:repo = s:hg_repo() |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
598 let l:output = l:repo.RunCommand('commit', '-l', a:log_file) |
16
724f6db3baa2
Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
599 if a:show_output && l:output !~# '\v%^\s*%$' |
724f6db3baa2
Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents:
15
diff
changeset
|
600 call s:trace("Output from hg commit:", 1) |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
601 echom l:output |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
602 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
603 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
604 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
605 call s:AddMainCommand("-bang Hgcommit :execute s:HgCommit(<bang>0, 0)") |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
606 call s:AddMainCommand("-bang Hgvcommit :execute s:HgCommit(<bang>0, 1)") |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
607 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
608 " }}} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
609 |
0 | 610 " Autoload Functions {{{ |
611 | |
612 " Prints a summary of the current repo (if any) that's appropriate for | |
613 " displaying on the status line. | |
614 function! lawrencium#statusline(...) | |
615 if !exists('b:mercurial_dir') | |
616 return '' | |
617 endif | |
5
3a4f9f41a7e2
Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
618 let l:prefix = (a:0 > 0 ? a:1 : '') |
3a4f9f41a7e2
Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
619 let l:suffix = (a:0 > 1 ? a:2 : '') |
3a4f9f41a7e2
Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
620 let l:branch_file = s:hg_repo().GetFullPath('.hg/branch') |
3a4f9f41a7e2
Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
621 let l:branch = readfile(l:branch_file)[0] |
3a4f9f41a7e2
Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents:
4
diff
changeset
|
622 return l:prefix . l:branch . l:suffix |
0 | 623 endfunction |
624 | |
625 " Rescans the current buffer for setting up Mercurial commands. | |
626 " Passing '1' as the parameter enables debug traces temporarily. | |
627 function! lawrencium#rescan(...) | |
628 if exists('b:mercurial_dir') | |
629 unlet b:mercurial_dir | |
630 endif | |
631 if a:0 && a:1 | |
632 let l:trace_backup = g:lawrencium_trace | |
633 let g:lawrencium_trace = 1 | |
634 endif | |
635 call s:setup_buffer_commands() | |
636 if a:0 && a:1 | |
637 let g:lawrencium_trace = l:trace_backup | |
638 endif | |
639 endfunction | |
640 | |
641 " Enables/disables the debug trace. | |
642 function! lawrencium#debugtrace(...) | |
643 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1)) | |
644 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.") | |
645 endfunction | |
646 | |
647 " }}} | |
648 |