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