Mercurial > vim-lawrencium
comparison plugin/lawrencium.vim @ 8:1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 11 Dec 2011 23:04:36 -0800 |
parents | adc267e2f0f4 |
children | 82a49134a85c |
comparison
equal
deleted
inserted
replaced
7:adc267e2f0f4 | 8:1e155bfa94ad |
---|---|
187 | 187 |
188 " }}} | 188 " }}} |
189 | 189 |
190 " Main Buffer Commands {{{ | 190 " Main Buffer Commands {{{ |
191 | 191 |
192 " Store the commands for Lawrencium-enabled buffers so that we can add them in | |
193 " batch when we need to. | |
192 let s:main_commands = [] | 194 let s:main_commands = [] |
193 | 195 |
194 function! s:AddMainCommand(command) abort | 196 function! s:AddMainCommand(command) abort |
195 let s:main_commands += [a:command] | 197 let s:main_commands += [a:command] |
196 endfunction | 198 endfunction |
204 augroup lawrencium_main | 206 augroup lawrencium_main |
205 autocmd! | 207 autocmd! |
206 autocmd User Lawrencium call s:DefineMainCommands() | 208 autocmd User Lawrencium call s:DefineMainCommands() |
207 augroup end | 209 augroup end |
208 | 210 |
211 " Auto-complete function for commands that take repo-relative file paths. | |
212 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort | |
213 let l:matches = s:hg_repo().Glob(a:ArgLead . '*', 1) | |
214 call map(l:matches, 's:normalizepath(v:val)') | |
215 return l:matches | |
216 endfunction | |
217 | |
218 " Auto-complete function for commands that take repo-relative directory paths. | |
219 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort | |
220 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/') | |
221 call map(l:matches, 's:normalizepath(v:val)') | |
222 return l:matches | |
223 endfunction | |
209 | 224 |
210 " Hg {{{ | 225 " Hg {{{ |
211 | 226 |
212 function! s:Hg(...) abort | 227 function! s:Hg(bang, ...) abort |
213 let l:repo = s:hg_repo() | 228 let l:repo = s:hg_repo() |
214 echo call(l:repo.RunCommand, a:000, l:repo) | 229 let l:output = call(l:repo.RunCommand, a:000, l:repo) |
215 endfunction | 230 if a:bang |
216 | 231 " Open the output of the command in a temp file. |
217 call s:AddMainCommand("-nargs=* Hg :execute s:Hg(<f-args>)") | 232 let l:temp_file = tempname() |
233 execute 'pedit ' . l:temp_file | |
234 wincmd p | |
235 call append(0, l:output) | |
236 else | |
237 " Just print out the output of the command. | |
238 echo l:output | |
239 endif | |
240 endfunction | |
241 | |
242 call s:AddMainCommand("-bang -nargs=* Hg :execute s:Hg(<bang>0, <f-args>)") | |
218 | 243 |
219 " }}} | 244 " }}} |
220 | 245 |
221 " Hgstatus {{{ | 246 " Hgstatus {{{ |
222 | 247 |
239 " Open a new temp buffer in the preview window, jump to it, | 264 " Open a new temp buffer in the preview window, jump to it, |
240 " and paste the `hg status` output in there. | 265 " and paste the `hg status` output in there. |
241 " Also, make it a nice size, but restore the `previewheight` setting after | 266 " Also, make it a nice size, but restore the `previewheight` setting after |
242 " we're done. | 267 " we're done. |
243 let l:temp_file = tempname() | 268 let l:temp_file = tempname() |
269 let l:temp_file = fnamemodify(l:temp_file, ':h') . 'hg-status-' . fnamemodify(l:temp_file, ':t') . '.txt' | |
244 let l:preview_height = &previewheight | 270 let l:preview_height = &previewheight |
245 execute "setlocal previewheight=" . (len(l:status_lines) + 1) | 271 execute "setlocal previewheight=" . (len(l:status_lines) + 1) |
246 execute "pedit " . l:temp_file | 272 execute "pedit " . l:temp_file |
247 wincmd p | 273 wincmd p |
248 call append(0, l:status_lines) | 274 call append(0, l:status_lines) |
285 | 311 |
286 " }}} | 312 " }}} |
287 | 313 |
288 " Hgcd, Hglcd {{{ | 314 " Hgcd, Hglcd {{{ |
289 | 315 |
290 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort | |
291 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/') | |
292 call map(l:matches, 's:normalizepath(v:val)') | |
293 return l:matches | |
294 endfunction | |
295 | |
296 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | 316 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") |
297 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | 317 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") |
298 | 318 |
299 " }}} | 319 " }}} |
300 | 320 |
301 " Hgedit {{{ | 321 " Hgedit {{{ |
302 | 322 |
303 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort | |
304 let l:matches = s:hg_repo().Glob(a:ArgLead . '*', 1) | |
305 call map(l:matches, 's:normalizepath(v:val)') | |
306 return l:matches | |
307 endfunction | |
308 | |
309 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :edit<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | 323 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :edit<bang> `=s:hg_repo().GetFullPath(<q-args>)`") |
324 | |
325 " }}} | |
326 | |
327 " Hgdiff {{{ | |
328 | |
329 function! s:HgDiff(filename, vertical, ...) abort | |
330 " Default revisions to diff: the working directory (special Lawrencium | |
331 " hard-coded syntax) and the parent of the working directory (using | |
332 " Mercurial's revsets syntax). | |
333 let l:rev1 = 'lawrencium#_wdir_' | |
334 let l:rev2 = 'p1()' | |
335 if a:0 == 1 | |
336 let l:rev2 = a:1 | |
337 elseif a:0 == 2 | |
338 let l:rev1 = a:1 | |
339 let l:rev2 = a:2 | |
340 endif | |
341 | |
342 " Get the current repo, and expand the given filename in case it contains | |
343 " fancy filename modifiers. | |
344 let l:repo = s:hg_repo() | |
345 let l:path = expand(a:filename) | |
346 call s:trace("Diff'ing '".l:rev1."' and '".l:rev2."' on file: ".l:path) | |
347 | |
348 " We'll keep a list of buffers in this diff, so when one exits, the | |
349 " others' 'diff' flag is turned off. | |
350 let l:diff_buffers = [] | |
351 | |
352 " Get the first file and open it. | |
353 if l:rev1 == 'lawrencium#_wdir_' | |
354 if bufexists(l:path) | |
355 execute 'buffer ' . fnameescape(l:path) | |
356 else | |
357 execute 'edit ' . fnameescape(l:path) | |
358 endif | |
359 else | |
360 let l:temp_file = tempname() | |
361 call l:repo.RunCommand('cat', '-r', '"'.l:rev1.'"', '-o', l:temp_file, l:path) | |
362 execute 'edit ' . fnameescape(l:temp_file) | |
363 endif | |
364 " Set it up to be part of the diff windows, set its repo dir. | |
365 diffthis | |
366 let b:mercurial_dir = l:repo.root_dir | |
367 | |
368 " Get the second file and open it too. | |
369 let l:diffsplit = 'diffsplit' | |
370 if a:vertical | |
371 let l:diffsplit = 'vertical diffsplit' | |
372 endif | |
373 if l:rev2 == 'lawrencium#_wdir_' | |
374 execute l:diffsplit . ' ' . fnameescape(l:path) | |
375 else | |
376 let l:temp_file = tempname() | |
377 call l:repo.RunCommand('cat', '-r', '"'.l:rev2.'"', '-o', l:temp_file, l:path) | |
378 execute l:diffsplit . ' ' . fnameescape(l:temp_file) | |
379 endif | |
380 " Set its repo dir. | |
381 let b:mercurial_dir = l:repo.root_dir | |
382 endfunction | |
383 | |
384 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiff :execute s:HgDiff('%:p', 0, <f-args>)") | |
385 call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiff :execute s:HgDiff('%:p', 1, <f-args>)") | |
310 | 386 |
311 " }}} | 387 " }}} |
312 | 388 |
313 " }}} | 389 " }}} |
314 | 390 |