Mercurial > vim-lawrencium
annotate plugin/lawrencium.vim @ 81:a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 07 Mar 2014 00:26:59 -0800 |
parents | cac06d16dafc |
children | 31801dcca77d |
rev | line source |
---|---|
0 | 1 " lawrencium.vim - A Mercurial wrapper |
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com> | |
79 | 3 " Version: 0.3.1 |
0 | 4 |
5 " Globals {{{ | |
6 | |
7 if !exists('g:lawrencium_debug') | |
8 let g:lawrencium_debug = 0 | |
9 endif | |
10 | |
11 if (exists('g:loaded_lawrencium') || &cp) && !g:lawrencium_debug | |
12 finish | |
13 endif | |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
14 if (exists('g:loaded_lawrencium') && g:lawrencium_debug) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
15 echom "Reloaded Lawrencium." |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
16 endif |
0 | 17 let g:loaded_lawrencium = 1 |
18 | |
19 if !exists('g:lawrencium_hg_executable') | |
20 let g:lawrencium_hg_executable = 'hg' | |
21 endif | |
22 | |
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 | 27 if !exists('g:lawrencium_trace') |
28 let g:lawrencium_trace = 0 | |
29 endif | |
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 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
35 if !exists('g:lawrencium_auto_close_buffers') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
36 let g:lawrencium_auto_close_buffers = 1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
37 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
38 |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
39 if !exists('g:lawrencium_annotate_width_offset') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
40 let g:lawrencium_annotate_width_offset = 0 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
41 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
42 |
0 | 43 " }}} |
44 | |
45 " Utility {{{ | |
46 | |
47 " Strips the ending slash in a path. | |
48 function! s:stripslash(path) | |
49 return fnamemodify(a:path, ':s?[/\\]$??') | |
50 endfunction | |
51 | |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
52 " Surrounds the given string with double quotes. |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
53 function! s:addquotes(str) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
54 return '"' . a:str . '"' |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
55 endfunction |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
56 |
0 | 57 " Normalizes the slashes in a path. |
58 function! s:normalizepath(path) | |
59 if exists('+shellslash') && &shellslash | |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
60 return substitute(a:path, '\v/', '\\', 'g') |
0 | 61 elseif has('win32') |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
62 return substitute(a:path, '\v/', '\\', 'g') |
0 | 63 else |
64 return a:path | |
65 endif | |
66 endfunction | |
67 | |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
68 " Shell-slashes the path (opposite of `normalizepath`). |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
69 function! s:shellslash(path) |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
70 if exists('+shellslash') && !&shellslash |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
71 return substitute(a:path, '\v\\', '/', 'g') |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
72 else |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
73 return a:path |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
74 endif |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
75 endfunction |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
76 |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
77 " 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
|
78 function! s:tempname(name, ...) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
79 let l:path = tempname() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
80 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
|
81 if a:0 > 0 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
82 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
|
83 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
84 return l:result |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
85 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
86 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
87 " Delete a temporary file if it exists. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
88 function! s:clean_tempfile(path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
89 if filewritable(a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
90 call s:trace("Cleaning up temporary file: " . a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
91 call delete(a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
92 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
93 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
94 |
0 | 95 " Prints a message if debug tracing is enabled. |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
96 function! s:trace(message, ...) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
97 if g:lawrencium_trace || (a:0 && a:1) |
0 | 98 let l:message = "lawrencium: " . a:message |
99 echom l:message | |
100 endif | |
101 endfunction | |
102 | |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
103 " 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
|
104 function! s:error(message) |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
105 echom "lawrencium error: " . a:message |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
106 endfunction |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
107 |
0 | 108 " Throw a Lawrencium exception message. |
109 function! s:throw(message) | |
110 let v:errmsg = "lawrencium: " . a:message | |
111 throw v:errmsg | |
112 endfunction | |
113 | |
114 " Finds the repository root given a path inside that repository. | |
115 " Throw an error if not repository is found. | |
116 function! s:find_repo_root(path) | |
117 let l:path = s:stripslash(a:path) | |
118 let l:previous_path = "" | |
119 while l:path != l:previous_path | |
120 if isdirectory(l:path . '/.hg/store') | |
121 return simplify(fnamemodify(l:path, ':p')) | |
122 endif | |
123 let l:previous_path = l:path | |
124 let l:path = fnamemodify(l:path, ':h') | |
125 endwhile | |
126 call s:throw("No Mercurial repository found above: " . a:path) | |
127 endfunction | |
128 | |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
129 " 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
|
130 " the repository root, relative file path and revision number/changeset ID. |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
131 " |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
132 " If a second argument exists, it must be: |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
133 " - `relative`: to make the file path relative to the repository root. |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
134 " - `absolute`: to make the file path absolute. |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
135 " |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
136 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>
diff
changeset
|
137 let l:repo_path = s:shellslash(a:lawrencium_path) |
81
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
138 let l:repo_path = substitute(l:repo_path, '\\ ', ' ', 'g') |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
139 if l:repo_path =~? '\v^lawrencium://' |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
140 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://')) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
141 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
142 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
143 let l:root_dir = '' |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
144 let l:at_idx = stridx(l:repo_path, '//') |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
145 if l:at_idx >= 0 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
146 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
|
147 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
|
148 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
149 |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
150 let l:value = '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
151 let l:action = '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
152 let l:actionidx = stridx(l:repo_path, '//') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
153 if l:actionidx >= 0 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
154 let l:action = strpart(l:repo_path, l:actionidx + 2) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
155 let l:repo_path = strpart(l:repo_path, 0, l:actionidx) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
156 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
157 let l:equalidx = stridx(l:action, '=') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
158 if l:equalidx >= 0 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
159 let l:value = strpart(l:action, l:equalidx + 1) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
160 let l:action = strpart(l:action, 0, l:equalidx) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
161 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
162 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
163 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
164 if a:0 > 0 |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
165 execute 'cd! ' . l:root_dir |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
166 if a:1 == 'relative' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
167 let l:repo_path = fnamemodify(l:repo_path, ':.') |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
168 elseif a:1 == 'absolute' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
169 let l:repo_path = fnamemodify(l:repo_path, ':p') |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
170 endif |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
171 execute 'cd! -' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
172 endif |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
173 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
174 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
|
175 return l:result |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
176 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
177 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
178 " Finds a window whose displayed buffer has a given variable |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
179 " set to the given value. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
180 function! s:find_buffer_window(varname, varvalue) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
181 for wnr in range(1, winnr('$')) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
182 let l:bnr = winbufnr(wnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
183 if getbufvar(l:bnr, a:varname) == a:varvalue |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
184 return l:wnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
185 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
186 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
187 return -1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
188 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
189 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
190 " Opens a buffer in a way that makes it easy to delete it later: |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
191 " - if the about-to-be previous buffer doesn't have a given variable, |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
192 " just open the new buffer. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
193 " - if the about-to-be previous buffer has a given variable, open the |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
194 " new buffer with the `keepalt` option to make it so that the |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
195 " actual previous buffer (returned by things like `bufname('#')`) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
196 " is the original buffer that was there before the first deletable |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
197 " buffer was opened. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
198 function! s:edit_deletable_buffer(varname, varvalue, path) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
199 let l:edit_cmd = 'edit ' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
200 if getbufvar('%', a:varname) != '' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
201 let l:edit_cmd = 'keepalt edit ' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
202 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
203 execute l:edit_cmd . fnameescape(a:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
204 call setbufvar('%', a:varname, a:varvalue) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
205 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
206 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
207 " Deletes all buffers that have a given variable set to a given value. |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
208 " For each buffer, if it is not shown in any window, it will be just deleted. |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
209 " If it is shown in a window, that window will be switched to the alternate |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
210 " buffer before the buffer is deleted, unless the `lawrencium_quit_on_delete` |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
211 " variable is set to `1`, in which case the window is closed too. |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
212 function! s:delete_dependency_buffers(varname, varvalue) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
213 let l:cur_winnr = winnr() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
214 for bnr in range(1, bufnr('$')) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
215 if getbufvar(bnr, a:varname) == a:varvalue |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
216 " Delete this buffer if it is not shown in any window. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
217 " Otherwise, display the alternate buffer before deleting |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
218 " it so the window is not closed. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
219 let l:bwnr = bufwinnr(bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
220 if l:bwnr < 0 || getbufvar(bnr, 'lawrencium_quit_on_delete') == 1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
221 if bufloaded(l:bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
222 call s:trace("Deleting dependency buffer " . bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
223 execute "bdelete! " . bnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
224 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
225 call s:trace("Dependency buffer " . bnr . " is already unladed.") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
226 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
227 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
228 execute l:bwnr . "wincmd w" |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
229 " TODO: better handle case where there's no previous/alternate buffer? |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
230 let l:prev_bnr = bufnr('#') |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
231 if l:prev_bnr > 0 && bufloaded(l:prev_bnr) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
232 execute "buffer " . l:prev_bnr |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
233 if bufloaded(l:bnr) |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
234 call s:trace("Deleting dependency buffer " . bnr . " after switching to " . l:prev_bnr . " in window " . l:bwnr) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
235 execute "bdelete! " . bnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
236 else |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
237 call s:trace("Dependency buffer " . bnr . " is unladed after switching to " . l:prev_bnr) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
238 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
239 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
240 call s:trace("Deleting dependency buffer " . bnr . " and window.") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
241 bdelete! |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
242 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
243 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
244 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
245 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
246 if l:cur_winnr != winnr() |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
247 call s:trace("Returning to window " . l:cur_winnr) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
248 execute l:cur_winnr . "wincmd w" |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
249 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
250 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
251 |
71 | 252 " Clean up all the 'HG:' lines from a commit message, and see if there's |
253 " any message left (Mercurial does this automatically, usually, but | |
254 " apparently not when you feed it a log file...). | |
255 function! s:clean_commit_file(log_file) abort | |
256 let l:lines = readfile(a:log_file) | |
257 call filter(l:lines, "v:val !~# '\\v^HG:'") | |
258 if len(filter(copy(l:lines), "v:val !~# '\\v^\\s*$'")) == 0 | |
259 return 0 | |
260 endif | |
261 call writefile(l:lines, a:log_file) | |
262 return 1 | |
263 endfunction | |
264 | |
0 | 265 " }}} |
266 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
267 " Mercurial Repository Object {{{ |
0 | 268 |
269 " Let's define a Mercurial repo 'class' using prototype-based object-oriented | |
270 " programming. | |
271 " | |
272 " The prototype dictionary. | |
273 let s:HgRepo = {} | |
274 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
275 " Constructor. |
0 | 276 function! s:HgRepo.New(path) abort |
277 let l:newRepo = copy(self) | |
278 let l:newRepo.root_dir = s:find_repo_root(a:path) | |
279 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir) | |
280 return l:newRepo | |
281 endfunction | |
282 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
283 " Gets a full path given a repo-relative path. |
0 | 284 function! s:HgRepo.GetFullPath(path) abort |
285 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
|
286 if a:path =~# '\v^[/\\]' |
0 | 287 let l:root_dir = s:stripslash(l:root_dir) |
288 endif | |
289 return l:root_dir . a:path | |
290 endfunction | |
291 | |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
292 function! s:HgRepo.GetRelativePath(path) abort |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
293 execute 'cd! ' . self.root_dir |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
294 let l:relative_path = fnamemodify(a:path, ':.') |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
295 execute 'cd! -' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
296 return l:relative_path |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
297 endfunction |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
298 |
0 | 299 " Gets a list of files matching a root-relative pattern. |
300 " If a flag is passed and is TRUE, a slash will be appended to all | |
301 " directories. | |
302 function! s:HgRepo.Glob(pattern, ...) abort | |
303 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
|
304 if (a:pattern =~# '\v^[/\\]') |
0 | 305 let l:root_dir = s:stripslash(l:root_dir) |
306 endif | |
307 let l:matches = split(glob(l:root_dir . a:pattern), '\n') | |
308 if a:0 && a:1 | |
309 for l:idx in range(len(l:matches)) | |
310 if !filereadable(l:matches[l:idx]) | |
311 let l:matches[l:idx] = l:matches[l:idx] . '/' | |
312 endif | |
313 endfor | |
314 endif | |
315 let l:strip_len = len(l:root_dir) | |
316 call map(l:matches, 'v:val[l:strip_len : -1]') | |
317 return l:matches | |
318 endfunction | |
319 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
320 " Gets a full Mercurial command. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
321 function! s:HgRepo.GetCommand(command, ...) abort |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
322 " 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
|
323 " argument list. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
324 let l:arg_list = a:000 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
325 if a:0 == 1 && type(a:1) == type([]) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
326 let l:arg_list = a:1 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
327 endif |
0 | 328 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) |
81
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
329 let l:hg_command = l:hg_command . ' ' . a:command |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
330 for l:arg in l:arg_list |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
331 if stridx(l:arg, ' ') >= 0 |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
332 let l:hg_command = l:hg_command . ' "' . l:arg . '"' |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
333 else |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
334 let l:hg_command = l:hg_command . ' ' . l:arg |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
335 endif |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
336 endfor |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
337 return l:hg_command |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
338 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
339 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
340 " Runs a Mercurial command in the repo. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
341 function! s:HgRepo.RunCommand(command, ...) abort |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
342 let l:all_args = [a:command] + a:000 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
343 let l:hg_command = call(self['GetCommand'], l:all_args, self) |
0 | 344 call s:trace("Running Mercurial command: " . l:hg_command) |
345 return system(l:hg_command) | |
346 endfunction | |
347 | |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
348 " 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
|
349 " buffer. |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
350 function! s:HgRepo.ReadCommandOutput(command, ...) abort |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
351 let l:all_args = [a:command] + a:000 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
352 let l:hg_command = call(self['GetCommand'], l:all_args, self) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
353 call s:trace("Running Mercurial command: " . l:hg_command) |
57
220c9508ff62
Fixes for Lawrencium files:
Ludovic Chabant <ludovic@chabant.com>
parents:
55
diff
changeset
|
354 execute '0read !' . escape(l:hg_command, '%#\') |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
355 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
356 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
357 " 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
|
358 " 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
|
359 " unless '0' is passed as the 4th argument. |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
360 function! s:HgRepo.GetLawrenciumPath(path, action, value, ...) abort |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
361 let l:path = a:path |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
362 if a:0 == 0 || !a:1 |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
363 let l:path = self.GetRelativePath(a:path) |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
364 endif |
81
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
365 let l:path = escape(l:path, ' \') |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
366 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
|
367 if a:action !=? '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
368 let l:result = l:result . '//' . a:action |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
369 if a:value !=? '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
370 let l:result = l:result . '=' . a:value |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
371 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
372 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
373 return l:result |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
374 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
375 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
376 " Repo cache map. |
0 | 377 let s:buffer_repos = {} |
378 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
379 " Get a cached repo. |
0 | 380 function! s:hg_repo(...) abort |
381 " Use the given path, or the mercurial directory of the current buffer. | |
382 if a:0 == 0 | |
383 if exists('b:mercurial_dir') | |
384 let l:path = b:mercurial_dir | |
385 else | |
386 let l:path = s:find_repo_root(expand('%:p')) | |
387 endif | |
388 else | |
389 let l:path = a:1 | |
390 endif | |
391 " Find a cache repo instance, or make a new one. | |
392 if has_key(s:buffer_repos, l:path) | |
393 return get(s:buffer_repos, l:path) | |
394 else | |
395 let l:repo = s:HgRepo.New(l:path) | |
396 let s:buffer_repos[l:path] = l:repo | |
397 return l:repo | |
398 endif | |
399 endfunction | |
400 | |
401 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo. | |
402 " If the file is not in a Mercurial repo, just exit silently. | |
403 function! s:setup_buffer_commands() abort | |
404 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...") | |
405 let l:do_setup = 1 | |
406 if exists('b:mercurial_dir') | |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
407 if b:mercurial_dir =~# '\v^\s*$' |
0 | 408 unlet b:mercurial_dir |
409 else | |
410 let l:do_setup = 0 | |
411 endif | |
412 endif | |
413 try | |
414 let l:repo = s:hg_repo() | |
415 catch /^lawrencium\:/ | |
416 return | |
417 endtry | |
418 let b:mercurial_dir = l:repo.root_dir | |
419 if exists('b:mercurial_dir') && l:do_setup | |
420 call s:trace("Setting Mercurial commands for buffer '" . bufname('%')) | |
421 call s:trace(" with repo : " . expand(b:mercurial_dir)) | |
422 silent doautocmd User Lawrencium | |
423 endif | |
424 endfunction | |
425 | |
426 augroup lawrencium_detect | |
427 autocmd! | |
428 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() | |
429 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif | |
430 augroup end | |
431 | |
432 " }}} | |
433 | |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
434 " Buffer Object {{{ |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
435 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
436 " The prototype dictionary. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
437 let s:Buffer = {} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
438 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
439 " Constructor. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
440 function! s:Buffer.New(number) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
441 let l:newBuffer = copy(self) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
442 let l:newBuffer.nr = a:number |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
443 let l:newBuffer.var_backup = {} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
444 let l:newBuffer.on_delete = [] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
445 let l:newBuffer.on_winleave = [] |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
446 let l:newBuffer.on_unload = [] |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
447 execute 'augroup lawrencium_buffer_' . a:number |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
448 execute ' autocmd!' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
449 execute ' autocmd BufDelete <buffer=' . a:number . '> call s:buffer_on_delete(' . a:number . ')' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
450 execute 'augroup end' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
451 call s:trace("Built new buffer object for buffer: " . a:number) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
452 return l:newBuffer |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
453 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
454 |
66 | 455 function! s:Buffer.GetName() dict abort |
456 return bufname(self.nr) | |
457 endfunction | |
458 | |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
459 function! s:Buffer.GetVar(var) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
460 return getbufvar(self.nr, a:var) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
461 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
462 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
463 function! s:Buffer.SetVar(var, value) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
464 if !has_key(self.var_backup, a:var) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
465 self.var_backup[a:var] = getbufvar(self.nr, a:var) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
466 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
467 return setbufvar(self.nr, a:var, a:value) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
468 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
469 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
470 function! s:Buffer.RestoreVars() dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
471 for key in keys(self.var_backup) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
472 setbufvar(self.nr, key, self.var_backup[key]) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
473 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
474 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
475 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
476 function! s:Buffer.OnDelete(cmd) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
477 call s:trace("Adding BufDelete callback for buffer " . self.nr . ": " . a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
478 call add(self.on_delete, a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
479 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
480 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
481 function! s:Buffer.OnWinLeave(cmd) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
482 if len(self.on_winleave) == 0 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
483 call s:trace("Adding BufWinLeave auto-command on buffer " . self.nr) |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
484 execute 'augroup lawrencium_buffer_' . self.nr . '_winleave' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
485 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
486 execute ' autocmd BufWinLeave <buffer=' . self.nr . '> call s:buffer_on_winleave(' . self.nr .')' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
487 execute 'augroup end' |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
488 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
489 call s:trace("Adding BufWinLeave callback for buffer " . self.nr . ": " . a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
490 call add(self.on_winleave, a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
491 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
492 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
493 function! s:Buffer.OnUnload(cmd) dict abort |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
494 if len(self.on_unload) == 0 |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
495 call s:trace("Adding BufUnload auto-command on buffer " . self.nr) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
496 execute 'augroup lawrencium_buffer_' . self.nr . '_unload' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
497 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
498 execute ' autocmd BufUnload <buffer=' . self.nr . '> call s:buffer_on_unload(' . self.nr . ')' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
499 execute 'augroup end' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
500 endif |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
501 call s:trace("Adding BufUnload callback for buffer " . self.nr . ": " . a:cmd) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
502 call add(self.on_unload, a:cmd) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
503 endfunction |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
504 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
505 let s:buffer_objects = {} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
506 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
507 " Get a buffer instance for the specified buffer number, or the |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
508 " current buffer if nothing is specified. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
509 function! s:buffer_obj(...) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
510 let l:bufnr = a:0 ? a:1 : bufnr('%') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
511 if !has_key(s:buffer_objects, l:bufnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
512 let s:buffer_objects[l:bufnr] = s:Buffer.New(l:bufnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
513 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
514 return s:buffer_objects[l:bufnr] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
515 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
516 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
517 " Execute all the "on delete" callbacks. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
518 function! s:buffer_on_delete(number) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
519 let l:bufobj = s:buffer_objects[a:number] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
520 call s:trace("Calling BufDelete callbacks on buffer " . l:bufobj.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
521 for cmd in l:bufobj.on_delete |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
522 call s:trace(" [" . cmd . "]") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
523 execute cmd |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
524 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
525 call s:trace("Deleted buffer object " . l:bufobj.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
526 call remove(s:buffer_objects, l:bufobj.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
527 execute 'augroup lawrencium_buffer_' . l:bufobj.nr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
528 execute ' autocmd!' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
529 execute 'augroup end' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
530 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
531 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
532 " Execute all the "on winleave" callbacks. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
533 function! s:buffer_on_winleave(number) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
534 let l:bufobj = s:buffer_objects[a:number] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
535 call s:trace("Calling BufWinLeave callbacks on buffer " . l:bufobj.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
536 for cmd in l:bufobj.on_winleave |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
537 call s:trace(" [" . cmd . "]") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
538 execute cmd |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
539 endfor |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
540 execute 'augroup lawrencium_buffer_' . l:bufobj.nr . '_winleave' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
541 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
542 execute 'augroup end' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
543 endfunction |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
544 |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
545 " Execute all the "on unload" callbacks. |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
546 function! s:buffer_on_unload(number) abort |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
547 let l:bufobj = s:buffer_objects[a:number] |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
548 call s:trace("Calling BufUnload callbacks on buffer " . l:bufobj.nr) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
549 for cmd in l:bufobj.on_unload |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
550 call s:trace(" [" . cmd . "]") |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
551 execute cmd |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
552 endfor |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
553 execute 'augroup lawrencium_buffer_' . l:bufobj.nr . '_unload' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
554 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
555 execute 'augroup end' |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
556 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
557 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
558 " }}} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
559 |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
560 " Lawrencium Files {{{ |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
561 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
562 " Read revision (`hg cat`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
563 function! s:read_lawrencium_rev(repo, path_parts, full_path) abort |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
564 let l:rev = a:path_parts['value'] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
565 if l:rev == '' |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
566 call a:repo.ReadCommandOutput('cat', a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
567 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
568 call a:repo.ReadCommandOutput('cat', '-r', s:addquotes(l:rev), a:full_path) |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
569 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
570 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
571 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
572 " Status (`hg status`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
573 function! s:read_lawrencium_status(repo, path_parts, full_path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
574 if a:path_parts['path'] == '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
575 call a:repo.ReadCommandOutput('status') |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
576 else |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
577 call a:repo.ReadCommandOutput('status', a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
578 endif |
71 | 579 setlocal nomodified |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
580 setlocal filetype=hgstatus |
71 | 581 setlocal bufhidden=delete |
582 setlocal buftype=nofile | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
583 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
584 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
585 " Log (`hg log`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
586 let s:log_style_file = expand("<sfile>:h:h") . "/resources/hg_log.style" |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
587 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
588 function! s:read_lawrencium_log(repo, path_parts, full_path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
589 if a:path_parts['path'] == '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
590 call a:repo.ReadCommandOutput('log', '--style', shellescape(s:log_style_file)) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
591 else |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
592 call a:repo.ReadCommandOutput('log', '--style', shellescape(s:log_style_file), a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
593 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
594 setlocal filetype=hglog |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
595 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
596 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
597 " Diff revisions (`hg diff`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
598 function! s:read_lawrencium_diff(repo, path_parts, full_path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
599 let l:diffargs = [] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
600 let l:commaidx = stridx(a:path_parts['value'], ',') |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
601 if l:commaidx > 0 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
602 let l:rev1 = strpart(a:path_parts['value'], 0, l:commaidx) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
603 let l:rev2 = strpart(a:path_parts['value'], l:commaidx + 1) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
604 if l:rev1 == '-' |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
605 let l:diffargs = [ '-r', s:addquotes(l:rev2) ] |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
606 elseif l:rev2 == '-' |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
607 let l:diffargs = [ '-r', s:addquotes(l:rev1) ] |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
608 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
609 let l:diffargs = [ '-r', s:addquotes(l:rev1), '-r', s:addquotes(l:rev2) ] |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
610 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
611 elseif a:path_parts['value'] != '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
612 let l:diffargs = [ '-c', a:path_parts['value'] ] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
613 else |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
614 let l:diffargs = [] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
615 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
616 if a:path_parts['path'] != '' && a:path_parts['path'] != '.' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
617 call add(l:diffargs, a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
618 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
619 call a:repo.ReadCommandOutput('diff', l:diffargs) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
620 setlocal filetype=diff |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
621 setlocal nofoldenable |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
622 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
623 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
624 " Annotate file |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
625 function! s:read_lawrencium_annotate(repo, path_parts, full_path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
626 call a:repo.ReadCommandOutput('annotate', '-c', '-n', '-u', '-d', '-q', a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
627 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
628 |
71 | 629 " MQ series |
630 function! s:read_lawrencium_qseries(repo, path_parts, full_path) abort | |
631 let l:names = split(a:repo.RunCommand('qseries'), '\n') | |
632 let l:head = split(a:repo.RunCommand('qapplied', '-s'), '\n') | |
633 let l:tail = split(a:repo.RunCommand('qunapplied', '-s'), '\n') | |
634 | |
635 let l:idx = 0 | |
636 let l:curbuffer = bufname('%') | |
637 for line in l:head | |
638 call setbufvar(l:curbuffer, 'lawrencium_patchname_' . (l:idx + 1), l:names[l:idx]) | |
639 call append(l:idx, "*" . line) | |
640 let l:idx = l:idx + 1 | |
641 endfor | |
642 for line in l:tail | |
643 call setbufvar(l:curbuffer, 'lawrencium_patchname_' . (l:idx + 1), l:names[l:idx]) | |
644 call append(l:idx, line) | |
645 let l:idx = l:idx + 1 | |
646 endfor | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
647 call setbufvar(l:curbuffer, 'lawrencium_patchname_top', l:names[len(l:head) - 1]) |
71 | 648 set filetype=hgqseries |
649 endfunction | |
650 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
651 " Generic read |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
652 let s:lawrencium_file_readers = { |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
653 \'rev': function('s:read_lawrencium_rev'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
654 \'log': function('s:read_lawrencium_log'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
655 \'diff': function('s:read_lawrencium_diff'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
656 \'status': function('s:read_lawrencium_status'), |
71 | 657 \'annotate': function('s:read_lawrencium_annotate'), |
658 \'qseries': function('s:read_lawrencium_qseries') | |
659 \} | |
660 let s:lawrencium_file_customoptions = { | |
661 \'status': 1 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
662 \} |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
663 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
664 function! s:ReadLawrenciumFile(path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
665 call s:trace("Reading Lawrencium file: " . a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
666 let l:path_parts = s:parse_lawrencium_path(a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
667 if l:path_parts['root'] == '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
668 call s:throw("Can't get repository root from: " . a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
669 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
670 if !has_key(s:lawrencium_file_readers, l:path_parts['action']) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
671 call s:throw("No registered reader for action: " . l:path_parts['action']) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
672 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
673 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
674 " Call the registered reader. |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
675 let l:repo = s:hg_repo(l:path_parts['root']) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
676 let l:full_path = l:repo.root_dir . l:path_parts['path'] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
677 let LawrenciumFileReader = s:lawrencium_file_readers[l:path_parts['action']] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
678 call LawrenciumFileReader(l:repo, l:path_parts, l:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
679 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
680 " Setup the new buffer. |
71 | 681 if !has_key(s:lawrencium_file_customoptions, l:path_parts['action']) |
682 setlocal readonly | |
683 setlocal nomodified | |
684 setlocal bufhidden=delete | |
685 setlocal buftype=nofile | |
686 endif | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
687 goto |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
688 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
689 " Remember the repo it belongs to and make |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
690 " the Lawrencium commands available. |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
691 let b:mercurial_dir = l:repo.root_dir |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
692 call s:DefineMainCommands() |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
693 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
694 return '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
695 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
696 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
697 function! s:WriteLawrenciumFile(path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
698 call s:trace("Writing Lawrencium file: " . a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
699 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
700 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
701 augroup lawrencium_files |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
702 autocmd! |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
703 autocmd BufReadCmd lawrencium://**//**//* exe s:ReadLawrenciumFile(expand('<amatch>')) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
704 autocmd BufWriteCmd lawrencium://**//**//* exe s:WriteLawrenciumFile(expand('<amatch>')) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
705 augroup END |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
706 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
707 " }}} |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
708 |
14 | 709 " Buffer Commands Management {{{ |
0 | 710 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
711 " 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
|
712 " batch when we need to. |
0 | 713 let s:main_commands = [] |
714 | |
715 function! s:AddMainCommand(command) abort | |
716 let s:main_commands += [a:command] | |
717 endfunction | |
718 | |
719 function! s:DefineMainCommands() | |
720 for l:command in s:main_commands | |
721 execute 'command! -buffer ' . l:command | |
722 endfor | |
723 endfunction | |
724 | |
725 augroup lawrencium_main | |
726 autocmd! | |
727 autocmd User Lawrencium call s:DefineMainCommands() | |
728 augroup end | |
729 | |
14 | 730 " }}} |
731 | |
732 " Commands Auto-Complete {{{ | |
733 | |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
734 " 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
|
735 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
736 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
|
737 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
738 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
739 endfunction |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
740 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
741 " 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
|
742 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
743 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
744 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
745 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
746 endfunction |
0 | 747 |
14 | 748 " }}} |
749 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
750 " Hg {{{ |
0 | 751 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
752 function! s:Hg(bang, ...) abort |
0 | 753 let l:repo = s:hg_repo() |
44
95f8e7cb5ca2
Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents:
43
diff
changeset
|
754 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
|
755 " 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
|
756 " 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
|
757 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
|
758 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
759 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
|
760 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
|
761 execute 'cd! -' |
fc20a265551d
Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents:
41
diff
changeset
|
762 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
763 if a:bang |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
764 " 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
|
765 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>
diff
changeset
|
766 split |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
767 execute 'edit ' . l:temp_file |
21
d0acefc1ec9a
Fixed multi-line output of `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
768 call append(0, split(l:output, '\n')) |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
769 call cursor(1, 1) |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
770 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
771 " Make it a temp buffer |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
772 setlocal bufhidden=delete |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
773 setlocal buftype=nofile |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
774 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
775 " 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
|
776 let l:command_name = s:GetHgCommandName(a:000) |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
777 if l:command_name != '' && exists('g:lawrencium_hg_commands_file_types') |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
778 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
|
779 if l:file_type != '' |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
780 execute 'setlocal ft=' . l:file_type |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
781 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
782 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
783 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
784 " Just print out the output of the command. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
785 echo l:output |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
786 endif |
0 | 787 endfunction |
788 | |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
789 " 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
|
790 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
|
791 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
|
792 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
|
793 else |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
794 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
|
795 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
796 |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
797 " Include the command file type mappings. |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
798 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
|
799 if filereadable(s:file_type_mappings) |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
800 execute "source " . s:file_type_mappings |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
801 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
802 |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
803 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
|
804 " 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
|
805 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
|
806 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
807 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
808 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
809 " 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
|
810 " Gotta find out why... |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
811 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
|
812 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
|
813 let l:arglead = '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
814 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
815 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
816 " 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
|
817 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
|
818 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
|
819 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
820 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
821 " 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
|
822 " the command name). |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
823 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
|
824 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
|
825 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
826 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
827 " 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
|
828 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
|
829 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
|
830 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
|
831 " 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
|
832 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
|
833 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
|
834 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
|
835 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
836 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
837 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
838 " 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
|
839 if l:arglead[0] ==# '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
840 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
841 else |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
842 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
|
843 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
844 |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
845 function! s:GetHgCommandName(args) abort |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
846 for l:a in a:args |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
847 if stridx(l:a, '-') != 0 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
848 return l:a |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
849 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
850 endfor |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
851 return '' |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
852 endfunction |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
853 |
26
de588a4bca10
Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
854 call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :call s:Hg(<bang>0, <f-args>)") |
0 | 855 |
856 " }}} | |
857 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
858 " Hgstatus {{{ |
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
859 |
0 | 860 function! s:HgStatus() abort |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
861 " Get the repo and the Lawrencium path for `hg status`. |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
862 let l:repo = s:hg_repo() |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
863 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
864 |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
865 " Open the Lawrencium buffer in a new split window of the right size. |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
866 execute "rightbelow split " . l:status_path |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
867 if line('$') == 1 |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
868 " Buffer is empty, which means there are not changes... |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
869 " Quit and display a message. |
64
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
870 " TODO: figure out why the first `echom` doesn't show when alone. |
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
871 bdelete |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
872 echom "Nothing was modified." |
64
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
873 echom "" |
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
874 return |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
875 endif |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
876 |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
877 execute "setlocal winfixheight" |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
878 execute "setlocal winheight=" . (line('$') + 1) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
879 execute "resize " . (line('$') + 1) |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
880 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
881 " Add some nice commands. |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
882 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit() |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
883 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
884 command! -buffer Hgstatusvdiff :call s:HgStatus_Diff(1) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
885 command! -buffer Hgstatusdiffsum :call s:HgStatus_DiffSummary(0) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
886 command! -buffer Hgstatusvdiffsum :call s:HgStatus_DiffSummary(1) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
887 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
888 command! -buffer -range Hgstatusaddremove :call s:HgStatus_AddRemove(<line1>, <line2>) |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
889 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
|
890 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
|
891 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
|
892 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
|
893 |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
894 " Add some handy mappings. |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
895 if g:lawrencium_define_mappings |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
896 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr> |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
897 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
|
898 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
|
899 nnoremap <buffer> <silent> <C-D> :Hgstatusdiff<cr> |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
900 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
|
901 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
|
902 nnoremap <buffer> <silent> <C-H> :Hgstatusvdiffsum<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
903 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
904 nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
905 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr> |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
906 nnoremap <buffer> <silent> q :bdelete!<cr> |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
907 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
908 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
909 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
910 endif |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
911 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
912 |
75
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
913 function! s:HgStatus_Refresh() abort |
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
914 " Just re-edit the buffer, it will reload the contents by calling |
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
915 " the matching Mercurial command. |
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
916 edit |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
917 endfunction |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
918 |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
919 function! s:HgStatus_FileEdit() abort |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
920 " 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
|
921 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
|
922 |
21a879a09f20
Trying to keep the cursor line when open an already opened file in `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
23
diff
changeset
|
923 " 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
|
924 " 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 endfor |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
933 wincmd p |
81
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
934 execute 'edit ' . escape(l:filename, ' \') |
0 | 935 endfunction |
936 | |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
937 function! s:HgStatus_AddRemove(linestart, lineend) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
938 " Get the selected filenames. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
939 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
|
940 if len(l:filenames) == 0 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
941 call s:error("No files to add or remove in selection or current line.") |
69 | 942 return |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
943 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
944 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
945 " 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
|
946 let l:repo = s:hg_repo() |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
947 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
|
948 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
949 " Refresh the status window. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
950 call s:HgStatus_Refresh() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
951 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
952 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
953 function! s:HgStatus_Commit(linestart, lineend, bang, vertical) abort |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
954 " Get the selected filenames. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
955 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
|
956 if len(l:filenames) == 0 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
957 call s:error("No files to commit in selection or file.") |
69 | 958 return |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
959 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
960 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
961 " Run `Hgcommit` on those paths. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
962 call s:HgCommit(a:bang, a:vertical, l:filenames) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
963 endfunction |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
964 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
965 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
|
966 " 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
|
967 call s:HgStatus_FileEdit() |
0e952b7c79d7
Fixed a bug with opening a diff from `Hgstatus`
Ludovic Chabant <ludovic@chabant.com>
parents:
24
diff
changeset
|
968 call s:HgDiff('%:p', a:vertical) |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
969 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
970 |
58
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
971 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
|
972 " 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
|
973 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
|
974 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
|
975 if a:vertical |
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
976 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
|
977 endif |
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
978 wincmd p |
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
979 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
|
980 endfunction |
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
981 |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
982 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
|
983 " Get the selected filenames. |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
984 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
|
985 if len(l:filenames) == 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
986 call s:error("No files in selection or file to create patch.") |
69 | 987 return |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
988 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
989 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
990 " 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
|
991 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
|
992 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
|
993 if a:0 > 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
994 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
|
995 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
|
996 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
|
997 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
998 call l:repo.RunCommand('qnew', l:filenames) |
72
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
999 |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1000 " Refresh the status window. |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1001 call s:HgStatus_Refresh() |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1002 endfunction |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1003 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1004 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
|
1005 " Get the selected filenames. |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1006 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
|
1007 if len(l:filenames) == 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1008 call s:error("No files in selection or file to refresh the patch.") |
69 | 1009 return |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1010 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1011 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1012 " 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
|
1013 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
|
1014 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
|
1015 call l:repo.RunCommand('qrefresh', l:filenames) |
72
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1016 |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1017 " Refresh the status window. |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1018 call s:HgStatus_Refresh() |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1019 endfunction |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1020 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1021 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1022 function! s:HgStatus_GetSelectedFile() abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1023 let l:filenames = s:HgStatus_GetSelectedFiles() |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1024 return l:filenames[0] |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1025 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1026 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1027 function! s:HgStatus_GetSelectedFiles(...) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1028 if a:0 >= 2 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1029 let l:lines = getline(a:1, a:2) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1030 else |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1031 let l:lines = [] |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1032 call add(l:lines, getline('.')) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1033 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1034 let l:filenames = [] |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1035 let l:repo = s:hg_repo() |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1036 for line in l:lines |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1037 if a:0 >= 3 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1038 let l:status = s:HgStatus_GetFileStatus(line) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1039 if index(a:3, l:status) < 0 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1040 continue |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1041 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1042 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1043 " 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
|
1044 " look-aheads and look-behinds. See for yourself: |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1045 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
|
1046 let l:filename = l:repo.GetFullPath(l:filename) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1047 call add(l:filenames, l:filename) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1048 endfor |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1049 return l:filenames |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1050 endfunction |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1051 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1052 function! s:HgStatus_GetFileStatus(...) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1053 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
|
1054 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
|
1055 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1056 |
26
de588a4bca10
Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
1057 call s:AddMainCommand("Hgstatus :call s:HgStatus()") |
0 | 1058 |
1059 " }}} | |
1060 | |
1061 " Hgcd, Hglcd {{{ | |
1062 | |
1063 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
1064 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
1065 | |
1066 " }}} | |
1067 | |
1068 " Hgedit {{{ | |
1069 | |
27
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1070 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
|
1071 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
|
1072 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
|
1073 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
|
1074 else |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1075 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
|
1076 endif |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1077 endfunction |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1078 |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1079 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
|
1080 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1081 " }}} |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1082 |
70
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1083 " Hgvimgrep {{{ |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1084 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1085 function! s:HgVimGrep(bang, pattern, ...) abort |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1086 let l:repo = s:hg_repo() |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1087 let l:file_paths = [] |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1088 if a:0 > 0 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1089 for ff in a:000 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1090 let l:full_ff = l:repo.GetFullPath(ff) |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1091 call add(l:file_paths, l:full_ff) |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1092 endfor |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1093 else |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1094 call add(l:file_paths, l:repo.root_dir . "**") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1095 endif |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1096 if a:bang |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1097 execute "vimgrep! " . a:pattern . " " . join(l:file_paths, " ") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1098 else |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1099 execute "vimgrep " . a:pattern . " " . join(l:file_paths, " ") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1100 endif |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1101 endfunction |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1102 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1103 call s:AddMainCommand("-bang -nargs=+ -complete=customlist,s:ListRepoFiles Hgvimgrep :call s:HgVimGrep(<bang>0, <f-args>)") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1104 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1105 " }}} |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1106 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1107 " Hgdiff, Hgvdiff {{{ |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1108 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1109 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
|
1110 " 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
|
1111 " 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
|
1112 " 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
|
1113 let l:rev1 = '' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1114 let l:rev2 = 'p1()' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1115 if a:0 == 1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1116 if type(a:1) == type([]) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1117 if len(a:1) >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1118 let l:rev1 = a:1[0] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1119 let l:rev2 = a:1[1] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1120 elseif len(a:1) == 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1121 let l:rev2 = a:1[0] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1122 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1123 else |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1124 let l:rev2 = a:1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1125 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1126 elseif a:0 == 2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1127 let l:rev1 = a:1 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1128 let l:rev2 = a:2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1129 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1130 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1131 " 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
|
1132 " fancy filename modifiers. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1133 let l:repo = s:hg_repo() |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1134 let l:path = expand(a:filename) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1135 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
|
1136 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1137 " 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
|
1138 " others' 'diff' flag is turned off. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1139 let l:diff_buffers = [] |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1140 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1141 " 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
|
1142 if l:rev1 == '' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1143 if bufexists(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1144 execute 'buffer ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1145 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1146 execute 'edit ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1147 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
1148 " 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
|
1149 call s:HgDiff_DiffThis() |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1150 else |
52
cd0b1cea326c
Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents:
51
diff
changeset
|
1151 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
|
1152 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
|
1153 " 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
|
1154 call s:HgDiff_DiffThis() |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1155 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1156 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1157 " Get the second file and open it too. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1158 let l:diffsplit = 'diffsplit' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1159 if a:vertical |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1160 let l:diffsplit = 'vertical diffsplit' |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1161 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
|
1162 if l:rev2 == '' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1163 execute l:diffsplit . ' ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1164 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1165 let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev2) |
52
cd0b1cea326c
Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents:
51
diff
changeset
|
1166 execute l:diffsplit . ' ' . fnameescape(l:rev_path) |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1167 endif |
0 | 1168 endfunction |
1169 | |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1170 function! s:HgDiff_DiffThis() abort |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1171 " 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
|
1172 " 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
|
1173 " 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
|
1174 if !&diff |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1175 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
|
1176 let w:lawrencium_diffoff = {} |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1177 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
|
1178 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
|
1179 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
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 diffthis |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1185 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1186 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1187 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1188 function! s:HgDiff_DiffOff(...) abort |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1189 " 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
|
1190 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
|
1191 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1192 " 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
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1199 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
|
1200 else |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1201 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
|
1202 diffoff |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1203 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1204 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1205 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1206 function! s:HgDiff_GetDiffWindows() abort |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1207 let l:result = [] |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1208 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
|
1209 if getwinvar(nr, '&diff') |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1210 call add(l:result, nr) |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1211 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1212 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1213 return l:result |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1214 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1215 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1216 function! s:HgDiff_CleanUp() abort |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1217 " 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
|
1218 if !&diff |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1219 return |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1220 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1221 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1222 " 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
|
1223 " turn off diff everywhere. |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1224 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
|
1225 if len(l:nrs) <= 2 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1226 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
|
1227 for nr in l:nrs |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1228 if getwinvar(nr, '&diff') |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1229 call s:HgDiff_DiffOff(nr) |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1230 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1231 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1232 else |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1233 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
|
1234 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1235 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1236 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1237 augroup lawrencium_diff |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1238 autocmd! |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1239 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
|
1240 augroup end |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1241 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1242 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
|
1243 call s:AddMainCommand("-nargs=* Hgvdiff :call s:HgDiff('%:p', 1, <f-args>)") |
0 | 1244 |
1245 " }}} | |
1246 | |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1247 " 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
|
1248 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1249 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
|
1250 " 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
|
1251 " 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
|
1252 " 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
|
1253 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
|
1254 if a:0 == 1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1255 if type(a:1) == type([]) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1256 if len(a:1) >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1257 let l:revs = a:1[0] . ',' . a:1[1] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1258 elseif len(a:1) == 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1259 let l:revs = a:1[0] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1260 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1261 else |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1262 let l:revs = a:1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1263 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
|
1264 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
|
1265 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
|
1266 endif |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1267 |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1268 " 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
|
1269 " 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
|
1270 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
|
1271 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
|
1272 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
|
1273 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs) |
66 | 1274 let l:cmd = 'edit ' |
51
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1275 if a:split == 1 |
66 | 1276 let l:cmd = 'rightbelow split ' |
51
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1277 elseif a:split == 2 |
66 | 1278 let l:cmd = 'rightbelow vsplit ' |
51
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1279 endif |
66 | 1280 execute l:cmd . l:special |
51
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1281 endfunction |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1282 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1283 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
|
1284 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
|
1285 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
|
1286 |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1287 " }}} |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1288 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1289 " Hgcommit {{{ |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1290 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1291 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
|
1292 " 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
|
1293 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
|
1294 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1295 " Get the list of files to commit. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1296 " 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
|
1297 " actual list passed as the first extra parameter. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1298 let l:filenames = [] |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1299 if a:0 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1300 let l:filenames = a:000 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1301 if a:0 == 1 && type(a:1) == type([]) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1302 let l:filenames = a:1 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1303 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1304 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1305 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1306 " 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
|
1307 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
|
1308 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
|
1309 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
|
1310 call append(0, ['', '']) |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1311 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
|
1312 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
|
1313 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1314 " 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
|
1315 " 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
|
1316 let b:mercurial_dir = l:repo.root_dir |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1317 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
|
1318 setlocal bufhidden=delete |
53
b7caa6693c39
`Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents:
52
diff
changeset
|
1319 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
|
1320 if a:bang |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1321 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
|
1322 else |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1323 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
|
1324 endif |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1325 " Make commands available. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1326 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
|
1327 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1328 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1329 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
|
1330 \'M': 'modified', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1331 \'A': 'added', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1332 \'R': 'removed', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1333 \'C': 'clean', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1334 \'!': 'missing', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1335 \'?': 'not tracked', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1336 \'I': 'ignored', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1337 \' ': '', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1338 \} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1339 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1340 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
|
1341 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
|
1342 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
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1348 if len(a:filenames) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1349 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
|
1350 else |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1351 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
|
1352 endif |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1353 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
|
1354 if l:line ==# '' |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1355 continue |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1356 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
1357 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
|
1358 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
|
1359 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
|
1360 endfor |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1361 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1362 return l:msg |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1363 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1364 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1365 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
|
1366 " 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
|
1367 if !filereadable(a:log_file) |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1368 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
|
1369 return |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1370 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1371 |
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
|
1372 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
|
1373 |
71 | 1374 " Clean all the 'HG: ' lines. |
1375 let l:is_valid = s:clean_commit_file(a:log_file) | |
1376 if !l:is_valid | |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1377 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
|
1378 return |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1379 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
|
1380 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1381 " 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
|
1382 let l:repo = s:hg_repo() |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1383 let l:hg_args = ['-l', a:log_file] |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1384 call extend(l:hg_args, b:lawrencium_commit_files) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1385 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
|
1386 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
|
1387 call s:trace("Output from hg commit:", 1) |
17
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1388 for l:output_line in split(l:output, '\n') |
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1389 echom l:output_line |
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1390 endfor |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1391 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1392 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1393 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1394 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
|
1395 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
|
1396 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1397 " }}} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1398 |
37
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1399 " Hgrevert {{{ |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1400 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1401 function! s:HgRevert(bang, ...) abort |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1402 " Get the files to revert. |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1403 let l:filenames = a:000 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1404 if a:0 == 0 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1405 let l:filenames = [ expand('%:p') ] |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1406 endif |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1407 if a:bang |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1408 call insert(l:filenames, '--no-backup', 0) |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1409 endif |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1410 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1411 " Get the repo and run the command. |
37
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1412 let l:repo = s:hg_repo() |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1413 call l:repo.RunCommand('revert', l:filenames) |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1414 endfunction |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1415 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1416 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
|
1417 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1418 " }}} |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1419 |
66 | 1420 " Hglog, Hglogthis {{{ |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1421 |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1422 function! s:HgLog(vertical, ...) abort |
66 | 1423 " Get the file or directory to get the log from. |
1424 " (empty string is for the whole repository) | |
1425 let l:repo = s:hg_repo() | |
1426 if a:0 > 0 | |
1427 let l:path = l:repo.GetRelativePath(expand(a:1)) | |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1428 else |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1429 let l:path = '' |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1430 endif |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1431 |
66 | 1432 " Get the Lawrencium path for this `hg log`, |
1433 " open it in a preview window and jump to it. | |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1434 let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', '') |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1435 if a:vertical |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1436 execute 'vertical pedit ' . l:log_path |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1437 else |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1438 execute 'pedit ' . l:log_path |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1439 endif |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1440 wincmd P |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1441 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1442 " Add some other nice commands and mappings. |
66 | 1443 let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path))) |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1444 command! -buffer -nargs=* Hglogdiffsum :call s:HgLog_DiffSummary(0, <f-args>) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1445 command! -buffer -nargs=* Hglogvdiffsum :call s:HgLog_DiffSummary(1, <f-args>) |
66 | 1446 if l:is_file |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1447 command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1448 command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(0, <f-args>) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1449 command! -buffer -nargs=* Hglogvdiff :call s:HgLog_Diff(1, <f-args>) |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1450 endif |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1451 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1452 if g:lawrencium_define_mappings |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1453 nnoremap <buffer> <silent> <C-U> :Hglogdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1454 nnoremap <buffer> <silent> <C-H> :Hglogvdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1455 nnoremap <buffer> <silent> <cr> :Hglogvdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1456 nnoremap <buffer> <silent> q :bdelete!<cr> |
66 | 1457 if l:is_file |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1458 nnoremap <buffer> <silent> <C-E> :Hglogrevedit<cr> |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1459 nnoremap <buffer> <silent> <C-D> :Hglogdiff<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1460 nnoremap <buffer> <silent> <C-V> :Hglogvdiff<cr> |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1461 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1462 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1463 |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1464 " Clean up when the log buffer is deleted. |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1465 let l:bufobj = s:buffer_obj() |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1466 call l:bufobj.OnDelete('call s:HgLog_Delete(' . l:bufobj.nr . ')') |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1467 endfunction |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1468 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1469 function! s:HgLog_Delete(bufnr) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1470 if g:lawrencium_auto_close_buffers |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1471 call s:delete_dependency_buffers('lawrencium_diff_for', a:bufnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1472 call s:delete_dependency_buffers('lawrencium_rev_for', a:bufnr) |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1473 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1474 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1475 |
66 | 1476 function! s:HgLog_FileRevEdit() |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1477 let l:repo = s:hg_repo() |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1478 let l:bufobj = s:buffer_obj() |
66 | 1479 let l:rev = s:HgLog_GetSelectedRev() |
1480 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) | |
1481 let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'rev', l:rev) | |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1482 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1483 " Go to the window we were in before going in the log window, |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1484 " and open the revision there. |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1485 wincmd p |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1486 call s:edit_deletable_buffer('lawrencium_rev_for', l:bufobj.nr, l:path) |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1487 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1488 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1489 function! s:HgLog_Diff(vertical, ...) abort |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1490 let l:revs = [] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1491 if a:0 >= 2 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1492 let l:revs = [a:1, a:2] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1493 elseif a:0 == 1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1494 let l:revs = [a:1, 'p1('.a:1.')'] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1495 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1496 let l:sel = s:HgLog_GetSelectedRev() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1497 let l:revs = [l:sel, 'p1('.l:sel.')'] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1498 endif |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1499 |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1500 let l:repo = s:hg_repo() |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1501 let l:bufobj = s:buffer_obj() |
66 | 1502 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1503 let l:path = l:repo.GetFullPath(l:log_path['path']) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1504 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1505 " Go to the window we were in before going to the log window, |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1506 " and open the split diff there. |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1507 wincmd p |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1508 call s:HgDiff(l:path, a:vertical, l:revs) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1509 endfunction |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1510 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1511 function! s:HgLog_DiffSummary(vertical, ...) abort |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1512 let l:revs = [] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1513 if a:0 >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1514 let l:revs = [a:1, a:2] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1515 elseif a:0 == 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1516 let l:revs = [a:1] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1517 else |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1518 let l:revs = [s:HgLog_GetSelectedRev()] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1519 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1520 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1521 let l:split_type = 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1522 if a:vertical |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1523 let l:split_type = 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1524 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1525 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1526 let l:repo = s:hg_repo() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1527 let l:bufobj = s:buffer_obj() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1528 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1529 let l:path = l:repo.GetFullPath(l:log_path['path']) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1530 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1531 " Go to the window we were in before going in the log window, |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1532 " and split for the diff summary from there. |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1533 wincmd p |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1534 call s:HgDiffSummary(l:path, l:split_type, l:revs) |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1535 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1536 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1537 function! s:HgLog_GetSelectedRev(...) abort |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1538 if a:0 == 1 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1539 let l:line = getline(a:1) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1540 else |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1541 let l:line = getline('.') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1542 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1543 " Behold, Vim's look-ahead regex syntax again! WTF. |
53
b7caa6693c39
`Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents:
52
diff
changeset
|
1544 let l:rev = matchstr(l:line, '\v^(\d+)(\:)@=') |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1545 if l:rev == '' |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1546 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
|
1547 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1548 return l:rev |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1549 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1550 |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1551 call s:AddMainCommand("Hglogthis :call s:HgLog(0, '%:p')") |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1552 call s:AddMainCommand("Hgvlogthis :call s:HgLog(1, '%:p')") |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1553 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(0, <f-args>)") |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1554 call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hgvlog :call s:HgLog(1, <f-args>)") |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1555 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1556 " }}} |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1557 |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1558 " Hgannotate {{{ |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1559 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1560 function! s:HgAnnotate() abort |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1561 " Get the Lawrencium path for the annotated file. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1562 let l:path = expand('%:p') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1563 let l:bufnr = bufnr('%') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1564 let l:repo = s:hg_repo() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1565 let l:annotation_path = l:repo.GetLawrenciumPath(l:path, 'annotate', '') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1566 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1567 " Check if we're trying to annotate something with local changes. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1568 let l:has_local_edits = 0 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1569 let l:path_status = l:repo.RunCommand('status', l:path) |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1570 if l:path_status != '' |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1571 call s:trace("Found local edits for '" . l:path . "'. Will annotate parent revision.") |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1572 let l:has_local_edits = 1 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1573 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1574 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1575 if l:has_local_edits |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1576 " Just open the output of the command. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1577 echom "Local edits found, will show the annotations for the parent revision." |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1578 execute 'edit ' . l:annotation_path |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1579 setlocal nowrap nofoldenable |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1580 setlocal filetype=hgannotate |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1581 else |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1582 " Store some info about the current buffer. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1583 let l:cur_topline = line('w0') + &scrolloff |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1584 let l:cur_line = line('.') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1585 let l:cur_wrap = &wrap |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1586 let l:cur_foldenable = &foldenable |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1587 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1588 " Open the annotated file in a split buffer on the left, after |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1589 " having disabled wrapping and folds on the current file. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1590 " Make both windows scroll-bound. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1591 setlocal scrollbind nowrap nofoldenable |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1592 execute 'keepalt leftabove vsplit ' . l:annotation_path |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1593 setlocal nonumber |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1594 setlocal scrollbind nowrap nofoldenable foldcolumn=0 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1595 setlocal filetype=hgannotate |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1596 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1597 " When the annotated buffer is deleted, restore the settings we |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1598 " changed on the current buffer, and go back to that buffer. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1599 let l:annotate_buffer = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1600 call l:annotate_buffer.OnDelete('execute bufwinnr(' . l:bufnr . ') . "wincmd w"') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1601 call l:annotate_buffer.OnDelete('setlocal noscrollbind') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1602 if l:cur_wrap |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1603 call l:annotate_buffer.OnDelete('setlocal wrap') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1604 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1605 if l:cur_foldenable |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1606 call l:annotate_buffer.OnDelete('setlocal foldenable') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1607 endif |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1608 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1609 " Go to the line we were at in the source buffer when we |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1610 " opened the annotation window. |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1611 execute l:cur_topline |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1612 normal! zt |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1613 execute l:cur_line |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1614 syncbind |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1615 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1616 " Set the correct window width for the annotations. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1617 let l:column_count = strlen(matchstr(getline('.'), '[^:]*:')) + g:lawrencium_annotate_width_offset - 1 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1618 execute "vertical resize " . l:column_count |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1619 setlocal winfixwidth |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1620 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1621 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1622 " Make the annotate buffer a Lawrencium buffer. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1623 let b:mercurial_dir = l:repo.root_dir |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1624 let b:lawrencium_annotated_path = l:path |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1625 let b:lawrencium_annotated_bufnr = l:bufnr |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1626 call s:DefineMainCommands() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1627 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1628 " Add some other nice commands and mappings. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1629 command! -buffer Hgannotatediffsum :call s:HgAnnotate_DiffSummary() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1630 if g:lawrencium_define_mappings |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1631 nnoremap <buffer> <silent> <cr> :Hgannotatediffsum<cr> |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1632 endif |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1633 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1634 " Clean up when the annotate buffer is deleted. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1635 let l:bufobj = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1636 call l:bufobj.OnDelete('call s:HgAnnotate_Delete(' . l:bufobj.nr . ')') |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1637 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1638 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1639 function! s:HgAnnotate_Delete(bufnr) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1640 if g:lawrencium_auto_close_buffers |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1641 call s:delete_dependency_buffers('lawrencium_diff_for', a:bufnr) |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1642 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1643 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1644 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1645 function! s:HgAnnotate_DiffSummary() abort |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1646 " Get the path for the diff of the revision specified under the cursor. |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1647 let l:line = getline('.') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1648 let l:rev_hash = matchstr(l:line, '\v[a-f0-9]{12}') |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1649 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1650 " Get the Lawrencium path for the diff, and the buffer object for the |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1651 " annotation. |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1652 let l:repo = s:hg_repo() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1653 let l:path = l:repo.GetLawrenciumPath(b:lawrencium_annotated_path, 'diff', l:rev_hash) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1654 let l:annotate_buffer = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1655 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1656 " Find a window already displaying diffs for this annotation. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1657 let l:diff_winnr = s:find_buffer_window('lawrencium_diff_for', l:annotate_buffer.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1658 if l:diff_winnr == -1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1659 " Not found... go back to the main source buffer and open a bottom |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1660 " split with the diff for the specified revision. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1661 execute bufwinnr(b:lawrencium_annotated_bufnr) . 'wincmd w' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1662 execute 'rightbelow split ' . fnameescape(l:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1663 let b:lawrencium_diff_for = l:annotate_buffer.nr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1664 let b:lawrencium_quit_on_delete = 1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1665 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1666 " Found! Use that window to open the diff. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1667 execute l:diff_winnr . 'wincmd w' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1668 execute 'edit ' . fnameescape(l:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1669 let b:lawrencium_diff_for = l:annotate_buffer.nr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1670 endif |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1671 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1672 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1673 call s:AddMainCommand("Hgannotate :call s:HgAnnotate()") |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1674 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1675 " }}} |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1676 |
71 | 1677 " Hgqseries {{{ |
1678 | |
1679 function! s:HgQSeries() abort | |
1680 " Open the MQ series in the preview window and jump to it. | |
1681 let l:repo = s:hg_repo() | |
1682 let l:path = l:repo.GetLawrenciumPath('', 'qseries', '') | |
1683 execute 'pedit ' . l:path | |
1684 wincmd P | |
1685 | |
1686 " Make the series buffer a Lawrencium buffer. | |
1687 let b:mercurial_dir = l:repo.root_dir | |
1688 call s:DefineMainCommands() | |
1689 | |
1690 " Add some commands and mappings. | |
1691 command! -buffer Hgqseriesgoto :call s:HgQSeries_Goto() | |
1692 command! -buffer Hgqserieseditmessage :call s:HgQSeries_EditMessage() | |
1693 command! -buffer -nargs=+ Hgqseriesrename :call s:HgQSeries_Rename(<f-args>) | |
1694 if g:lawrencium_define_mappings | |
1695 nnoremap <buffer> <silent> <C-g> :Hgqseriesgoto<cr> | |
1696 nnoremap <buffer> <silent> <C-e> :Hgqserieseditmessage<cr> | |
1697 nnoremap <buffer> <silent> q :bdelete!<cr> | |
1698 endif | |
1699 endfunction | |
1700 | |
1701 function! s:HgQSeries_GetCurrentPatchName() abort | |
1702 let l:pos = getpos('.') | |
1703 return getbufvar('%', 'lawrencium_patchname_' . l:pos[1]) | |
1704 endfunction | |
1705 | |
1706 function! s:HgQSeries_Goto() abort | |
1707 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
1708 let l:patchname = s:HgQSeries_GetCurrentPatchName() |
71 | 1709 if len(l:patchname) == 0 |
1710 call s:error("No patch to go to here.") | |
1711 return | |
1712 endif | |
1713 call l:repo.RunCommand('qgoto', l:patchname) | |
1714 edit | |
1715 endfunction | |
1716 | |
1717 function! s:HgQSeries_Rename(...) abort | |
1718 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
1719 let l:current_name = s:HgQSeries_GetCurrentPatchName() |
71 | 1720 if len(l:current_name) == 0 |
1721 call s:error("No patch to rename here.") | |
1722 return | |
1723 endif | |
1724 let l:new_name = '"' . join(a:000, ' ') . '"' | |
1725 call l:repo.RunCommand('qrename', l:current_name, l:new_name) | |
1726 edit | |
1727 endfunction | |
1728 | |
1729 function! s:HgQSeries_EditMessage() abort | |
1730 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
1731 let l:patchname = getbufvar('%', 'lawrencium_patchname_top') |
71 | 1732 if len(l:patchname) == 0 |
1733 call s:error("No patch to edit here.") | |
1734 return | |
1735 endif | |
1736 let l:current = split(l:repo.RunCommand('qheader', l:patchname), '\n') | |
1737 | |
1738 " Open a temp file to write the commit message. | |
1739 let l:temp_file = s:tempname('hg-qrefedit-', '.txt') | |
1740 split | |
1741 execute 'edit ' . l:temp_file | |
1742 call append(0, 'HG: Enter the new commit message for patch "' . l:patchname . '" here.\n') | |
1743 call append(0, '') | |
1744 call append(0, l:current) | |
1745 call cursor(1, 1) | |
1746 | |
1747 " Make it a temp buffer that will actually change the commit message | |
1748 " when it is saved and closed. | |
1749 let b:mercurial_dir = l:repo.root_dir | |
1750 let b:lawrencium_patchname = l:patchname | |
1751 setlocal bufhidden=delete | |
1752 setlocal filetype=hgcommit | |
1753 autocmd BufDelete <buffer> call s:HgQSeries_EditMessage_Execute(expand('<afile>:p')) | |
1754 | |
1755 call s:DefineMainCommands() | |
1756 endfunction | |
1757 | |
1758 function! s:HgQSeries_EditMessage_Execute(log_file) abort | |
1759 if !filereadable(a:log_file) | |
1760 call s:error("abort: Commit message not saved") | |
1761 return | |
1762 endif | |
1763 | |
1764 " Clean all the 'HG:' lines. | |
1765 let l:is_valid = s:clean_commit_file(a:log_file) | |
1766 if !l:is_valid | |
1767 call s:error("abort: Empty commit message") | |
1768 return | |
1769 endif | |
1770 | |
1771 " Get the repo and edit the given patch. | |
1772 let l:repo = s:hg_repo() | |
1773 let l:hg_args = ['-s', '-l', a:log_file] | |
1774 call l:repo.RunCommand('qref', l:hg_args) | |
1775 endfunction | |
1776 | |
1777 | |
1778 call s:AddMainCommand("Hgqseries call s:HgQSeries()") | |
1779 | |
1780 " }}} | |
1781 | |
0 | 1782 " Autoload Functions {{{ |
1783 | |
1784 " Prints a summary of the current repo (if any) that's appropriate for | |
1785 " displaying on the status line. | |
1786 function! lawrencium#statusline(...) | |
1787 if !exists('b:mercurial_dir') | |
1788 return '' | |
1789 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
|
1790 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
|
1791 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
|
1792 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
|
1793 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
|
1794 if filereadable(l:branch_file) |
35d097b9513c
Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1795 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
|
1796 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
|
1797 return l:prefix . l:branch . l:suffix |
0 | 1798 endfunction |
1799 | |
1800 " Rescans the current buffer for setting up Mercurial commands. | |
1801 " Passing '1' as the parameter enables debug traces temporarily. | |
1802 function! lawrencium#rescan(...) | |
1803 if exists('b:mercurial_dir') | |
1804 unlet b:mercurial_dir | |
1805 endif | |
1806 if a:0 && a:1 | |
1807 let l:trace_backup = g:lawrencium_trace | |
1808 let g:lawrencium_trace = 1 | |
1809 endif | |
1810 call s:setup_buffer_commands() | |
1811 if a:0 && a:1 | |
1812 let g:lawrencium_trace = l:trace_backup | |
1813 endif | |
1814 endfunction | |
1815 | |
1816 " Enables/disables the debug trace. | |
1817 function! lawrencium#debugtrace(...) | |
1818 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1)) | |
1819 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.") | |
1820 endfunction | |
1821 | |
1822 " }}} | |
1823 |