annotate plugin/lawrencium.vim @ 58:621185a5fa48

Added ability to show diff summaries from the status window.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 14 Nov 2012 22:21:30 -0800
parents 220c9508ff62
children 396da6e76952
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 " lawrencium.vim - A Mercurial wrapper
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com>
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 " Version: 0.1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 " Globals {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 if !exists('g:lawrencium_debug')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 let g:lawrencium_debug = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 finish
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 let g:loaded_lawrencium = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 if !exists('g:lawrencium_hg_executable')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 let g:lawrencium_hg_executable = 'hg'
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
23 if !exists('g:lawrencium_auto_cd')
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
24 let g:lawrencium_auto_cd = 1
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
25 endif
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
26
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 if !exists('g:lawrencium_trace')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 let g:lawrencium_trace = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
31 if !exists('g:lawrencium_define_mappings')
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
32 let g:lawrencium_define_mappings = 1
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
33 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
34
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 " Utility {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 " Strips the ending slash in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 function! s:stripslash(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 return fnamemodify(a:path, ':s?[/\\]$??')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 " Normalizes the slashes in a path.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 function! s:normalizepath(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 if exists('+shellslash') && &shellslash
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
47 return substitute(a:path, '\v/', '\\', 'g')
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 elseif has('win32')
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
49 return substitute(a:path, '\v/', '\\', 'g')
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 return a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
55 " Shell-slashes the path (opposite of `normalizepath`).
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
56 function! s:shellslash(path)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
57 if exists('+shellslash') && !&shellslash
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
58 return substitute(a:path, '\v\\', '/', 'g')
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
59 else
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
60 return a:path
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
61 endif
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
62 endfunction
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
63
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
64 " 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
65 function! s:tempname(name, ...)
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
66 let l:path = tempname()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
67 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
68 if a:0 > 0
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
69 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
70 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
71 return l:result
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
72 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
73
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
74 " Delete a temporary file if it exists.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
75 function! s:clean_tempfile(path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
76 if filewritable(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
77 call s:trace("Cleaning up temporary file: " . a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
78 call delete(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
79 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
80 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
81
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 " Prints a message if debug tracing is enabled.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
83 function! s:trace(message, ...)
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
84 if g:lawrencium_trace || (a:0 && a:1)
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 let l:message = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 echom l:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
90 " Prints an error message with 'lawrencium error' prefixed to it.
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
91 function! s:error(message)
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
92 echom "lawrencium error: " . a:message
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
93 endfunction
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
94
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 " Throw a Lawrencium exception message.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 function! s:throw(message)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 let v:errmsg = "lawrencium: " . a:message
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 throw v:errmsg
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 " Finds the repository root given a path inside that repository.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 " Throw an error if not repository is found.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 function! s:find_repo_root(path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 let l:path = s:stripslash(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 let l:previous_path = ""
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 while l:path != l:previous_path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 if isdirectory(l:path . '/.hg/store')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 return simplify(fnamemodify(l:path, ':p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 let l:previous_path = l:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 let l:path = fnamemodify(l:path, ':h')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 endwhile
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 call s:throw("No Mercurial repository found above: " . a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
116 " Given a Lawrencium path (e.g: 'lawrencium:///repo/root_dir//foo/bar/file.py//rev=34'), extract
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
117 " the repository root, relative file path and revision number/changeset ID.
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
118 function! s:parse_lawrencium_path(lawrencium_path, ...)
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
119 let l:repo_path = s:shellslash(a:lawrencium_path)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
120 if l:repo_path =~? '\v^lawrencium://'
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
121 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://'))
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
122 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
123
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
124 let l:root_dir = ''
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
125 let l:at_idx = stridx(l:repo_path, '//')
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
126 if l:at_idx >= 0
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
127 let l:root_dir = strpart(l:repo_path, 0, l:at_idx)
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
128 let l:repo_path = strpart(l:repo_path, l:at_idx + 2)
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
129 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
130
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
131 let l:value = ''
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
132 let l:action = ''
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
133 let l:actionidx = stridx(l:repo_path, '//')
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
134 if l:actionidx >= 0
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
135 let l:action = strpart(l:repo_path, l:actionidx + 2)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
136 let l:repo_path = strpart(l:repo_path, 0, l:actionidx)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
137
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
138 let l:equalidx = stridx(l:action, '=')
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
139 if l:equalidx >= 0
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
140 let l:value = strpart(l:action, l:equalidx + 1)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
141 let l:action = strpart(l:action, 0, l:equalidx)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
142 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
143 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
144
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
145 if a:0 > 0
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
146 execute 'cd! ' . l:root_dir
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
147 if a:1 == 'relative'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
148 let l:repo_path = fnamemodify(l:repo_path, ':.')
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
149 elseif a:1 == 'absolute'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
150 let l:repo_path = fnamemodify(l:repo_path, ':p')
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
151 endif
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
152 execute 'cd! -'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
153 endif
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
154
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
155 let l:result = { 'root': l:root_dir, 'path': l:repo_path, 'action': l:action, 'value': l:value }
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
156 return l:result
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
157 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
158
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 " Mercurial Repository {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 " Let's define a Mercurial repo 'class' using prototype-based object-oriented
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 " programming.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165 "
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
166 " The prototype dictionary.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
167 let s:HgRepo = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
168
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
169 " Constructor.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 function! s:HgRepo.New(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171 let l:newRepo = copy(self)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 let l:newRepo.root_dir = s:find_repo_root(a:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 return l:newRepo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
177 " Gets a full path given a repo-relative path.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 function! s:HgRepo.GetFullPath(path) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 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
180 if a:path =~# '\v^[/\\]'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 return l:root_dir . a:path
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
186 function! s:HgRepo.GetRelativePath(path) abort
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
187 execute 'cd! ' . self.root_dir
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
188 let l:relative_path = fnamemodify(a:path, ':.')
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
189 execute 'cd! -'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
190 return l:relative_path
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
191 endfunction
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
192
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 " Gets a list of files matching a root-relative pattern.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 " If a flag is passed and is TRUE, a slash will be appended to all
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 " directories.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 function! s:HgRepo.Glob(pattern, ...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 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
198 if (a:pattern =~# '\v^[/\\]')
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 let l:root_dir = s:stripslash(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 let l:matches = split(glob(l:root_dir . a:pattern), '\n')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 for l:idx in range(len(l:matches))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 if !filereadable(l:matches[l:idx])
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 let l:matches[l:idx] = l:matches[l:idx] . '/'
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 let l:strip_len = len(l:root_dir)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 call map(l:matches, 'v:val[l:strip_len : -1]')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 return l:matches
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
214 " Gets a full Mercurial command.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
215 function! s:HgRepo.GetCommand(command, ...) abort
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
216 " If there's only one argument, and it's a list, then use that as the
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
217 " argument list.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
218 let l:arg_list = a:000
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
219 if a:0 == 1 && type(a:1) == type([])
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
220 let l:arg_list = a:1
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
221 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir))
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
223 let l:hg_command = l:hg_command . ' ' . a:command . ' ' . join(l:arg_list, ' ')
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
224 return l:hg_command
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
225 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
226
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
227 " Runs a Mercurial command in the repo.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
228 function! s:HgRepo.RunCommand(command, ...) abort
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
229 let l:all_args = [a:command] + a:000
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
230 let l:hg_command = call(self['GetCommand'], l:all_args, self)
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 call s:trace("Running Mercurial command: " . l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232 return system(l:hg_command)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
235 " Runs a Mercurial command in the repo and read it output into the current
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
236 " buffer.
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
237 function! s:HgRepo.ReadCommandOutput(command, ...) abort
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
238 let l:all_args = [a:command] + a:000
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
239 let l:hg_command = call(self['GetCommand'], l:all_args, self)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
240 call s:trace("Running Mercurial command: " . l:hg_command)
57
220c9508ff62 Fixes for Lawrencium files:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
241 execute '0read !' . escape(l:hg_command, '%#\')
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
242 endfunction
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
243
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
244 " Build a Lawrencium path for the given file and action.
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
245 " By default, the given path will be made relative to the repository root,
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
246 " unless '0' is passed as the 4th argument.
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
247 function! s:HgRepo.GetLawrenciumPath(path, action, value, ...) abort
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
248 let l:path = a:path
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
249 if a:0 == 0 || !a:1
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
250 let l:path = self.GetRelativePath(a:path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
251 endif
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
252 let l:result = 'lawrencium://' . s:stripslash(self.root_dir) . '//' . l:path
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
253 if a:action !=? ''
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
254 let l:result = l:result . '//' . a:action
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
255 if a:value !=? ''
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
256 let l:result = l:result . '=' . a:value
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
257 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
258 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
259 return l:result
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
260 endfunction
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
261
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
262 " Repo cache map.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 let s:buffer_repos = {}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
265 " Get a cached repo.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 function! s:hg_repo(...) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 " Use the given path, or the mercurial directory of the current buffer.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 if a:0 == 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 let l:path = b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 let l:path = s:find_repo_root(expand('%:p'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 let l:path = a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277 " Find a cache repo instance, or make a new one.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278 if has_key(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279 return get(s:buffer_repos, l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
280 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
281 let l:repo = s:HgRepo.New(l:path)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
282 let s:buffer_repos[l:path] = l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
283 return l:repo
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
284 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
285 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
286
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
287 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
288 " If the file is not in a Mercurial repo, just exit silently.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
289 function! s:setup_buffer_commands() abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
290 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
291 let l:do_setup = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
292 if exists('b:mercurial_dir')
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
293 if b:mercurial_dir =~# '\v^\s*$'
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295 else
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 let l:do_setup = 0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
297 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
298 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299 try
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 let l:repo = s:hg_repo()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 catch /^lawrencium\:/
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
302 return
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 endtry
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
304 let b:mercurial_dir = l:repo.root_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
305 if exists('b:mercurial_dir') && l:do_setup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306 call s:trace("Setting Mercurial commands for buffer '" . bufname('%'))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
307 call s:trace(" with repo : " . expand(b:mercurial_dir))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
308 silent doautocmd User Lawrencium
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
309 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
310 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
311
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
312 augroup lawrencium_detect
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
313 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
314 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
315 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
316 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
317
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
318 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
320 " Buffer Commands Management {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
322 " 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
323 " batch when we need to.
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
324 let s:main_commands = []
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
325
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
326 function! s:AddMainCommand(command) abort
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
327 let s:main_commands += [a:command]
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
328 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
329
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
330 function! s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
331 for l:command in s:main_commands
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
332 execute 'command! -buffer ' . l:command
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
333 endfor
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 augroup lawrencium_main
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337 autocmd!
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 autocmd User Lawrencium call s:DefineMainCommands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339 augroup end
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
341 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
342
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
343 " Commands Auto-Complete {{{
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
344
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
345 " 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
346 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
347 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
348 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
349 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
350 endfunction
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
351
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
352 " 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
353 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
354 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
355 call map(l:matches, 's:normalizepath(v:val)')
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
356 return l:matches
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
357 endfunction
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
358
14
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
359 " }}}
eab2680e6818 Better fold sections.
Ludovic Chabant <ludovic@chabant.com>
parents: 12
diff changeset
360
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
361 " Hg {{{
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
362
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
363 function! s:Hg(bang, ...) abort
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
364 let l:repo = s:hg_repo()
44
95f8e7cb5ca2 Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents: 43
diff changeset
365 if g:lawrencium_auto_cd
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
366 " Temporary set the current directory to the root of the repo
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
367 " to make auto-completed paths work magically.
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
368 execute 'cd! ' . l:repo.root_dir
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
369 endif
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
370 let l:output = call(l:repo.RunCommand, a:000, l:repo)
44
95f8e7cb5ca2 Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents: 43
diff changeset
371 if g:lawrencium_auto_cd
43
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
372 execute 'cd! -'
fc20a265551d Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 41
diff changeset
373 endif
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
374 if a:bang
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
375 " 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
376 let l:temp_file = s:tempname('hg-output-', '.txt')
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
377 split
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
378 execute 'edit ' . l:temp_file
21
d0acefc1ec9a Fixed multi-line output of `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents: 18
diff changeset
379 call append(0, split(l:output, '\n'))
46
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
380 call cursor(1, 1)
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
381
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
382 " Make it a temp buffer
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
383 setlocal bufhidden=delete
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
384 setlocal buftype=nofile
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
385
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
386 " Try to find a nice syntax to set given the current command.
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
387 let l:command_name = s:GetHgCommandName(a:000)
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
388 if l:command_name != '' && exists('g:lawrencium_hg_commands_file_types')
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
389 let l:file_type = get(g:lawrencium_hg_commands_file_types, l:command_name, '')
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
390 if l:file_type != ''
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
391 execute 'setlocal ft=' . l:file_type
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
392 endif
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
393 endif
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
394 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
395 " Just print out the output of the command.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
396 echo l:output
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
397 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
398 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
399
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
400 " 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
401 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
402 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
403 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
404 else
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
405 call s:error("Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium.")
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
406 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
407
46
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
408 " Include the command file type mappings.
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
409 let s:file_type_mappings = expand("<sfile>:h:h") . '/resources/hg_command_file_types.vim'
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
410 if filereadable(s:file_type_mappings)
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
411 execute "source " . s:file_type_mappings
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
412 endif
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
413
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
414 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
415 " 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
416 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
417 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
418 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
419
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
420 " 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
421 " Gotta find out why...
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
422 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
423 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
424 let l:arglead = '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
425 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
426
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
427 " 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
428 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
429 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
430 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
431
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
432 " 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
433 " the command name).
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
434 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
435 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
436 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
437
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
438 " 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
439 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
440 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
441 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
442 " 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
443 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
444 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
445 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
446 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
447 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
448
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
449 " 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
450 if l:arglead[0] ==# '-'
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
451 return []
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
452 else
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
453 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
454 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
455
46
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
456 function! s:GetHgCommandName(args) abort
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
457 for l:a in a:args
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
458 if stridx(l:a, '-') != 0
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
459 return l:a
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
460 endif
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
461 endfor
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
462 return ''
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
463 endfunction
6a4f5200d8da `:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 45
diff changeset
464
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
465 call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :call s:Hg(<bang>0, <f-args>)")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
466
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
467 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
468
4
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
469 " Hgstatus {{{
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
470
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
471 function! s:HgStatus() abort
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
472 " 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
473 let l:repo = s:hg_repo()
b6e4446ed292 HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents: 0
diff changeset
474 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
475 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
476 echo "Nothing modified."
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
477 endif
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
478
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
479 " Open a new temp buffer in a new window, jump to it,
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
480 " 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
481 let l:temp_file = s:tempname('hg-status-', '.txt')
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
482 let l:status_lines = split(l:status_text, '\n')
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
483 split
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
484 execute "setlocal winfixheight"
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
485 execute "setlocal winheight=" . (len(l:status_lines) + 1)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
486 execute "resize " . (len(l:status_lines) + 1)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
487 execute "edit " . l:temp_file
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
488 call append(0, l:status_lines)
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
489 call cursor(1, 1)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
490 " 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
491 setlocal bufhidden=delete
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
492
7
adc267e2f0f4 Added syntax highlighting for hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 6
diff changeset
493 " 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
494 " to it.
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
495 let b:mercurial_dir = l:repo.root_dir
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
496 setlocal buftype=nofile
53
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
497 setlocal filetype=hgstatus
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
498
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
499 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
500 call s:DefineMainCommands()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
501
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
502 " Add some nice commands.
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
503 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit()
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
504 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
505 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1)
58
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
506 command! -buffer Hgstatusdiffsum :call s:HgStatus_DiffSummary(0)
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
507 command! -buffer Hgstatusvdiffsum :call s:HgStatus_DiffSummary(1)
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
508 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh()
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
509 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
510 command! -buffer -range=% -bang Hgstatuscommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 0)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
511 command! -buffer -range=% -bang Hgstatusvcommit :call s:HgStatus_Commit(<line1>, <line2>, <bang>0, 1)
40
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
512 command! -buffer -range=% -nargs=+ Hgstatusqnew :call s:HgStatus_QNew(<line1>, <line2>, <f-args>)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
513 command! -buffer -range=% Hgstatusqrefresh :call s:HgStatus_QRefresh(<line1>, <line2>)
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
514
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
515 " Add some handy mappings.
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
516 if g:lawrencium_define_mappings
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
517 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
518 nnoremap <buffer> <silent> <C-N> :call search('^[MARC\!\?I ]\s.', 'We')<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
519 nnoremap <buffer> <silent> <C-P> :call search('^[MARC\!\?I ]\s.', 'Wbe')<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
520 nnoremap <buffer> <silent> <C-D> :Hgstatusdiff<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
521 nnoremap <buffer> <silent> <C-V> :Hgstatusvdiff<cr>
58
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
522 nnoremap <buffer> <silent> <C-U> :Hgstatusdiffsum<cr>
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
523 nnoremap <buffer> <silent> <C-H> :Hgstatusvdiffsum<cr>
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
524 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr>
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
525 nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr>
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
526 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr>
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
527 nnoremap <buffer> <silent> q :bdelete!<cr>
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
528
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
529 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr>
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
530 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr>
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
531 endif
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
532
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
533 " Make sure the file is deleted with the buffer.
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
534 autocmd BufDelete <buffer> call s:clean_tempfile(expand('<afile>:p'))
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
535 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
536
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
537 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
538 " 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
539 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
540 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
541
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
542 " 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
543 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
544 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
545 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
546 edit
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
547 endfunction
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
548
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
549 function! s:HgStatus_FileEdit() abort
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
550 " Get the path of the file the cursor is on.
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
551 let l:filename = s:HgStatus_GetSelectedFile()
24
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
552
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
553 " If the file is already open in a window, jump to that window.
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
554 " Otherwise, jump to the previous window and open it there.
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
555 for nr in range(1, winnr('$'))
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
556 let l:br = winbufnr(nr)
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
557 let l:bpath = fnamemodify(bufname(l:br), ':p')
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
558 if l:bpath ==# l:filename
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
559 execute nr . 'wincmd w'
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
560 return
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
561 endif
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
562 endfor
6
1da613c13d81 Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 5
diff changeset
563 wincmd p
24
21a879a09f20 Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents: 23
diff changeset
564 execute 'edit ' . l:filename
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
565 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
566
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
567 function! s:HgStatus_AddRemove(linestart, lineend) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
568 " Get the selected filenames.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
569 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['!', '?'])
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
570 if len(l:filenames) == 0
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
571 call s:error("No files to add or remove in selection or current line.")
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
572 endif
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
573
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
574 " Run `addremove` on those paths.
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
575 let l:repo = s:hg_repo()
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
576 call l:repo.RunCommand('addremove', l:filenames)
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
577
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
578 " Refresh the status window.
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
579 call s:HgStatus_Refresh()
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
580 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
581
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
582 function! s:HgStatus_Commit(linestart, lineend, bang, vertical) abort
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
583 " Get the selected filenames.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
584 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
585 if len(l:filenames) == 0
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
586 call s:error("No files to commit in selection or file.")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
587 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
588
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
589 " Run `Hgcommit` on those paths.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
590 call s:HgCommit(a:bang, a:vertical, l:filenames)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
591 endfunction
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
592
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
593 function! s:HgStatus_Diff(vertical) abort
25
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
594 " Open the file and run `Hgdiff` on it.
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
595 call s:HgStatus_FileEdit()
0e952b7c79d7 Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents: 24
diff changeset
596 call s:HgDiff('%:p', a:vertical)
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
597 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
598
58
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
599 function! s:HgStatus_DiffSummary(vertical) abort
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
600 " Get the path of the file the cursor is on.
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
601 let l:path = s:HgStatus_GetSelectedFile()
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
602 let l:split_type = 1
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
603 if a:vertical
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
604 let l:split_type = 2
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
605 endif
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
606 wincmd p
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
607 call s:HgDiffSummary(l:path, l:split_type)
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
608 endfunction
621185a5fa48 Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents: 57
diff changeset
609
40
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
610 function! s:HgStatus_QNew(linestart, lineend, patchname, ...) abort
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
611 " Get the selected filenames.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
612 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
613 if len(l:filenames) == 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
614 call s:error("No files in selection or file to create patch.")
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
615 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
616
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
617 " Run `Hg qnew` on those paths.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
618 let l:repo = s:hg_repo()
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
619 call insert(l:filenames, a:patchname, 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
620 if a:0 > 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
621 call insert(l:filenames, '-m', 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
622 let l:message = '"' . join(a:000, ' ') . '"'
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
623 call insert(l:filenames, l:message, 1)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
624 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
625 call l:repo.RunCommand('qnew', l:filenames)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
626 endfunction
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
627
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
628 function! s:HgStatus_QRefresh(linestart, lineend) abort
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
629 " Get the selected filenames.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
630 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R'])
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
631 if len(l:filenames) == 0
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
632 call s:error("No files in selection or file to refresh the patch.")
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
633 endif
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
634
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
635 " Run `Hg qrefresh` on those paths.
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
636 let l:repo = s:hg_repo()
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
637 call insert(l:filenames, '-s', 0)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
638 call l:repo.RunCommand('qrefresh', l:filenames)
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
639 endfunction
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
640
a63ec818ab21 Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 37
diff changeset
641
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
642 function! s:HgStatus_GetSelectedFile() abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
643 let l:filenames = s:HgStatus_GetSelectedFiles()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
644 return l:filenames[0]
9
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
645 endfunction
82a49134a85c Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents: 8
diff changeset
646
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
647 function! s:HgStatus_GetSelectedFiles(...) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
648 if a:0 >= 2
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
649 let l:lines = getline(a:1, a:2)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
650 else
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
651 let l:lines = []
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
652 call add(l:lines, getline('.'))
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
653 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
654 let l:filenames = []
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
655 let l:repo = s:hg_repo()
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
656 for line in l:lines
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
657 if a:0 >= 3
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
658 let l:status = s:HgStatus_GetFileStatus(line)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
659 if index(a:3, l:status) < 0
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
660 continue
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
661 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
662 endif
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
663 " Yay, awesome, Vim's regex syntax is fucked up like shit, especially for
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
664 " look-aheads and look-behinds. See for yourself:
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
665 let l:filename = matchstr(l:line, '\v(^[MARC\!\?I ]\s)@<=.*')
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
666 let l:filename = l:repo.GetFullPath(l:filename)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
667 call add(l:filenames, l:filename)
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
668 endfor
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
669 return l:filenames
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
670 endfunction
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
671
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
672 function! s:HgStatus_GetFileStatus(...) abort
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
673 let l:line = a:0 ? a:1 : getline('.')
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
674 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
675 endfunction
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
676
26
de588a4bca10 Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents: 25
diff changeset
677 call s:AddMainCommand("Hgstatus :call s:HgStatus()")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
678
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
679 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
680
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
681 " Hgcd, Hglcd {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
682
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
683 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
684 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
685
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
686 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
687
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
688 " Hgedit {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
689
27
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
690 function! s:HgEdit(bang, filename) abort
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
691 let l:full_path = s:hg_repo().GetFullPath(a:filename)
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
692 if a:bang
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
693 execute "edit! " . l:full_path
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
694 else
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
695 execute "edit " . l:full_path
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
696 endif
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
697 endfunction
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
698
09115be355e2 Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents: 26
diff changeset
699 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoFiles Hgedit :call s:HgEdit(<bang>0, <f-args>)")
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
700
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
701 " }}}
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
702
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
703 " Hgdiff, Hgvdiff {{{
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
704
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
705 function! s:HgDiff(filename, vertical, ...) abort
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
706 " Default revisions to diff: the working directory (null string)
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
707 " and the parent of the working directory (using Mercurial's revsets syntax).
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
708 " Otherwise, use the 1 or 2 revisions specified as extra parameters.
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
709 let l:rev1 = ''
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
710 let l:rev2 = 'p1()'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
711 if a:0 == 1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
712 let l:rev2 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
713 elseif a:0 == 2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
714 let l:rev1 = a:1
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
715 let l:rev2 = a:2
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
716 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
717
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
718 " 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
719 " fancy filename modifiers.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
720 let l:repo = s:hg_repo()
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
721 let l:path = expand(a:filename)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
722 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
723
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
724 " 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
725 " others' 'diff' flag is turned off.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
726 let l:diff_buffers = []
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
727
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
728 " Get the first file and open it.
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
729 if l:rev1 == ''
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
730 if bufexists(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
731 execute 'buffer ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
732 else
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
733 execute 'edit ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
734 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
735 " Make it part of the diff group.
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
736 call s:HgDiff_DiffThis()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
737 else
52
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
738 let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev1)
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
739 execute 'edit ' . fnameescape(l:rev_path)
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
740 " Make it part of the diff group.
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
741 call s:HgDiff_DiffThis()
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
742 endif
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
743
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
744 " Get the second file and open it too.
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
745 let l:diffsplit = 'diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
746 if a:vertical
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
747 let l:diffsplit = 'vertical diffsplit'
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
748 endif
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
749 if l:rev2 == ''
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
750 execute l:diffsplit . ' ' . fnameescape(l:path)
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
751 else
52
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
752 let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev1)
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
753 execute l:diffsplit . ' ' . fnameescape(l:rev_path)
8
1e155bfa94ad Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents: 7
diff changeset
754 endif
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
755 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
756
23
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
757 function! s:HgDiff_DiffThis() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
758 " Store some commands to run when we exit diff mode.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
759 " It's needed because `diffoff` reverts those settings to their default
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
760 " values, instead of their previous ones.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
761 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
762 call s:trace('Enabling diff mode on ' . bufname('%'))
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
763 let w:lawrencium_diffoff = {}
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
764 let w:lawrencium_diffoff['&diff'] = 0
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
765 let w:lawrencium_diffoff['&wrap'] = &l:wrap
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
766 let w:lawrencium_diffoff['&scrollopt'] = &l:scrollopt
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
767 let w:lawrencium_diffoff['&scrollbind'] = &l:scrollbind
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
768 let w:lawrencium_diffoff['&cursorbind'] = &l:cursorbind
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
769 let w:lawrencium_diffoff['&foldmethod'] = &l:foldmethod
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
770 let w:lawrencium_diffoff['&foldcolumn'] = &l:foldcolumn
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
771 diffthis
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
772 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
773 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
774
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
775 function! s:HgDiff_DiffOff(...) abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
776 " Get the window name (given as a paramter, or current window).
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
777 let l:nr = a:0 ? a:1 : winnr()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
778
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
779 " Run the commands we saved in `HgDiff_DiffThis`, or just run `diffoff`.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
780 let l:backup = getwinvar(l:nr, 'lawrencium_diffoff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
781 if type(l:backup) == type({}) && len(l:backup) > 0
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
782 call s:trace('Disabling diff mode on ' . l:nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
783 for key in keys(l:backup)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
784 call setwinvar(l:nr, key, l:backup[key])
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
785 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
786 call setwinvar(l:nr, 'lawrencium_diffoff', {})
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
787 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
788 call s:trace('Disabling diff mode on ' . l:nr . ' (but no true restore)')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
789 diffoff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
790 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
791 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
792
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
793 function! s:HgDiff_GetDiffWindows() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
794 let l:result = []
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
795 for nr in range(1, winnr('$'))
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
796 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
797 call add(l:result, nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
798 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
799 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
800 return l:result
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
801 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
802
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
803 function! s:HgDiff_CleanUp() abort
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
804 " If we're not leaving a diff window, do nothing.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
805 if !&diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
806 return
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
807 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
808
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
809 " If there will be only one diff window left (plus the one we're leaving),
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
810 " turn off diff everywhere.
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
811 let l:nrs = s:HgDiff_GetDiffWindows()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
812 if len(l:nrs) <= 2
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
813 call s:trace('Disabling diff mode in ' . len(l:nrs) . ' windows.')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
814 for nr in l:nrs
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
815 if getwinvar(nr, '&diff')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
816 call s:HgDiff_DiffOff(nr)
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
817 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
818 endfor
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
819 else
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
820 call s:trace('Still ' . len(l:nrs) . ' diff windows open.')
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
821 endif
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
822 endfunction
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
823
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
824 augroup lawrencium_diff
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
825 autocmd!
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
826 autocmd BufWinLeave * call s:HgDiff_CleanUp()
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
827 augroup end
84bceffbb19c Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents: 21
diff changeset
828
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
829 call s:AddMainCommand("-nargs=* Hgdiff :call s:HgDiff('%:p', 0, <f-args>)")
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
830 call s:AddMainCommand("-nargs=* Hgvdiff :call s:HgDiff('%:p', 1, <f-args>)")
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
831
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
832 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
833
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
834 " Hgdiffsum, Hgdiffsumsplit, Hgvdiffsumsplit {{{
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
835
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
836 function! s:HgDiffSummary(filename, split, ...) abort
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
837 " Default revisions to diff: the working directory (null string)
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
838 " and the parent of the working directory (using Mercurial's revsets syntax).
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
839 " Otherwise, use the 1 or 2 revisions specified as extra parameters.
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
840 let l:revs = ''
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
841 if a:0 == 1
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
842 let l:revs = a:1
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
843 elseif a:0 >= 2
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
844 let l:revs = a:1 . ',' . a:2
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
845 endif
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
846
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
847 " Get the current repo, and expand the given filename in case it contains
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
848 " fancy filename modifiers.
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
849 let l:repo = s:hg_repo()
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
850 let l:path = expand(a:filename)
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
851 call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path)
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
852 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs)
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
853 if a:split == 1
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
854 split
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
855 elseif a:split == 2
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
856 vsplit
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
857 endif
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
858 execute 'edit ' . l:special
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
859 " Open all folds by default.
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
860 " TODO: maybe set `nofoldenable` instead?
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
861 %foldopen!
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
862 endfunction
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
863
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
864 call s:AddMainCommand("-nargs=* Hgdiffsum :call s:HgDiffSummary('%:p', 0, <f-args>)")
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
865 call s:AddMainCommand("-nargs=* Hgdiffsumsplit :call s:HgDiffSummary('%:p', 1, <f-args>)")
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
866 call s:AddMainCommand("-nargs=* Hgvdiffsumsplit :call s:HgDiffSummary('%:p', 2, <f-args>)")
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
867
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
868 " }}}
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
869
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
870 " Hgcommit {{{
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
871
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
872 function! s:HgCommit(bang, vertical, ...) abort
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
873 " 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
874 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
875
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
876 " Get the list of files to commit.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
877 " It can either be several files passed as extra parameters, or an
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
878 " actual list passed as the first extra parameter.
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
879 let l:filenames = []
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
880 if a:0
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
881 let l:filenames = a:000
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
882 if a:0 == 1 && type(a:1) == type([])
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
883 let l:filenames = a:1
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
884 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
885 endif
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
886
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
887 " 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
888 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
889 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
890 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
891 call append(0, ['', ''])
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
892 call append(2, split(s:HgCommit_GenerateMessage(l:repo, l:filenames), '\n'))
28
0cdfdab43907 `Hgcommit` now puts the cursor at the beginning of the commit message.
Ludovic Chabant <ludovic@chabant.com>
parents: 27
diff changeset
893 call cursor(1, 1)
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
894
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
895 " 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
896 " 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
897 let b:mercurial_dir = l:repo.root_dir
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
898 let b:lawrencium_commit_files = l:filenames
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
899 setlocal bufhidden=delete
53
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
900 setlocal filetype=hgcommit
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
901 if a:bang
15
f02e37f395ae Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents: 14
diff changeset
902 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
903 else
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
904 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
905 endif
31
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
906 " Make commands available.
3a0f7bb6ea64 Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
907 call s:DefineMainCommands()
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
908 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
909
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
910 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
911 \'M': 'modified',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
912 \'A': 'added',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
913 \'R': 'removed',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
914 \'C': 'clean',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
915 \'!': 'missing',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
916 \'?': 'not tracked',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
917 \'I': 'ignored',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
918 \' ': '',
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
919 \}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
920
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
921 function! s:HgCommit_GenerateMessage(repo, filenames) abort
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
922 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
923 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
924 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
925 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
926 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
927 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
928
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
929 if len(a:filenames)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
930 let l:status_lines = split(a:repo.RunCommand('status', a:filenames), "\n")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
931 else
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
932 let l:status_lines = split(a:repo.RunCommand('status'), "\n")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
933 endif
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
934 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
935 if l:line ==# ''
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
936 continue
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
937 endif
11
b4baab0a4a92 Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents: 10
diff changeset
938 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
939 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
940 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
941 endfor
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
942
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
943 return l:msg
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
944 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
945
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
946 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
947 " 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
948 if !filereadable(a:log_file)
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
949 call s:error("abort: Commit message not saved")
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
950 return
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
951 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
952
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
953 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
954
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
955 " Clean up all the 'HG:' lines from the commit message, and see if there's
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
956 " any message left (Mercurial does this automatically, usually, but
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
957 " apparently not when you feed it a log file...).
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
958 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
959 call filter(l:lines, "v:val !~# '\\v^HG:'")
18
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
960 if len(filter(copy(l:lines), "v:val !~# '\\v^\\s*$'")) == 0
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
961 call s:error("abort: Empty commit message")
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
962 return
4f04d5e052eb Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents: 17
diff changeset
963 endif
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
964 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
965
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
966 " 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
967 let l:repo = s:hg_repo()
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
968 let l:hg_args = ['-l', a:log_file]
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
969 call extend(l:hg_args, b:lawrencium_commit_files)
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
970 let l:output = l:repo.RunCommand('commit', l:hg_args)
16
724f6db3baa2 Don't show `hg commit` output if there's nothing to show.
Ludovic Chabant <ludovic@chabant.com>
parents: 15
diff changeset
971 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
972 call s:trace("Output from hg commit:", 1)
17
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
973 for l:output_line in split(l:output, '\n')
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
974 echom l:output_line
5c6c605d0660 Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents: 16
diff changeset
975 endfor
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
976 endif
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
977 endfunction
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
978
33
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
979 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgcommit :call s:HgCommit(<bang>0, 0, <f-args>)")
a5b2f8e4fb6c Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents: 32
diff changeset
980 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgvcommit :call s:HgCommit(<bang>0, 1, <f-args>)")
10
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
981
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
982 " }}}
7d16084d40a9 Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents: 9
diff changeset
983
37
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
984 " Hgrevert {{{
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
985
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
986 function! s:HgRevert(bang, ...) abort
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
987 " Get the files to revert.
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
988 let l:filenames = a:000
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
989 if a:0 == 0
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
990 let l:filenames = [ expand('%:p') ]
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
991 endif
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
992 if a:bang
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
993 call insert(l:filenames, '--no-backup', 0)
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
994 endif
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
995
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
996 " Get the repo and run the command.
37
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
997 let l:repo = s:hg_repo()
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
998 call l:repo.RunCommand('revert', l:filenames)
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
999 endfunction
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
1000
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
1001 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgrevert :call s:HgRevert(<bang>0, <f-args>)")
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
1002
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
1003 " }}}
9361f6b9e5a4 Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 33
diff changeset
1004
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1005 " Hglog, Hgrepolog {{{
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1006
53
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
1007 let s:log_style_file = expand("<sfile>:h:h") . "/resources/hg_log.style"
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
1008
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1009 function! s:HgLog(is_file, ...) abort
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1010 " Get the file or directory to get the log from, or figure out
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1011 " some nice defaults (the current file, or the whole repository).
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1012 if a:is_file
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1013 let l:log_path = expand('%:p')
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1014 else
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1015 let l:log_path = '.'
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1016 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1017
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1018 " If the file or directory is specified, get the absolute path.
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1019 let l:repo = s:hg_repo()
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1020 if a:0 == 1
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1021 let l:log_path = l:repo.GetFullPath(a:1)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1022 endif
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1023
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1024 " Run the command.
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1025 if l:log_path == '.'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1026 let l:output = l:repo.RunCommand('log', '--style', shellescape(s:log_style_file))
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1027 else
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1028 let l:output = l:repo.RunCommand('log', '--style', shellescape(s:log_style_file), l:log_path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1029 endif
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1030
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1031 " Remember the file that opened this log.
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1032 let l:original_path = expand('%:p')
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1033
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1034 " Open a new temp buffer in the preview window, jump to it,
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1035 " and paste the `hg log` output in there.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1036 let l:temp_file = s:tempname('hg-log-', '.txt')
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1037 execute "pedit " . l:temp_file
47
edc43c59b3b8 avoid conflicts with plugins like minibufexplorer that might open a buffer when a new one is created
Sylvain Soliman <Sylvain.Soliman@m4x.org>
parents: 45
diff changeset
1038 wincmd P
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1039 call append(0, split(l:output, '\n'))
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1040 call cursor(1, 1)
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1041
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1042 " Setup the buffer correctly: readonly, and with the correct repo linked
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1043 " to it, and deleted on close.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1044 let b:mercurial_dir = l:repo.root_dir
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1045 let b:lawrencium_logged_path = l:repo.GetRelativePath(l:log_path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1046 let b:lawrencium_original_path = l:original_path
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1047 setlocal bufhidden=delete
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1048 setlocal buftype=nofile
53
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
1049 setlocal filetype=hglog
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1050
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1051 " Make commands available.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1052 call s:DefineMainCommands()
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1053
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1054 " Add some other nice commands and mappings.
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1055 command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(<f-args>)
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1056 if a:is_file
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1057 command! -buffer -nargs=? Hglogrevedit :call s:HgLog_FileRevEdit(<f-args>)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1058 endif
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1059
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1060 if g:lawrencium_define_mappings
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1061 nnoremap <buffer> <silent> <cr> :Hglogdiff<cr>
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1062 nnoremap <buffer> <silent> q :bdelete!<cr>
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1063 if a:is_file
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1064 nnoremap <buffer> <silent> <C-E> :Hglogrevedit<cr>
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1065 endif
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1066 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1067
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1068 " Clean up when the log buffer is deleted.
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1069 execute 'autocmd BufDelete <buffer> call s:HgLog_Delete(' . a:is_file . ', "' . fnameescape(l:temp_file) . '")'
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1070 endfunction
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1071
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1072 function! s:HgLog_Delete(was_file, path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1073 let l:repo = s:hg_repo()
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1074 let l:orignr = winnr()
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1075 let l:origedit = b:lawrencium_original_path
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1076 let l:origroot = s:stripslash(b:mercurial_dir)
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1077 let l:origpath = s:stripslash(b:lawrencium_logged_path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1078 call s:trace("Cleaning up '" . a:path . "', opened from '" . l:origedit . "'")
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1079 " Delete any other buffer opened by this log.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1080 " (buffers with Lawrencium paths that match this repo and filename)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1081 for nr in range(1, winnr('$'))
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1082 let l:br = winbufnr(nr)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1083 let l:bpath = bufname(l:br)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1084 let l:bpath_comps = s:parse_lawrencium_path(l:bpath)
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1085 if l:bpath_comps['root'] != ''
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1086 let l:bpath_root = s:normalizepath(l:bpath_comps['root'])
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1087 let l:bpath_path = s:normalizepath(s:stripslash(l:bpath_comps['path']))
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1088 call s:trace("Comparing '".l:bpath_path."' and '".l:origpath."' for cleanup.")
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1089 if l:bpath_root == l:origroot && l:bpath_path == l:origpath
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1090 " Go to that window and switch to the previous buffer
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1091 " from the buffer with the file revision.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1092 " Just switching away should delete the buffer since it
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1093 " has `bufhidden=delete`.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1094 execute nr . 'wincmd w'
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1095 let l:altbufname = s:shellslash(bufname('#'))
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1096 if l:altbufname =~# '\v^lawrencium://'
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1097 " This is a special Lawrencium buffer... it could be
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1098 " a previously shown revision of the file opened with
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1099 " this very `Hglog`, which we don't want to switch to.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1100 " Let's just default to editing the original file
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1101 " again... not sure what else to do here...
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1102 call s:trace("Reverting to editing: " . l:origedit)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1103 execute 'edit ' . l:origedit
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1104 else
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1105 bprevious
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1106 endif
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1107 endif
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1108 endif
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1109 endfor
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1110 " Restore the current window if we switched away.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1111 let l:curnr = winnr()
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1112 if l:curnr != l:orignr
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1113 execute l:orignr . 'wincmd w'
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1114 endif
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1115
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1116 " Delete the temp file if it was created somehow.
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1117 call s:clean_tempfile(a:path)
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1118 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1119
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1120 function! s:HgLog_FileRevEdit(...)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1121 if a:0 > 0
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1122 " Revision was given manually.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1123 let l:rev = a:1
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1124 else
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1125 " Revision should be parsed from the current line in the log.
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1126 let l:rev = s:HgLog_GetSelectedRev()
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1127 endif
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1128 let l:repo = s:hg_repo()
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1129 let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'rev', l:rev)
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1130 wincmd p
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1131 execute 'edit ' . fnameescape(l:path)
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1132 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1133
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1134 function! s:HgLog_Diff(...) abort
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1135 if a:0 >= 2
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1136 let l:revs = a:1 . ',' . a:2
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1137 elseif a:0 == 1
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1138 let l:revs = a:1
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1139 else
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1140 let l:revs = s:HgLog_GetSelectedRev()
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1141 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1142 let l:repo = s:hg_repo()
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1143 let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'diff', l:revs)
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1144 wincmd p
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1145 execute 'edit ' . fnameescape(l:path)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1146 endfunction
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1147
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1148 function! s:HgLog_GetSelectedRev(...) abort
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1149 if a:0 == 1
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1150 let l:line = getline(a:1)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1151 else
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1152 let l:line = getline('.')
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1153 endif
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1154 " Behold, Vim's look-ahead regex syntax again! WTF.
53
b7caa6693c39 `Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents: 52
diff changeset
1155 let l:rev = matchstr(l:line, '\v^(\d+)(\:)@=')
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1156 if l:rev == ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1157 call s:throw("Can't parse revision number from line: " . l:line)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1158 endif
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1159 return l:rev
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1160 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1161
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1162 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoDirs Hgrepolog :call s:HgLog(0, <f-args>)")
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1163 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(1, <f-args>)")
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1164
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1165 " }}}
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1166
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1167 " Lawrencium files {{{
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1168
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1169 function! s:ReadLawrenciumFile(path) abort
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1170 call s:trace("Reading Lawrencium file '" . a:path)
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1171 let l:comps = s:parse_lawrencium_path(a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1172 if l:comps['root'] == ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1173 call s:throw("Can't get repository root from: " . a:path)
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1174 endif
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1175
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1176 let l:repo = s:hg_repo(l:comps['root'])
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1177 let l:full_path = l:repo.root_dir . l:comps['path']
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1178 if l:comps['action'] == 'rev'
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1179 " Read revision (`hg cat`)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1180 if l:comps['value'] == ''
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1181 call l:repo.ReadCommandOutput('cat', l:full_path)
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1182 else
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1183 call l:repo.ReadCommandOutput('cat', '-r', l:comps['value'], l:full_path)
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1184 endif
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1185 elseif l:comps['action'] == 'diff'
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1186 " Diff revisions (`hg diff`)
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1187 let l:diffargs = []
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1188 let l:commaidx = stridx(l:comps['value'], ',')
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1189 if l:commaidx > 0
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1190 let l:rev1 = strpart(l:comps['value'], 0, l:commaidx)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1191 let l:rev2 = strpart(l:comps['value'], l:commaidx + 1)
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1192 if l:rev1 == '-'
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1193 let l:diffargs = [ '-r', l:rev2 ]
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1194 elseif l:rev2 == '-'
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1195 let l:diffargs = [ '-r', l:rev1 ]
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1196 else
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1197 let l:diffargs = [ '-r', l:rev1, '-r', l:rev2 ]
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1198 endif
51
671f5e18b515 Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents: 49
diff changeset
1199 elseif l:comps['value'] != ''
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1200 let l:diffargs = [ '-c', l:comps['value'] ]
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1201 else
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1202 let l:diffargs = []
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1203 endif
55
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1204 if l:comps['path'] != '' && l:comps['path'] != '.'
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1205 call add(l:diffargs, l:full_path)
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1206 endif
6a61724190ea Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents: 53
diff changeset
1207 call l:repo.ReadCommandOutput('diff', l:diffargs)
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1208 setlocal filetype=diff
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1209 endif
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1210
52
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1211 " Setup the new buffer.
48
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1212 setlocal readonly
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1213 setlocal nomodified
85e39bdd7089 Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
parents: 46 47
diff changeset
1214 setlocal bufhidden=delete
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1215 setlocal buftype=nofile
57
220c9508ff62 Fixes for Lawrencium files:
Ludovic Chabant <ludovic@chabant.com>
parents: 55
diff changeset
1216 goto
52
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1217
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1218 " Remember the repo it belongs to and make
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1219 " the Lawrencium commands available.
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1220 let b:mercurial_dir = l:repo.root_dir
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1221 call s:DefineMainCommands()
cd0b1cea326c Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents: 51
diff changeset
1222
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1223 return ''
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1224 endfunction
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1225
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1226 augroup lawrencium_files
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1227 autocmd!
49
dffb41c2067c Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents: 48
diff changeset
1228 autocmd BufReadCmd lawrencium://**//**//* exe s:ReadLawrenciumFile(expand('<amatch>'))
45
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1229 augroup END
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1230
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1231 " }}}
ea0ae8f6af81 Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents: 44
diff changeset
1232
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1233 " Autoload Functions {{{
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1234
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1235 " Prints a summary of the current repo (if any) that's appropriate for
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1236 " displaying on the status line.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1237 function! lawrencium#statusline(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1238 if !exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1239 return ''
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1240 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
1241 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
1242 let l:suffix = (a:0 > 1 ? a:2 : '')
30
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
1243 let l:branch = 'default'
5
3a4f9f41a7e2 Use a hackish shortcut to get the current branch faster for the statusline.
Ludovic Chabant <ludovic@chabant.com>
parents: 4
diff changeset
1244 let l:branch_file = s:hg_repo().GetFullPath('.hg/branch')
30
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
1245 if filereadable(l:branch_file)
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
1246 let l:branch = readfile(l:branch_file)[0]
35d097b9513c Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents: 28
diff changeset
1247 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
1248 return l:prefix . l:branch . l:suffix
0
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1249 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1250
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1251 " Rescans the current buffer for setting up Mercurial commands.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1252 " Passing '1' as the parameter enables debug traces temporarily.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1253 function! lawrencium#rescan(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1254 if exists('b:mercurial_dir')
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1255 unlet b:mercurial_dir
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1256 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1257 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1258 let l:trace_backup = g:lawrencium_trace
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1259 let g:lawrencium_trace = 1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1260 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1261 call s:setup_buffer_commands()
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1262 if a:0 && a:1
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1263 let g:lawrencium_trace = l:trace_backup
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1264 endif
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1265 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1266
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1267 " Enables/disables the debug trace.
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1268 function! lawrencium#debugtrace(...)
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1269 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1))
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1270 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.")
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1271 endfunction
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1272
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1273 " }}}
0a5b490dc35d Initial commit
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1274