Mercurial > vim-lawrencium
annotate plugin/lawrencium.vim @ 124:d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 16 Feb 2016 22:14:26 -0800 |
parents | 860e6502b239 |
children | bbb19d37c681 |
rev | line source |
---|---|
0 | 1 " lawrencium.vim - A Mercurial wrapper |
2 " Maintainer: Ludovic Chabant <http://ludovic.chabant.com> | |
114
facd2506066f
Bumped version. I should release this stuff more often.
Ludovic Chabant <ludovic@chabant.com>
parents:
113
diff
changeset
|
3 " Version: 0.4.0 |
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 |
108
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
51 if !exists('g:lawrencium_record_start_in_working_buffer') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
52 let g:lawrencium_record_start_in_working_buffer = 0 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
53 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
54 |
0 | 55 " }}} |
56 | |
57 " Utility {{{ | |
58 | |
59 " Strips the ending slash in a path. | |
60 function! s:stripslash(path) | |
61 return fnamemodify(a:path, ':s?[/\\]$??') | |
62 endfunction | |
63 | |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
64 " Surrounds the given string with double quotes. |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
65 function! s:addquotes(str) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
66 return '"' . a:str . '"' |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
67 endfunction |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
68 |
98
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
69 " Returns whether a path is absolute. |
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
70 function! s:isabspath(path) |
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
71 return a:path =~# '\v^(\w\:)?[/\\]' |
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
72 endfunction |
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
73 |
0 | 74 " Normalizes the slashes in a path. |
75 function! s:normalizepath(path) | |
76 if exists('+shellslash') && &shellslash | |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
77 return substitute(a:path, '\v/', '\\', 'g') |
0 | 78 elseif has('win32') |
48
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') |
0 | 80 else |
81 return a:path | |
82 endif | |
83 endfunction | |
84 | |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
85 " 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
|
86 function! s:shellslash(path) |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
87 if exists('+shellslash') && !&shellslash |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
88 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
|
89 else |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
90 return a:path |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
91 endif |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
92 endfunction |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
93 |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
94 " 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
|
95 function! s:tempname(name, ...) |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
96 let l:path = tempname() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
97 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
|
98 if a:0 > 0 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
99 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
|
100 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
101 return l:result |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
102 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
103 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
104 " Delete a temporary file if it exists. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
105 function! s:clean_tempfile(path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
106 if filewritable(a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
107 call s:trace("Cleaning up temporary file: " . a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
108 call delete(a:path) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
109 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
110 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
111 |
0 | 112 " Prints a message if debug tracing is enabled. |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
113 function! s:trace(message, ...) |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
114 if g:lawrencium_trace || (a:0 && a:1) |
0 | 115 let l:message = "lawrencium: " . a:message |
116 echom l:message | |
117 endif | |
118 endfunction | |
119 | |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
120 " 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
|
121 function! s:error(message) |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
122 echom "lawrencium error: " . a:message |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
123 endfunction |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
124 |
0 | 125 " Throw a Lawrencium exception message. |
126 function! s:throw(message) | |
127 let v:errmsg = "lawrencium: " . a:message | |
128 throw v:errmsg | |
129 endfunction | |
130 | |
131 " Finds the repository root given a path inside that repository. | |
132 " Throw an error if not repository is found. | |
133 function! s:find_repo_root(path) | |
134 let l:path = s:stripslash(a:path) | |
135 let l:previous_path = "" | |
136 while l:path != l:previous_path | |
121
5168645017dd
Check for `.hg` directory instead of `.hg/store`.
Ludovic Chabant <ludovic@chabant.com>
parents:
119
diff
changeset
|
137 if isdirectory(l:path . '/.hg') |
104
518a6b2eff56
Simpler looking repo paths.
Ludovic Chabant <ludovic@chabant.com>
parents:
103
diff
changeset
|
138 return s:normalizepath(simplify(fnamemodify(l:path, ':p'))) |
0 | 139 endif |
140 let l:previous_path = l:path | |
141 let l:path = fnamemodify(l:path, ':h') | |
142 endwhile | |
143 call s:throw("No Mercurial repository found above: " . a:path) | |
144 endfunction | |
145 | |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
146 " 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
|
147 " 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
|
148 " |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
149 " If a second argument exists, it must be: |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
150 " - `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
|
151 " - `absolute`: to make the file path absolute. |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
152 " |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 if l:repo_path =~? '\v^lawrencium://' |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
157 let l:repo_path = strpart(l:repo_path, strlen('lawrencium://')) |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
158 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
159 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
160 let l:root_dir = '' |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
161 let l:at_idx = stridx(l:repo_path, '//') |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
162 if l:at_idx >= 0 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
163 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
|
164 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
|
165 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
166 |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
167 let l:value = '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
168 let l:action = '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
169 let l:actionidx = stridx(l:repo_path, '//') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
170 if l:actionidx >= 0 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
171 let l:action = strpart(l:repo_path, l:actionidx + 2) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
172 let l:repo_path = strpart(l:repo_path, 0, l:actionidx) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
173 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
174 let l:equalidx = stridx(l:action, '=') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
175 if l:equalidx >= 0 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
176 let l:value = strpart(l:action, l:equalidx + 1) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
177 let l:action = strpart(l:action, 0, l:equalidx) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
178 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
179 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
180 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
181 if a:0 > 0 |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
182 execute 'cd! ' . fnameescape(l:root_dir) |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
183 if a:1 == 'relative' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
184 let l:repo_path = fnamemodify(l:repo_path, ':.') |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
185 elseif a:1 == 'absolute' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
186 let l:repo_path = fnamemodify(l:repo_path, ':p') |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
187 endif |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
188 execute 'cd! -' |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
189 endif |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
190 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
191 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
|
192 return l:result |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
193 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
194 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
195 " 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
|
196 " set to the given value. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
197 function! s:find_buffer_window(varname, varvalue) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
198 for wnr in range(1, winnr('$')) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
199 let l:bnr = winbufnr(wnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
200 if getbufvar(l:bnr, a:varname) == a:varvalue |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
201 return l:wnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
202 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
203 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
204 return -1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
205 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
206 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
207 " 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
|
208 " - 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
|
209 " just open the new buffer. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
210 " - 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
|
211 " 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
|
212 " actual previous buffer (returned by things like `bufname('#')`) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
213 " 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
|
214 " buffer was opened. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
215 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
|
216 let l:edit_cmd = 'edit ' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
217 if getbufvar('%', a:varname) != '' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
218 let l:edit_cmd = 'keepalt edit ' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
219 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
220 execute l:edit_cmd . fnameescape(a:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
221 call setbufvar('%', a:varname, a:varvalue) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
222 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
223 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
224 " 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
|
225 " 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
|
226 " 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
|
227 " 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
|
228 " 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
|
229 function! s:delete_dependency_buffers(varname, varvalue) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
230 let l:cur_winnr = winnr() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
231 for bnr in range(1, bufnr('$')) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
232 if getbufvar(bnr, a:varname) == a:varvalue |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
233 " 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
|
234 " Otherwise, display the alternate buffer before deleting |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
235 " it so the window is not closed. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
236 let l:bwnr = bufwinnr(bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
237 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
|
238 if bufloaded(l:bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
239 call s:trace("Deleting dependency buffer " . bnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
240 execute "bdelete! " . bnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
241 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
242 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
|
243 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
244 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
245 execute l:bwnr . "wincmd w" |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
246 " 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
|
247 let l:prev_bnr = bufnr('#') |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
248 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
|
249 execute "buffer " . l:prev_bnr |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
250 if bufloaded(l:bnr) |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
251 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
|
252 execute "bdelete! " . bnr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
253 else |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
254 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
|
255 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
256 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
257 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
|
258 bdelete! |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
259 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
260 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
261 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
262 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
263 if l:cur_winnr != winnr() |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
264 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
|
265 execute l:cur_winnr . "wincmd w" |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
266 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
267 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
268 |
71 | 269 " Clean up all the 'HG:' lines from a commit message, and see if there's |
270 " any message left (Mercurial does this automatically, usually, but | |
271 " apparently not when you feed it a log file...). | |
272 function! s:clean_commit_file(log_file) abort | |
273 let l:lines = readfile(a:log_file) | |
274 call filter(l:lines, "v:val !~# '\\v^HG:'") | |
275 if len(filter(copy(l:lines), "v:val !~# '\\v^\\s*$'")) == 0 | |
276 return 0 | |
277 endif | |
278 call writefile(l:lines, a:log_file) | |
279 return 1 | |
280 endfunction | |
281 | |
0 | 282 " }}} |
283 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
284 " Mercurial Repository Object {{{ |
0 | 285 |
286 " Let's define a Mercurial repo 'class' using prototype-based object-oriented | |
287 " programming. | |
288 " | |
289 " The prototype dictionary. | |
290 let s:HgRepo = {} | |
291 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
292 " Constructor. |
0 | 293 function! s:HgRepo.New(path) abort |
294 let l:newRepo = copy(self) | |
295 let l:newRepo.root_dir = s:find_repo_root(a:path) | |
296 call s:trace("Built new Mercurial repository object at : " . l:newRepo.root_dir) | |
297 return l:newRepo | |
298 endfunction | |
299 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
300 " Gets a full path given a repo-relative path. |
0 | 301 function! s:HgRepo.GetFullPath(path) abort |
302 let l:root_dir = self.root_dir | |
98
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
303 if s:isabspath(a:path) |
103
bc6003e7159e
Fix stupid typo, make sure paths are normalized.
Ludovic Chabant <ludovic@chabant.com>
parents:
101
diff
changeset
|
304 call s:throw("Expected relative path, got absolute path: " . a:path) |
0 | 305 endif |
103
bc6003e7159e
Fix stupid typo, make sure paths are normalized.
Ludovic Chabant <ludovic@chabant.com>
parents:
101
diff
changeset
|
306 return s:normalizepath(l:root_dir . a:path) |
0 | 307 endfunction |
308 | |
98
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
309 " Gets a repo-relative path given any path. |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
310 function! s:HgRepo.GetRelativePath(path) abort |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
311 execute 'lcd! ' . fnameescape(self.root_dir) |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
312 let l:relative_path = fnamemodify(a:path, ':.') |
98
e5ac6464a767
Handle absolute/relative paths properly.
Ludovic Chabant <ludovic@chabant.com>
parents:
96
diff
changeset
|
313 execute 'lcd! -' |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
314 return l:relative_path |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
315 endfunction |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
316 |
105
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
317 " Gets, and optionally creates, a temp folder for some operation in the `.hg` |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
318 " directory. |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
319 function! s:HgRepo.GetTempDir(path, ...) abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
320 let l:tmp_dir = self.GetFullPath('.hg/lawrencium/' . a:path) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
321 if !isdirectory(l:tmp_dir) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
322 if a:0 > 0 && !a:1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
323 return '' |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
324 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
325 call mkdir(l:tmp_dir, 'p') |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
326 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
327 return l:tmp_dir |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
328 endfunction |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
329 |
0 | 330 " Gets a list of files matching a root-relative pattern. |
331 " If a flag is passed and is TRUE, a slash will be appended to all | |
332 " directories. | |
333 function! s:HgRepo.Glob(pattern, ...) abort | |
334 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
|
335 if (a:pattern =~# '\v^[/\\]') |
0 | 336 let l:root_dir = s:stripslash(l:root_dir) |
337 endif | |
338 let l:matches = split(glob(l:root_dir . a:pattern), '\n') | |
339 if a:0 && a:1 | |
340 for l:idx in range(len(l:matches)) | |
341 if !filereadable(l:matches[l:idx]) | |
342 let l:matches[l:idx] = l:matches[l:idx] . '/' | |
343 endif | |
344 endfor | |
345 endif | |
346 let l:strip_len = len(l:root_dir) | |
347 call map(l:matches, 'v:val[l:strip_len : -1]') | |
348 return l:matches | |
349 endfunction | |
350 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
351 " Gets a full Mercurial command. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
352 function! s:HgRepo.GetCommand(command, ...) abort |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
353 " 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
|
354 " argument list. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
355 let l:arg_list = a:000 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
356 if a:0 == 1 && type(a:1) == type([]) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
357 let l:arg_list = a:1 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
358 endif |
124
d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
359 let l:prev_shellslash = &shellslash |
d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
360 setlocal noshellslash |
0 | 361 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
|
362 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
|
363 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
|
364 if stridx(l:arg, ' ') >= 0 |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
365 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
|
366 else |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
367 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
|
368 endif |
a42b0e63a8ea
Fixed some bug with filenames with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
79
diff
changeset
|
369 endfor |
124
d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
370 if l:prev_shellslash |
d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
371 setlocal shellslash |
d5602a22bab5
Correctly escape the command on Windows when `&shellslash` is enabled.
Ludovic Chabant <ludovic@chabant.com>
parents:
123
diff
changeset
|
372 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
373 return l:hg_command |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
374 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
375 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
376 " Runs a Mercurial command in the repo. |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
377 function! s:HgRepo.RunCommand(command, ...) abort |
123
860e6502b239
Use HGPLAIN to ensure command outputs are clean.
Ludovic Chabant <ludovic@chabant.com>
parents:
122
diff
changeset
|
378 let l:prev_hgplain = $HGPLAIN |
860e6502b239
Use HGPLAIN to ensure command outputs are clean.
Ludovic Chabant <ludovic@chabant.com>
parents:
122
diff
changeset
|
379 let $HGPLAIN = 'true' |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
380 let l:all_args = [a:command] + a:000 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
381 let l:hg_command = call(self['GetCommand'], l:all_args, self) |
0 | 382 call s:trace("Running Mercurial command: " . l:hg_command) |
123
860e6502b239
Use HGPLAIN to ensure command outputs are clean.
Ludovic Chabant <ludovic@chabant.com>
parents:
122
diff
changeset
|
383 let l:cmd_out = system(l:hg_command) |
860e6502b239
Use HGPLAIN to ensure command outputs are clean.
Ludovic Chabant <ludovic@chabant.com>
parents:
122
diff
changeset
|
384 let $HGPLAIN = l:prev_hgplain |
860e6502b239
Use HGPLAIN to ensure command outputs are clean.
Ludovic Chabant <ludovic@chabant.com>
parents:
122
diff
changeset
|
385 return l:cmd_out |
0 | 386 endfunction |
387 | |
84
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
388 " 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
|
389 " buffer. |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
390 function! s:HgRepo.ReadCommandOutput(command, ...) abort |
84
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
391 function! s:PutOutputIntoBuffer(command_line) |
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
392 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
|
393 execute '0read!' . escape(a:command_line, '%#\') |
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
394 if l:was_buffer_empty " (Always true?) |
99
001b341ab8ad
Fix for Lawrencium files having folded sections deleted incorrectly.
Ludovic Chabant <ludovic@chabant.com>
parents:
98
diff
changeset
|
395 " '0read' inserts before the cursor, leaving a blank line which |
001b341ab8ad
Fix for Lawrencium files having folded sections deleted incorrectly.
Ludovic Chabant <ludovic@chabant.com>
parents:
98
diff
changeset
|
396 " needs to be deleted... but if there are folds in this thing, we |
001b341ab8ad
Fix for Lawrencium files having folded sections deleted incorrectly.
Ludovic Chabant <ludovic@chabant.com>
parents:
98
diff
changeset
|
397 " must open them all first otherwise we could delete the whole |
001b341ab8ad
Fix for Lawrencium files having folded sections deleted incorrectly.
Ludovic Chabant <ludovic@chabant.com>
parents:
98
diff
changeset
|
398 " contents of the last fold (since Vim may close them all by |
001b341ab8ad
Fix for Lawrencium files having folded sections deleted incorrectly.
Ludovic Chabant <ludovic@chabant.com>
parents:
98
diff
changeset
|
399 " default). |
111
01edb7c58e0c
Don't touch vim registers holding deletions.
Shane Harper <shane@shaneharper.net>
parents:
110
diff
changeset
|
400 normal! zRG"_dd |
84
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
401 endif |
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
402 endfunction |
b82babe7fdf8
Fix: blank line added by HgRepo.ReadCommandOutput().
Shane Harper <shane@shaneharper.net>
parents:
83
diff
changeset
|
403 |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
404 let l:all_args = [a:command] + a:000 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
405 let l:hg_command = call(self['GetCommand'], l:all_args, self) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
406 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
|
407 call s:PutOutputIntoBuffer(l:hg_command) |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
408 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
409 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
410 " 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
|
411 " 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
|
412 " unless '0' is passed as the 4th argument. |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
413 function! s:HgRepo.GetLawrenciumPath(path, action, value, ...) abort |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
414 let l:path = a:path |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
415 if a:0 == 0 || !a:1 |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
416 let l:path = self.GetRelativePath(a:path) |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
417 endif |
88
08e0ab5985d2
Correctly escape paths on Windows.
Ludovic Chabant <ludovic@chabant.com>
parents:
87
diff
changeset
|
418 let l:path = fnameescape(l:path) |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
419 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
|
420 if a:action !=? '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
421 let l:result = l:result . '//' . a:action |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
422 if a:value !=? '' |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
423 let l:result = l:result . '=' . a:value |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
424 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
425 endif |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
426 return l:result |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
427 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
428 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
429 " Repo cache map. |
0 | 430 let s:buffer_repos = {} |
431 | |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
432 " Get a cached repo. |
0 | 433 function! s:hg_repo(...) abort |
434 " Use the given path, or the mercurial directory of the current buffer. | |
435 if a:0 == 0 | |
436 if exists('b:mercurial_dir') | |
437 let l:path = b:mercurial_dir | |
438 else | |
439 let l:path = s:find_repo_root(expand('%:p')) | |
440 endif | |
441 else | |
442 let l:path = a:1 | |
443 endif | |
444 " Find a cache repo instance, or make a new one. | |
445 if has_key(s:buffer_repos, l:path) | |
446 return get(s:buffer_repos, l:path) | |
447 else | |
448 let l:repo = s:HgRepo.New(l:path) | |
449 let s:buffer_repos[l:path] = l:repo | |
450 return l:repo | |
451 endif | |
452 endfunction | |
453 | |
454 " Sets up the current buffer with Lawrencium commands if it contains a file from a Mercurial repo. | |
455 " If the file is not in a Mercurial repo, just exit silently. | |
456 function! s:setup_buffer_commands() abort | |
457 call s:trace("Scanning buffer '" . bufname('%') . "' for Lawrencium setup...") | |
458 let l:do_setup = 1 | |
459 if exists('b:mercurial_dir') | |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
460 if b:mercurial_dir =~# '\v^\s*$' |
0 | 461 unlet b:mercurial_dir |
462 else | |
463 let l:do_setup = 0 | |
464 endif | |
465 endif | |
466 try | |
467 let l:repo = s:hg_repo() | |
468 catch /^lawrencium\:/ | |
469 return | |
470 endtry | |
471 let b:mercurial_dir = l:repo.root_dir | |
472 if exists('b:mercurial_dir') && l:do_setup | |
473 call s:trace("Setting Mercurial commands for buffer '" . bufname('%')) | |
474 call s:trace(" with repo : " . expand(b:mercurial_dir)) | |
475 silent doautocmd User Lawrencium | |
476 endif | |
477 endfunction | |
478 | |
479 augroup lawrencium_detect | |
480 autocmd! | |
481 autocmd BufNewFile,BufReadPost * call s:setup_buffer_commands() | |
482 autocmd VimEnter * if expand('<amatch>')==''|call s:setup_buffer_commands()|endif | |
483 augroup end | |
484 | |
485 " }}} | |
486 | |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
487 " Buffer Object {{{ |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
488 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
489 " The prototype dictionary. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
490 let s:Buffer = {} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
491 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
492 " Constructor. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
493 function! s:Buffer.New(number) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
494 let l:newBuffer = copy(self) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
495 let l:newBuffer.nr = a:number |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
496 let l:newBuffer.var_backup = {} |
105
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
497 let l:newBuffer.cmd_names = {} |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
498 let l:newBuffer.on_delete = [] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
499 let l:newBuffer.on_winleave = [] |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
500 let l:newBuffer.on_unload = [] |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
501 execute 'augroup lawrencium_buffer_' . a:number |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
502 execute ' autocmd!' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
503 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
|
504 execute 'augroup end' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
505 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
|
506 return l:newBuffer |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
507 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
508 |
105
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
509 function! s:Buffer.GetName(...) dict abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
510 let l:name = bufname(self.nr) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
511 if a:0 > 0 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
512 let l:name = fnamemodify(l:name, a:1) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
513 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
514 return l:name |
66 | 515 endfunction |
516 | |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
517 function! s:Buffer.GetVar(var) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
518 return getbufvar(self.nr, a:var) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
519 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
520 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
521 function! s:Buffer.SetVar(var, value) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
522 if !has_key(self.var_backup, a:var) |
105
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
523 let self.var_backup[a:var] = getbufvar(self.nr, a:var) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
524 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
525 return setbufvar(self.nr, a:var, a:value) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
526 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
527 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
528 function! s:Buffer.RestoreVars() dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
529 for key in keys(self.var_backup) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
530 setbufvar(self.nr, key, self.var_backup[key]) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
531 endfor |
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 |
105
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
534 function! s:Buffer.DefineCommand(name, ...) dict abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
535 if a:0 == 0 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
536 call s:throw("Not enough parameters for s:Buffer.DefineCommands()") |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
537 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
538 if a:0 == 1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
539 let l:flags = '' |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
540 let l:cmd = a:1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
541 else |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
542 let l:flags = a:1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
543 let l:cmd = a:2 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
544 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
545 if has_key(self.cmd_names, a:name) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
546 call s:throw("Command '".a:name."' is already defined in buffer ".self.nr) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
547 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
548 if bufnr('%') != self.nr |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
549 call s:throw("You must move to buffer ".self.nr."first before defining local commands") |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
550 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
551 let self.cmd_names[a:name] = 1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
552 let l:real_flags = '' |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
553 if type(l:flags) == type('') |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
554 let l:real_flags = l:flags |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
555 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
556 execute 'command -buffer '.l:real_flags.' '.a:name.' '.l:cmd |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
557 endfunction |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
558 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
559 function! s:Buffer.DeleteCommand(name) dict abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
560 if !has_key(self.cmd_names, a:name) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
561 call s:throw("Command '".a:name."' has not been defined in buffer ".self.nr) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
562 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
563 if bufnr('%') != self.nr |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
564 call s:throw("You must move to buffer ".self.nr."first before deleting local commands") |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
565 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
566 execute 'delcommand '.a:name |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
567 call remove(self.cmd_names, a:name) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
568 endfunction |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
569 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
570 function! s:Buffer.DeleteCommands() dict abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
571 if bufnr('%') != self.nr |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
572 call s:throw("You must move to buffer ".self.nr."first before deleting local commands") |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
573 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
574 for name in keys(self.cmd_names) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
575 execute 'delcommand '.name |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
576 endfor |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
577 let self.cmd_names = {} |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
578 endfunction |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
579 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
580 function! s:Buffer.MoveToFirstWindow() dict abort |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
581 let l:win_nr = bufwinnr(self.nr) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
582 if l:win_nr < 0 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
583 if a:0 > 0 && a:1 == 0 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
584 return 0 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
585 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
586 call s:throw("No windows currently showing buffer ".self.nr) |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
587 endif |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
588 execute l:win_nr.'wincmd w' |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
589 return 1 |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
590 endfunction |
fc5ffa4614b4
Infrastructure improvements
Ludovic Chabant <ludovic@chabant.com>
parents:
104
diff
changeset
|
591 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
592 function! s:Buffer.OnDelete(cmd) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
593 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
|
594 call add(self.on_delete, a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
595 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
596 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
597 function! s:Buffer.OnWinLeave(cmd) dict abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
598 if len(self.on_winleave) == 0 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
599 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
|
600 execute 'augroup lawrencium_buffer_' . self.nr . '_winleave' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
601 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
602 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
|
603 execute 'augroup end' |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
604 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
605 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
|
606 call add(self.on_winleave, a:cmd) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
607 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
608 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
609 function! s:Buffer.OnUnload(cmd) dict abort |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
610 if len(self.on_unload) == 0 |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
611 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
|
612 execute 'augroup lawrencium_buffer_' . self.nr . '_unload' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
613 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
614 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
|
615 execute 'augroup end' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
616 endif |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
617 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
|
618 call add(self.on_unload, a:cmd) |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
619 endfunction |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
620 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
621 let s:buffer_objects = {} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
622 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
623 " 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
|
624 " current buffer if nothing is specified. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
625 function! s:buffer_obj(...) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
626 let l:bufnr = a:0 ? a:1 : bufnr('%') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
627 if !has_key(s:buffer_objects, l:bufnr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
628 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
|
629 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
630 return s:buffer_objects[l:bufnr] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
631 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
632 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
633 " Execute all the "on delete" callbacks. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
634 function! s:buffer_on_delete(number) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
635 let l:bufobj = s:buffer_objects[a:number] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
636 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
|
637 for cmd in l:bufobj.on_delete |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
638 call s:trace(" [" . cmd . "]") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
639 execute cmd |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
640 endfor |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
641 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
|
642 call remove(s:buffer_objects, l:bufobj.nr) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
643 execute 'augroup lawrencium_buffer_' . l:bufobj.nr |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
644 execute ' autocmd!' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
645 execute 'augroup end' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
646 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
647 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
648 " Execute all the "on winleave" callbacks. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
649 function! s:buffer_on_winleave(number) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
650 let l:bufobj = s:buffer_objects[a:number] |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
651 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
|
652 for cmd in l:bufobj.on_winleave |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
653 call s:trace(" [" . cmd . "]") |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
654 execute cmd |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
655 endfor |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
656 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
|
657 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
658 execute 'augroup end' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
659 endfunction |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
660 |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
661 " Execute all the "on unload" callbacks. |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
662 function! s:buffer_on_unload(number) abort |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
663 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
|
664 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
|
665 for cmd in l:bufobj.on_unload |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
666 call s:trace(" [" . cmd . "]") |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
667 execute cmd |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
668 endfor |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
669 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
|
670 execute ' autocmd!' |
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
671 execute 'augroup end' |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
672 endfunction |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
673 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
674 " }}} |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
675 |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
676 " Lawrencium Files {{{ |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
677 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
678 " Read revision (`hg cat`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
679 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
|
680 let l:rev = a:path_parts['value'] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
681 if l:rev == '' |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
682 call a:repo.ReadCommandOutput('cat', a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
683 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
684 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
|
685 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
686 endfunction |
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 " Status (`hg status`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
689 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
|
690 if a:path_parts['path'] == '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
691 call a:repo.ReadCommandOutput('status') |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
692 else |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
693 call a:repo.ReadCommandOutput('status', a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
694 endif |
71 | 695 setlocal nomodified |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
696 setlocal filetype=hgstatus |
71 | 697 setlocal bufhidden=delete |
698 setlocal buftype=nofile | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
699 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
700 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
701 " Log (`hg log`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
702 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
|
703 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
704 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
|
705 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
|
706 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
|
707 |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
708 if a:path_parts['path'] == '' |
112
b051b81cc365
Fix double escaping when Lawrencium is stored in a folder with spaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
111
diff
changeset
|
709 call a:repo.ReadCommandOutput(l:log_cmd, '--style', s:log_style_file) |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
710 else |
112
b051b81cc365
Fix double escaping when Lawrencium is stored in a folder with spaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
111
diff
changeset
|
711 call a:repo.ReadCommandOutput(l:log_cmd, '--style', s:log_style_file, a:full_path) |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
712 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
713 setlocal filetype=hglog |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
714 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
715 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
716 " Diff revisions (`hg diff`) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
717 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
|
718 let l:diffargs = [] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
719 let l:commaidx = stridx(a:path_parts['value'], ',') |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
720 if l:commaidx > 0 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
721 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
|
722 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
|
723 if l:rev1 == '-' |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
724 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
|
725 elseif l:rev2 == '-' |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
726 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
|
727 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
728 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
|
729 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
730 elseif a:path_parts['value'] != '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
731 let l:diffargs = [ '-c', a:path_parts['value'] ] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
732 else |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
733 let l:diffargs = [] |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
734 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
735 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
|
736 call add(l:diffargs, a:full_path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
737 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
738 call a:repo.ReadCommandOutput('diff', l:diffargs) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
739 setlocal filetype=diff |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
740 setlocal nofoldenable |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
741 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
742 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
743 " Annotate file |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
744 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
|
745 let l:cmd_args = ['-c', '-n', '-u', '-d', '-q'] |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
746 if a:path_parts['value'] == 'v=1' |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
747 call insert(l:cmd_args, '-v', 0) |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
748 endif |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
749 call add(l:cmd_args, a:full_path) |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
750 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
|
751 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
752 |
71 | 753 " MQ series |
754 function! s:read_lawrencium_qseries(repo, path_parts, full_path) abort | |
755 let l:names = split(a:repo.RunCommand('qseries'), '\n') | |
756 let l:head = split(a:repo.RunCommand('qapplied', '-s'), '\n') | |
757 let l:tail = split(a:repo.RunCommand('qunapplied', '-s'), '\n') | |
758 | |
759 let l:idx = 0 | |
760 let l:curbuffer = bufname('%') | |
761 for line in l:head | |
762 call setbufvar(l:curbuffer, 'lawrencium_patchname_' . (l:idx + 1), l:names[l:idx]) | |
763 call append(l:idx, "*" . line) | |
764 let l:idx = l:idx + 1 | |
765 endfor | |
766 for line in l:tail | |
767 call setbufvar(l:curbuffer, 'lawrencium_patchname_' . (l:idx + 1), l:names[l:idx]) | |
768 call append(l:idx, line) | |
769 let l:idx = l:idx + 1 | |
770 endfor | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
771 call setbufvar(l:curbuffer, 'lawrencium_patchname_top', l:names[len(l:head) - 1]) |
71 | 772 set filetype=hgqseries |
773 endfunction | |
774 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
775 " Generic read |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
776 let s:lawrencium_file_readers = { |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
777 \'rev': function('s:read_lawrencium_rev'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
778 \'log': function('s:read_lawrencium_log'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
779 \'diff': function('s:read_lawrencium_diff'), |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
780 \'status': function('s:read_lawrencium_status'), |
71 | 781 \'annotate': function('s:read_lawrencium_annotate'), |
782 \'qseries': function('s:read_lawrencium_qseries') | |
783 \} | |
784 let s:lawrencium_file_customoptions = { | |
785 \'status': 1 | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
786 \} |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
787 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
788 function! s:ReadLawrenciumFile(path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
789 call s:trace("Reading Lawrencium file: " . a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
790 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
|
791 if l:path_parts['root'] == '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
792 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
|
793 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
794 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
|
795 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
|
796 endif |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
797 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
798 " Call the registered reader. |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 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
|
803 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
804 " Setup the new buffer. |
71 | 805 if !has_key(s:lawrencium_file_customoptions, l:path_parts['action']) |
806 setlocal readonly | |
807 setlocal nomodified | |
808 setlocal bufhidden=delete | |
809 setlocal buftype=nofile | |
810 endif | |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
811 goto |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
812 |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
813 " Remember the real Lawrencium path, because Vim can fuck up the slashes |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
814 " on Windows. |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
815 let b:lawrencium_path = a:path |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
816 |
67
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
817 " Remember the repo it belongs to and make |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
818 " the Lawrencium commands available. |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
819 let b:mercurial_dir = l:repo.root_dir |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
820 call s:DefineMainCommands() |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
821 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
822 return '' |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
823 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
824 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
825 function! s:WriteLawrenciumFile(path) abort |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
826 call s:trace("Writing Lawrencium file: " . a:path) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
827 endfunction |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
828 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
829 augroup lawrencium_files |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
830 autocmd! |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
831 autocmd BufReadCmd lawrencium://**//**//* exe s:ReadLawrenciumFile(expand('<amatch>')) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
832 autocmd BufWriteCmd lawrencium://**//**//* exe s:WriteLawrenciumFile(expand('<amatch>')) |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
833 augroup END |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
834 |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
835 " }}} |
1cf08e4a7947
Made Lawrencium file easier to extend.
Ludovic Chabant <ludovic@chabant.com>
parents:
66
diff
changeset
|
836 |
14 | 837 " Buffer Commands Management {{{ |
0 | 838 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
839 " 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
|
840 " batch when we need to. |
0 | 841 let s:main_commands = [] |
842 | |
843 function! s:AddMainCommand(command) abort | |
844 let s:main_commands += [a:command] | |
845 endfunction | |
846 | |
847 function! s:DefineMainCommands() | |
848 for l:command in s:main_commands | |
849 execute 'command! -buffer ' . l:command | |
850 endfor | |
851 endfunction | |
852 | |
853 augroup lawrencium_main | |
854 autocmd! | |
855 autocmd User Lawrencium call s:DefineMainCommands() | |
856 augroup end | |
857 | |
14 | 858 " }}} |
859 | |
860 " Commands Auto-Complete {{{ | |
861 | |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
862 " 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
|
863 function! s:ListRepoFiles(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
864 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
|
865 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
866 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
867 endfunction |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
868 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
869 " 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
|
870 function! s:ListRepoDirs(ArgLead, CmdLine, CursorPos) abort |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
871 let l:matches = s:hg_repo().Glob(a:ArgLead . '*/') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
872 call map(l:matches, 's:normalizepath(v:val)') |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
873 return l:matches |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
874 endfunction |
0 | 875 |
14 | 876 " }}} |
877 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
878 " Hg {{{ |
0 | 879 |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
880 function! s:Hg(bang, ...) abort |
0 | 881 let l:repo = s:hg_repo() |
44
95f8e7cb5ca2
Stop fucking with my brain, Python.
Ludovic Chabant <ludovic@chabant.com>
parents:
43
diff
changeset
|
882 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
|
883 " 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
|
884 " to make auto-completed paths work magically. |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
885 execute 'cd! ' . fnameescape(l:repo.root_dir) |
43
fc20a265551d
Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents:
41
diff
changeset
|
886 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
887 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
|
888 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
|
889 execute 'cd! -' |
fc20a265551d
Added auto cd'ing into the repo root for `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents:
41
diff
changeset
|
890 endif |
110
e66df94ebceb
adding HgCmdPost custom autocmd
Ghennadi Pilipenco <pilipenco@molecularhealth.com>
parents:
108
diff
changeset
|
891 silent doautocmd User HgCmdPost |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
892 if a:bang |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
893 " 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
|
894 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
|
895 split |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
896 execute 'edit ' . fnameescape(l:temp_file) |
21
d0acefc1ec9a
Fixed multi-line output of `:Hg`.
Ludovic Chabant <ludovic@chabant.com>
parents:
18
diff
changeset
|
897 call append(0, split(l:output, '\n')) |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
898 call cursor(1, 1) |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
899 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
900 " Make it a temp buffer |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
901 setlocal bufhidden=delete |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
902 setlocal buftype=nofile |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
903 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
904 " 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
|
905 let l:command_name = s:GetHgCommandName(a:000) |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
906 if l:command_name != '' && exists('g:lawrencium_hg_commands_file_types') |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
907 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
|
908 if l:file_type != '' |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
909 execute 'setlocal ft=' . l:file_type |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
910 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
911 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
912 else |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
913 " Just print out the output of the command. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
914 echo l:output |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
915 endif |
0 | 916 endfunction |
917 | |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
918 " 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
|
919 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
|
920 if filereadable(s:usage_file) |
89 | 921 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
|
922 else |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
923 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
|
924 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
925 |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
926 " Include the command file type mappings. |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
927 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
|
928 if filereadable(s:file_type_mappings) |
89 | 929 execute "source " . fnameescape(s:file_type_mappings) |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
930 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
931 |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
932 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
|
933 " 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
|
934 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
|
935 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
936 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
937 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
938 " 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
|
939 " Gotta find out why... |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
940 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
|
941 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
|
942 let l:arglead = '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
943 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
944 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
945 " 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
|
946 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
|
947 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
|
948 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
949 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
950 " 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
|
951 " the command name). |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
952 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
|
953 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
|
954 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
955 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
956 " 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
|
957 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
|
958 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
|
959 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
|
960 " 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
|
961 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
|
962 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
|
963 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
|
964 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
965 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
966 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
967 " 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
|
968 if l:arglead[0] ==# '-' |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
969 return [] |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
970 else |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
971 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
|
972 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
973 |
46
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
974 function! s:GetHgCommandName(args) abort |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
975 for l:a in a:args |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
976 if stridx(l:a, '-') != 0 |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
977 return l:a |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
978 endif |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
979 endfor |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
980 return '' |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
981 endfunction |
6a4f5200d8da
`:Hg!` command changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
45
diff
changeset
|
982 |
26
de588a4bca10
Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
983 call s:AddMainCommand("-bang -complete=customlist,s:CompleteHg -nargs=* Hg :call s:Hg(<bang>0, <f-args>)") |
0 | 984 |
985 " }}} | |
986 | |
4
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
987 " Hgstatus {{{ |
b6e4446ed292
HgStatus now outputs to the location window.
Ludovic Chabant <ludovic@chabant.com>
parents:
0
diff
changeset
|
988 |
0 | 989 function! s:HgStatus() abort |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
990 " 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
|
991 let l:repo = s:hg_repo() |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
992 let l:status_path = l:repo.GetLawrenciumPath('', 'status', '') |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
993 |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
994 " 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
|
995 if g:lawrencium_status_win_split_above |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
996 execute "keepalt leftabove split " . fnameescape(l:status_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
|
997 else |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
998 execute "keepalt rightbelow split " . fnameescape(l:status_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
|
999 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
|
1000 |
86
685dfc4b5862
Fix `Hgstatus` incorrectly saying nothing has changed.
Ludovic Chabant <ludovic@chabant.com>
parents:
84
diff
changeset
|
1001 if (line('$') == 1 && getline(1) == '') |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1002 " Buffer is empty, which means there are not changes... |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1003 " Quit and display a message. |
64
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
1004 " 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
|
1005 bdelete |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1006 echom "Nothing was modified." |
64
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
1007 echom "" |
e75ecde434d7
Display simple message when `Hgstatus` is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
63
diff
changeset
|
1008 return |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
1009 endif |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
1010 |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 endif |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1016 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1017 " 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
|
1018 command! -buffer Hgstatusedit :call s:HgStatus_FileEdit(0) |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1019 command! -buffer Hgstatusdiff :call s:HgStatus_Diff(0) |
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 command! -buffer Hgstatustabdiffsum :call s:HgStatus_DiffSummary(3) |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1025 command! -buffer Hgstatusrefresh :call s:HgStatus_Refresh() |
116
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1026 command! -buffer -range -bang Hgstatusrevert :call s:HgStatus_Revert(<line1>, <line2>, <bang>0) |
63
02a1be804fe8
Using Lawrencium buffers for `Hgstatus`.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
1027 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
|
1028 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
|
1029 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
|
1030 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
|
1031 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
|
1032 |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
1033 " Add some handy mappings. |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1034 if g:lawrencium_define_mappings |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1035 nnoremap <buffer> <silent> <cr> :Hgstatusedit<cr> |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1036 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
|
1037 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
|
1038 nnoremap <buffer> <silent> <C-D> :Hgstatustabdiff<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1039 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
|
1040 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
|
1041 nnoremap <buffer> <silent> <C-H> :Hgstatusvdiffsum<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1042 nnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1043 nnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1044 nnoremap <buffer> <silent> <C-R> :Hgstatusrefresh<cr> |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1045 nnoremap <buffer> <silent> q :bdelete!<cr> |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1046 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1047 vnoremap <buffer> <silent> <C-A> :Hgstatusaddremove<cr> |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1048 vnoremap <buffer> <silent> <C-S> :Hgstatuscommit<cr> |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1049 endif |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1050 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1051 |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1052 function! s:HgStatus_Refresh(...) abort |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1053 if a:0 > 0 |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1054 let l:win_nr = bufwinnr(a:1) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1055 call s:trace("Switching back to status window ".l:win_nr) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1056 if l:win_nr < 0 |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1057 call s:throw("Can't find the status window anymore!") |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1058 endif |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1059 execute l:win_nr . 'wincmd w' |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1060 " Delete everything in the buffer, and re-read the status into it. |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1061 " TODO: In theory I would only have to do `edit` like below when we're |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1062 " already in the window, but for some reason Vim just goes bonkers and |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1063 " weird shit happens. I have no idea why, hence the work-around here |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1064 " to bypass the whole `BufReadCmd` auto-command altogether, and just |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1065 " edit the buffer in place. |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1066 normal! ggVGd |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1067 call s:ReadLawrenciumFile(b:lawrencium_path) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1068 return |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1069 endif |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1070 |
75
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
1071 " 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
|
1072 " the matching Mercurial command. |
066c8654e754
Reverted some automatic `Hgstatus` window refresh.
Ludovic Chabant <ludovic@chabant.com>
parents:
74
diff
changeset
|
1073 edit |
6
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
1074 endfunction |
1da613c13d81
Better hg-status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
5
diff
changeset
|
1075 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1076 function! s:HgStatus_FileEdit(newtab) abort |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1077 " 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
|
1078 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
|
1079 |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1080 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
|
1081 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
|
1082 " 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
|
1083 " 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
|
1084 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
|
1085 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
|
1086 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
|
1087 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
|
1088 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
|
1089 return |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1090 endif |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1091 endfor |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1092 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
|
1093 else |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1094 " 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
|
1095 " 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
|
1096 " 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
|
1097 " 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
|
1098 tabnew |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1099 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
|
1100 endif |
117
2e38e754c896
Correctly escape filename when opening a buffer from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
116
diff
changeset
|
1101 execute 'edit ' . fnameescape(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
|
1102 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
|
1103 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
|
1104 endif |
0 | 1105 endfunction |
1106 | |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1107 function! s:HgStatus_AddRemove(linestart, lineend) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1108 " Get the selected filenames. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1109 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
|
1110 if len(l:filenames) == 0 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1111 call s:error("No files to add or remove in selection or current line.") |
69 | 1112 return |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1113 endif |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1114 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1115 " 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
|
1116 let l:repo = s:hg_repo() |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1117 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
|
1118 |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1119 " Refresh the status window. |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1120 call s:HgStatus_Refresh() |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1121 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1122 |
116
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1123 function! s:HgStatus_Revert(linestart, lineend, bang) abort |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1124 " Get the selected filenames. |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1125 let l:filenames = s:HgStatus_GetSelectedFiles(a:linestart, a:lineend, ['M', 'A', 'R']) |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1126 if len(l:filenames) == 0 |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1127 call s:error("No files to revert in selection or current line.") |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1128 return |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1129 endif |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1130 |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1131 " Run `revert` on those paths. |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1132 " If the bang modifier is specified, revert with no backup. |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1133 let l:repo = s:hg_repo() |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1134 if a:bang |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1135 call insert(l:filenames, '-C', 0) |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1136 endif |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1137 call l:repo.RunCommand('revert', l:filenames) |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1138 |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1139 " Refresh the status window. |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1140 call s:HgStatus_Refresh() |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1141 endfunction |
7da11e029773
Revert files from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
114
diff
changeset
|
1142 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1143 function! s:HgStatus_Commit(linestart, lineend, bang, vertical) abort |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1144 " Get the selected filenames. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1145 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
|
1146 if len(l:filenames) == 0 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1147 call s:error("No files to commit in selection or file.") |
69 | 1148 return |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1149 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1150 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1151 " Run `Hgcommit` on those paths. |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1152 let l:buf_nr = bufnr('%') |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1153 let l:callback = 'call s:HgStatus_Refresh('.l:buf_nr.')' |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1154 call s:HgCommit(a:bang, a:vertical, l:callback, l:filenames) |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1155 endfunction |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1156 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1157 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
|
1158 " 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
|
1159 " 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
|
1160 " 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
|
1161 " 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
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 endif |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1168 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
|
1169 call s:HgDiff('%:p', l:hgdiffsplit) |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1170 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1171 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1172 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
|
1173 " 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
|
1174 let l:path = s:HgStatus_GetSelectedFile() |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1175 " Reuse the same diff summary window |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1176 let l:reuse_id = 'lawrencium_diffsum_for_' . bufnr('%') |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1177 let l:split_prev_win = (a:split < 3) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1178 let l:args = {'reuse_id': l:reuse_id, 'use_prev_win': l:split_prev_win, |
113
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1179 \'avoid_win': winnr(), 'split_mode': a:split} |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1180 call s:HgDiffSummary(l:path, l:args) |
58
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
1181 endfunction |
621185a5fa48
Added ability to show diff summaries from the status window.
Ludovic Chabant <ludovic@chabant.com>
parents:
57
diff
changeset
|
1182 |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1183 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
|
1184 " Get the selected filenames. |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1185 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
|
1186 if len(l:filenames) == 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1187 call s:error("No files in selection or file to create patch.") |
69 | 1188 return |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1189 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1190 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1191 " 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
|
1192 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
|
1193 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
|
1194 if a:0 > 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1195 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
|
1196 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
|
1197 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
|
1198 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1199 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
|
1200 |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1201 " Refresh the status window. |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1202 call s:HgStatus_Refresh() |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1203 endfunction |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1204 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1205 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
|
1206 " Get the selected filenames. |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1207 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
|
1208 if len(l:filenames) == 0 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1209 call s:error("No files in selection or file to refresh the patch.") |
69 | 1210 return |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1211 endif |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1212 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1213 " 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
|
1214 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
|
1215 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
|
1216 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
|
1217 |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1218 " Refresh the status window. |
a987094d5ae6
Made the `Hgstatus` window refresh itself when needed.
Ludovic Chabant <ludovic@chabant.com>
parents:
71
diff
changeset
|
1219 call s:HgStatus_Refresh() |
40
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1220 endfunction |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1221 |
a63ec818ab21
Added `qnew` and `qrefresh` commands to the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
37
diff
changeset
|
1222 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1223 function! s:HgStatus_GetSelectedFile() abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1224 let l:filenames = s:HgStatus_GetSelectedFiles() |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1225 return l:filenames[0] |
9
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1226 endfunction |
82a49134a85c
Added keyboard shortcuts to Hgstatus window.
Ludovic Chabant <ludovic@chabant.com>
parents:
8
diff
changeset
|
1227 |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1228 function! s:HgStatus_GetSelectedFiles(...) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1229 if a:0 >= 2 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1230 let l:lines = getline(a:1, a:2) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1231 else |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1232 let l:lines = [] |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1233 call add(l:lines, getline('.')) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1234 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1235 let l:filenames = [] |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1236 let l:repo = s:hg_repo() |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1237 for line in l:lines |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1238 if a:0 >= 3 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1239 let l:status = s:HgStatus_GetFileStatus(line) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1240 if index(a:3, l:status) < 0 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1241 continue |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1242 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1243 endif |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1244 " 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
|
1245 " look-aheads and look-behinds. See for yourself: |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1246 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
|
1247 let l:filename = l:repo.GetFullPath(l:filename) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1248 call add(l:filenames, l:filename) |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1249 endfor |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1250 return l:filenames |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1251 endfunction |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1252 |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1253 function! s:HgStatus_GetFileStatus(...) abort |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1254 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
|
1255 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
|
1256 endfunction |
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1257 |
26
de588a4bca10
Fixed completely wrong code that somehow almost ran completely fine.
Ludovic Chabant <ludovic@chabant.com>
parents:
25
diff
changeset
|
1258 call s:AddMainCommand("Hgstatus :call s:HgStatus()") |
0 | 1259 |
1260 " }}} | |
1261 | |
1262 " Hgcd, Hglcd {{{ | |
1263 | |
1264 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hgcd :cd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
1265 call s:AddMainCommand("-bang -nargs=? -complete=customlist,s:ListRepoDirs Hglcd :lcd<bang> `=s:hg_repo().GetFullPath(<q-args>)`") | |
1266 | |
1267 " }}} | |
1268 | |
1269 " Hgedit {{{ | |
1270 | |
27
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1271 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
|
1272 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
|
1273 if a:bang |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1274 execute "edit! " . fnameescape(l:full_path) |
27
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1275 else |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1276 execute "edit " . fnameescape(l:full_path) |
27
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1277 endif |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1278 endfunction |
09115be355e2
Fixed a bug with running `Hgedit` on a directory with a trailing backslash.
Ludovic Chabant <ludovic@chabant.com>
parents:
26
diff
changeset
|
1279 |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1280 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
|
1281 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1282 " }}} |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1283 |
70
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1284 " Hgvimgrep {{{ |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1285 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1286 function! s:HgVimGrep(bang, pattern, ...) abort |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1287 let l:repo = s:hg_repo() |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1288 let l:file_paths = [] |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1289 if a:0 > 0 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1290 for ff in a:000 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1291 let l:full_ff = l:repo.GetFullPath(ff) |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1292 call add(l:file_paths, l:full_ff) |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1293 endfor |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1294 else |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1295 call add(l:file_paths, l:repo.root_dir . "**") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1296 endif |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1297 if a:bang |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1298 execute "vimgrep! " . a:pattern . " " . join(l:file_paths, " ") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1299 else |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1300 execute "vimgrep " . a:pattern . " " . join(l:file_paths, " ") |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1301 endif |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1302 endfunction |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1303 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1304 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
|
1305 |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1306 " }}} |
16e873b2a4a8
Added `Hgvimgrep` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
69
diff
changeset
|
1307 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1308 " Hgdiff, Hgvdiff, Hgtabdiff {{{ |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1309 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1310 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
|
1311 " 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
|
1312 " 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
|
1313 " Otherwise, use the 1 or 2 revisions specified as extra parameters. |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1314 let l:rev1 = 'p1()' |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1315 let l:rev2 = '' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1316 if a:0 == 1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1317 if type(a:1) == type([]) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1318 if len(a:1) >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1319 let l:rev1 = a:1[0] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1320 let l:rev2 = a:1[1] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1321 elseif len(a:1) == 1 |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1322 let l:rev1 = a:1[0] |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1323 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1324 else |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1325 let l:rev1 = a:1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1326 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1327 elseif a:0 == 2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1328 let l:rev1 = a:1 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1329 let l:rev2 = a:2 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1330 endif |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1331 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1332 " 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
|
1333 " fancy filename modifiers. |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1334 let l:repo = s:hg_repo() |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1335 let l:path = expand(a:filename) |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1336 let l:diff_id = localtime() |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1337 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
|
1338 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1339 " 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
|
1340 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
|
1341 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
|
1342 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
|
1343 " 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
|
1344 " 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
|
1345 " 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
|
1346 " (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
|
1347 tabnew |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1348 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
|
1349 execute 'edit ' . fnameescape(l:path) |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1350 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
|
1351 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
|
1352 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
|
1353 else |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1354 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
|
1355 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1356 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
1357 " Make it part of the diff group. |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1358 call s:HgDiff_DiffThis(l:diff_id) |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1359 else |
52
cd0b1cea326c
Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents:
51
diff
changeset
|
1360 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
|
1361 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
|
1362 " 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
|
1363 tabnew |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1364 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
|
1365 endif |
52
cd0b1cea326c
Use Lawrencium files for displaying revisions in an `Hgdiff`.
Ludovic Chabant <ludovic@chabant.com>
parents:
51
diff
changeset
|
1366 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
|
1367 " Make it part of the diff group. |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1368 call s:HgDiff_DiffThis(l:diff_id) |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1369 endif |
93
bc5a8dff3fa0
Another attempt to fix weird issues with cleaning up diff buffers.
Ludovic Chabant <ludovic@chabant.com>
parents:
92
diff
changeset
|
1370 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
|
1371 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
|
1372 endif |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1373 |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1374 " Get the second file and open it too. |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1375 " Don't use `diffsplit` because it will set `&diff` before we get a chance |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1376 " to save a bunch of local settings that we will want to restore later. |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1377 let l:diffsplit = 'split' |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1378 if a:split >= 1 |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1379 let l:diffsplit = 'vsplit' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1380 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
|
1381 if l:rev2 == '' |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1382 execute l:diffsplit . ' ' . fnameescape(l:path) |
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1383 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1384 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
|
1385 execute l:diffsplit . ' ' . fnameescape(l:rev_path) |
8
1e155bfa94ad
Added 'Hg!' and 'Hgdiff/Hgvdiff'.
Ludovic Chabant <ludovic@chabant.com>
parents:
7
diff
changeset
|
1386 endif |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1387 call s:HgDiff_DiffThis(l:diff_id) |
0 | 1388 endfunction |
1389 | |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1390 function! s:HgDiff_DiffThis(diff_id) abort |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1391 " 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
|
1392 " 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
|
1393 " values, instead of their previous ones. |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1394 if &diff |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1395 call s:throw("Calling diffthis too late on a buffer!") |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1396 return |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1397 endif |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1398 call s:trace('Enabling diff mode on ' . bufname('%')) |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1399 let w:lawrencium_diffoff = {} |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1400 let w:lawrencium_diffoff['&diff'] = 0 |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1401 let w:lawrencium_diffoff['&wrap'] = &l:wrap |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1402 let w:lawrencium_diffoff['&scrollopt'] = &l:scrollopt |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1403 let w:lawrencium_diffoff['&scrollbind'] = &l:scrollbind |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1404 let w:lawrencium_diffoff['&cursorbind'] = &l:cursorbind |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1405 let w:lawrencium_diffoff['&foldmethod'] = &l:foldmethod |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1406 let w:lawrencium_diffoff['&foldcolumn'] = &l:foldcolumn |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1407 let w:lawrencium_diff_id = a:diff_id |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1408 diffthis |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1409 autocmd BufWinLeave <buffer> call s:HgDiff_CleanUp() |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1410 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1411 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1412 function! s:HgDiff_DiffOff(...) abort |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1413 " 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
|
1414 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
|
1415 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1416 " 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
|
1417 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
|
1418 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
|
1419 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
|
1420 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
|
1421 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
|
1422 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1423 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
|
1424 else |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1425 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
|
1426 diffoff |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1427 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1428 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1429 |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1430 function! s:HgDiff_GetDiffWindows(diff_id) abort |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1431 let l:result = [] |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1432 for nr in range(1, winnr('$')) |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1433 if getwinvar(nr, '&diff') && getwinvar(nr, 'lawrencium_diff_id') == a:diff_id |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1434 call add(l:result, nr) |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1435 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1436 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1437 return l:result |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1438 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1439 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1440 function! s:HgDiff_CleanUp() abort |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1441 " If we're not leaving one of our diff window, do nothing. |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1442 if !&diff || !exists('w:lawrencium_diff_id') |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1443 return |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1444 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1445 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1446 " If there will be only one diff window left (plus the one we're leaving), |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1447 " turn off diff in it and restore its local settings. |
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1448 let l:nrs = s:HgDiff_GetDiffWindows(w:lawrencium_diff_id) |
23
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1449 if len(l:nrs) <= 2 |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1450 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
|
1451 for nr in l:nrs |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1452 if getwinvar(nr, '&diff') |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1453 call s:HgDiff_DiffOff(nr) |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1454 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1455 endfor |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1456 else |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1457 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
|
1458 endif |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1459 endfunction |
84bceffbb19c
Restore window settings when a diff window is closed.
Ludovic Chabant <ludovic@chabant.com>
parents:
21
diff
changeset
|
1460 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1461 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
|
1462 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
|
1463 call s:AddMainCommand("-nargs=* Hgtabdiff :call s:HgDiff('%:p', 2, <f-args>)") |
0 | 1464 |
1465 " }}} | |
1466 | |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1467 " 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
|
1468 |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1469 function! s:HgDiffSummary(filename, present_args, ...) 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
|
1470 " 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
|
1471 " 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
|
1472 " 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
|
1473 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
|
1474 if a:0 == 1 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1475 if type(a:1) == type([]) |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1476 if len(a:1) >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1477 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
|
1478 elseif len(a:1) == 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1479 let l:revs = a:1[0] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1480 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1481 else |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1482 let l:revs = a:1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1483 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
|
1484 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
|
1485 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
|
1486 endif |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1487 |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1488 " 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
|
1489 " 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
|
1490 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
|
1491 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
|
1492 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
|
1493 let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs) |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1494 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1495 " Build the correct edit command, and switch to the correct window, based |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1496 " on the presentation arguments we got. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1497 if type(a:present_args) == type(0) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1498 " Just got a split mode. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1499 let l:valid_args = {'split_mode': a:present_args} |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1500 else |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1501 " Got complex args. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1502 let l:valid_args = a:present_args |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1503 endif |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1504 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1505 " First, see if we should reuse an existing window based on some buffer |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1506 " variable. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1507 let l:target_winnr = -1 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1508 let l:split = get(l:valid_args, 'split_mode', 0) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1509 let l:reuse_id = get(l:valid_args, 'reuse_id', '') |
113
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1510 let l:avoid_id = get(l:valid_args, 'avoid_win', -1) |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1511 if l:reuse_id != '' |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1512 let l:target_winnr = s:find_buffer_window(l:reuse_id, 1) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1513 if l:target_winnr > 0 && l:split != 3 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1514 " Unless we'll be opening in a new tab, don't split anymore, since |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1515 " we found the exact window we wanted. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1516 let l:split = 0 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1517 endif |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1518 call s:trace("Looking for window with '".l:reuse_id."', found: ".l:target_winnr) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1519 endif |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1520 " If we didn't find anything, see if we should use the current or previous |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1521 " window. |
113
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1522 if l:target_winnr <= 0 |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1523 let l:use_prev_win = get(l:valid_args, 'use_prev_win', 0) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1524 if l:use_prev_win |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1525 let l:target_winnr = winnr('#') |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1526 call s:trace("Will use previous window: ".l:target_winnr) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1527 endif |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1528 endif |
113
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1529 " And let's see if we have a window we should actually avoid. |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1530 if l:avoid_id >= 0 && |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1531 \(l:target_winnr == l:avoid_id || |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1532 \(l:target_winnr <= 0 && winnr() == l:avoid_id)) |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1533 for wnr in range(1, winnr('$')) |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1534 if wnr != l:avoid_id |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1535 call s:trace("Avoiding using window ".l:avoid_id. |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1536 \", now using: ".wnr) |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1537 let l:target_winnr = wnr |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1538 break |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1539 endif |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1540 endfor |
8718e6dbea1e
Fix a bug with `:Hgstatus` showing diff summaries in its own window.
Ludovic Chabant <ludovic@chabant.com>
parents:
112
diff
changeset
|
1541 endif |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1542 " Now let's see what kind of split we want to use, if any. |
66 | 1543 let l:cmd = 'edit ' |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1544 if l:split == 1 |
66 | 1545 let l:cmd = 'rightbelow split ' |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1546 elseif l:split == 2 |
66 | 1547 let l:cmd = 'rightbelow vsplit ' |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1548 elseif l:split == 3 |
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 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
|
1550 endif |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1551 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1552 " All good now, proceed. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1553 if l:target_winnr > 0 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1554 execute l:target_winnr . "wincmd w" |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1555 endif |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1556 execute 'keepalt ' . l:cmd . fnameescape(l:special) |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1557 |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1558 " Set the reuse ID if we had one. |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1559 if l:reuse_id != '' |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1560 call s:trace("Setting reuse ID '".l:reuse_id."' on buffer: ".bufnr('%')) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1561 call setbufvar('%', l:reuse_id, 1) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1562 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
|
1563 endfunction |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1564 |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1565 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
|
1566 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
|
1567 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
|
1568 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
|
1569 |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1570 " }}} |
671f5e18b515
Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Ludovic Chabant <ludovic@chabant.com>
parents:
49
diff
changeset
|
1571 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1572 " Hgcommit {{{ |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1573 |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1574 function! s:HgCommit(bang, vertical, callback, ...) abort |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1575 " 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
|
1576 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
|
1577 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1578 " Get the list of files to commit. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1579 " 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
|
1580 " actual list passed as the first extra parameter. |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1581 let l:filenames = [] |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1582 if a:0 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1583 let l:filenames = a:000 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1584 if a:0 == 1 && type(a:1) == type([]) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1585 let l:filenames = a:1 |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1586 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1587 endif |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1588 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1589 " 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
|
1590 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
|
1591 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
|
1592 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
|
1593 call append(0, ['', '']) |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1594 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
|
1595 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
|
1596 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1597 " 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
|
1598 " 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
|
1599 let b:mercurial_dir = l:repo.root_dir |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1600 let b:lawrencium_commit_files = l:filenames |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1601 if type(a:callback) == type([]) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1602 let b:lawrencium_commit_pre_callback = a:callback[0] |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1603 let b:lawrencium_commit_post_callback = a:callback[1] |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1604 let b:lawrencium_commit_abort_callback = a:callback[2] |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1605 else |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1606 let b:lawrencium_commit_pre_callback = 0 |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1607 let b:lawrencium_commit_post_callback = a:callback |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1608 let b:lawrencium_commit_abort_callback = 0 |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1609 endif |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1610 setlocal bufhidden=delete |
53
b7caa6693c39
`Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents:
52
diff
changeset
|
1611 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
|
1612 if a:bang |
15
f02e37f395ae
Added ability to add files from the `hg status` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
14
diff
changeset
|
1613 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
|
1614 else |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1615 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
|
1616 endif |
31
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1617 " Make commands available. |
3a0f7bb6ea64
Hgstatus window improvements and bug fixes:
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
1618 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
|
1619 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1620 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1621 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
|
1622 \'M': 'modified', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1623 \'A': 'added', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1624 \'R': 'removed', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1625 \'C': 'clean', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1626 \'!': 'missing', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1627 \'?': 'not tracked', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1628 \'I': 'ignored', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1629 \' ': '', |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1630 \} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1631 |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1632 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
|
1633 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
|
1634 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
|
1635 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
|
1636 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
|
1637 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
|
1638 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
|
1639 |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1640 execute 'lcd ' . fnameescape(a:repo.root_dir) |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1641 if len(a:filenames) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1642 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
|
1643 else |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1644 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
|
1645 endif |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1646 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
|
1647 if l:line ==# '' |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1648 continue |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1649 endif |
11
b4baab0a4a92
Made most regex use the 'very-magic' syntax.
Ludovic Chabant <ludovic@chabant.com>
parents:
10
diff
changeset
|
1650 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
|
1651 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
|
1652 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
|
1653 endfor |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1654 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1655 return l:msg |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1656 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1657 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1658 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
|
1659 " 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
|
1660 if !filereadable(a:log_file) |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1661 call s:error("abort: Commit message not saved") |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1662 if exists('b:lawrencium_commit_abort_callback') && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1663 \type(b:lawrencium_commit_abort_callback) == type("") && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1664 \b:lawrencium_commit_abort_callback != '' |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1665 call s:trace("Executing abort callback: ".b:lawrencium_commit_abort_callback) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1666 execute b:lawrencium_commit_abort_callback |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1667 endif |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1668 return |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1669 endif |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1670 |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1671 " Execute a pre-callback if there is one. |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1672 if exists('b:lawrencium_commit_pre_callback') && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1673 \type(b:lawrencium_commit_pre_callback) == type("") && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1674 \b:lawrencium_commit_pre_callback != '' |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1675 call s:trace("Executing pre callback: ".b:lawrencium_commit_pre_callback) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1676 execute b:lawrencium_commit_pre_callback |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1677 endif |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1678 |
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
|
1679 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
|
1680 |
71 | 1681 " Clean all the 'HG: ' lines. |
1682 let l:is_valid = s:clean_commit_file(a:log_file) | |
1683 if !l:is_valid | |
18
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1684 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
|
1685 return |
4f04d5e052eb
Abort commit if the commit message is empty.
Ludovic Chabant <ludovic@chabant.com>
parents:
17
diff
changeset
|
1686 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
|
1687 |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1688 " 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
|
1689 let l:repo = s:hg_repo() |
33
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1690 let l:hg_args = ['-l', a:log_file] |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1691 call extend(l:hg_args, b:lawrencium_commit_files) |
a5b2f8e4fb6c
Changes to the `Hgstatus` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
32
diff
changeset
|
1692 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
|
1693 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
|
1694 call s:trace("Output from hg commit:", 1) |
17
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1695 for l:output_line in split(l:output, '\n') |
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1696 echom l:output_line |
5c6c605d0660
Better output for `hg commit`.
Ludovic Chabant <ludovic@chabant.com>
parents:
16
diff
changeset
|
1697 endfor |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1698 endif |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1699 |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1700 " Execute a post-callback if there is one. |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1701 if exists('b:lawrencium_commit_post_callback') && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1702 \type(b:lawrencium_commit_post_callback) == type("") && |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1703 \b:lawrencium_commit_post_callback != '' |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1704 call s:trace("Executing post callback: ".b:lawrencium_commit_post_callback) |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1705 execute b:lawrencium_commit_post_callback |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1706 endif |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1707 endfunction |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1708 |
106
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1709 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgcommit :call s:HgCommit(<bang>0, 0, 0, <f-args>)") |
77f77b2c2738
Callback system for `Hgcommit` so we can refresh the `Hgstatus` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
105
diff
changeset
|
1710 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgvcommit :call s:HgCommit(<bang>0, 1, 0, <f-args>)") |
10
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1711 |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1712 " }}} |
7d16084d40a9
Added 'Hgcommit' command (and this very change is committed with it!).
Ludovic Chabant <ludovic@chabant.com>
parents:
9
diff
changeset
|
1713 |
37
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1714 " Hgrevert {{{ |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1715 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1716 function! s:HgRevert(bang, ...) abort |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1717 " Get the files to revert. |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1718 let l:filenames = a:000 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1719 if a:0 == 0 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1720 let l:filenames = [ expand('%:p') ] |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1721 endif |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1722 if a:bang |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1723 call insert(l:filenames, '--no-backup', 0) |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1724 endif |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1725 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1726 " Get the repo and run the command. |
37
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1727 let l:repo = s:hg_repo() |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1728 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
|
1729 |
31801dcca77d
Re-edit a reverted file to see the change.
Ludovic Chabant <ludovic@chabant.com>
parents:
81
diff
changeset
|
1730 " 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
|
1731 edit |
37
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1732 endfunction |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1733 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1734 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
|
1735 |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1736 " }}} |
9361f6b9e5a4
Added `Hgrevert` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
33
diff
changeset
|
1737 |
119
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1738 " Hgremove {{{ |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1739 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1740 function! s:HgRemove(bang, ...) abort |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1741 " Get the files to remove. |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1742 let l:filenames = a:000 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1743 if a:0 == 0 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1744 let l:filenames = [ expand('%:p') ] |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1745 endif |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1746 if a:bang |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1747 call insert(l:filenames, '--force', 0) |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1748 endif |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1749 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1750 " Get the repo and run the command. |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1751 let l:repo = s:hg_repo() |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1752 call l:repo.RunCommand('rm', l:filenames) |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1753 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1754 " Re-edit the file to see the change. |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1755 edit |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1756 endfunction |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1757 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1758 call s:AddMainCommand("-bang -nargs=* -complete=customlist,s:ListRepoFiles Hgremove :call s:HgRemove(<bang>0, <f-args>)") |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1759 |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1760 " }}} |
4ca40abecc2a
Add `:Hgremove` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
117
diff
changeset
|
1761 |
66 | 1762 " Hglog, Hglogthis {{{ |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1763 |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1764 function! s:HgLog(vertical, ...) abort |
66 | 1765 " Get the file or directory to get the log from. |
1766 " (empty string is for the whole repository) | |
1767 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
|
1768 if a:0 > 0 && matchstr(a:1, '\v-*') == "" |
66 | 1769 let l:path = l:repo.GetRelativePath(expand(a:1)) |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1770 else |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1771 let l:path = '' |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1772 endif |
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1773 |
66 | 1774 " Get the Lawrencium path for this `hg log`, |
1775 " 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
|
1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 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
|
1781 |
e21a1819ab27
New command to export a patch and allow existing log command to take options.
Kannan Rajah <krajah@maprtech.com>
parents:
90
diff
changeset
|
1782 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
|
1783 if a:vertical |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1784 execute 'vertical pedit ' . fnameescape(l:log_path) |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1785 else |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1786 execute 'pedit ' . fnameescape(l:log_path) |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1787 endif |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1788 wincmd P |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1789 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1790 " Add some other nice commands and mappings. |
66 | 1791 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
|
1792 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
|
1793 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
|
1794 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
|
1795 command! -buffer -nargs=+ -complete=file Hglogexport :call s:HgLog_ExportPatch(<f-args>) |
66 | 1796 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
|
1797 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
|
1798 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
|
1799 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
|
1800 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
|
1801 endif |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1802 |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1803 if g:lawrencium_define_mappings |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1804 nnoremap <buffer> <silent> <C-U> :Hglogdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1805 nnoremap <buffer> <silent> <C-H> :Hglogvdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1806 nnoremap <buffer> <silent> <cr> :Hglogvdiffsum<cr> |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1807 nnoremap <buffer> <silent> q :bdelete!<cr> |
66 | 1808 if l:is_file |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1809 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
|
1810 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
|
1811 nnoremap <buffer> <silent> <C-V> :Hglogvdiff<cr> |
55
6a61724190ea
Improvements to Lawrencium paths:
Ludovic Chabant <ludovic@chabant.com>
parents:
53
diff
changeset
|
1812 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1813 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1814 |
48
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1815 " 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
|
1816 let l:bufobj = s:buffer_obj() |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1817 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
|
1818 endfunction |
85e39bdd7089
Lots of changes that should have gone in other commits (ugh):
Ludovic Chabant <ludovic@chabant.com>
diff
changeset
|
1819 |
65
e8f252a7ed9e
Made the `Hglog` window use Lawrencium buffers:
Ludovic Chabant <ludovic@chabant.com>
parents:
64
diff
changeset
|
1820 function! s:HgLog_Delete(bufnr) |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1821 if g:lawrencium_auto_close_buffers |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1822 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
|
1823 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
|
1824 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1825 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1826 |
66 | 1827 function! s:HgLog_FileRevEdit() |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1828 let l:repo = s:hg_repo() |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1829 let l:bufobj = s:buffer_obj() |
66 | 1830 let l:rev = s:HgLog_GetSelectedRev() |
1831 let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) | |
1832 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
|
1833 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1834 " 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
|
1835 " 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
|
1836 wincmd p |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1837 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
|
1838 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1839 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1840 function! s:HgLog_Diff(split, ...) abort |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1841 let l:revs = [] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1842 if a:0 >= 2 |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1843 let l:revs = [a:1, a:2] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1844 elseif a:0 == 1 |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1845 let l:revs = ['p1('.a:1.')', a:1] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1846 else |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1847 let l:sel = s:HgLog_GetSelectedRev() |
107
6846e12f8ec8
Improvements for the `Hgdiff` family of commands
Ludovic Chabant <ludovic@chabant.com>
parents:
106
diff
changeset
|
1848 let l:revs = ['p1('.l:sel.')', l:sel] |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1849 endif |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1850 |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1851 let l:repo = s:hg_repo() |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1852 let l:bufobj = s:buffer_obj() |
66 | 1853 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
|
1854 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
|
1855 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1856 " 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
|
1857 " 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
|
1858 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
|
1859 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
|
1860 endif |
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1861 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
|
1862 endfunction |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1863 |
87
e688b658ce5b
Add variants of existing commands that open things in a new tab page.
Ludovic Chabant <ludovic@chabant.com>
parents:
86
diff
changeset
|
1864 function! s:HgLog_DiffSummary(split, ...) abort |
73
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1865 let l:revs = [] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1866 if a:0 >= 2 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1867 let l:revs = [a:1, a:2] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1868 elseif a:0 == 1 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1869 let l:revs = [a:1] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1870 else |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1871 let l:revs = [s:HgLog_GetSelectedRev()] |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1872 endif |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1873 |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1874 let l:repo = s:hg_repo() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1875 let l:bufobj = s:buffer_obj() |
785d1a1faa6c
Changes and fixes to the `Hglog` window:
Ludovic Chabant <ludovic@chabant.com>
parents:
72
diff
changeset
|
1876 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
|
1877 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
|
1878 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1879 " 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
|
1880 " and split for the diff summary from there. |
101
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1881 let l:reuse_id = 'lawrencium_diffsum_for_' . bufnr('%') |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1882 let l:split_prev_win = (a:split < 3) |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1883 let l:args = {'reuse_id': l:reuse_id, 'use_prev_win': l:split_prev_win, |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1884 \'split_mode': a:split} |
2078a8b475c2
More advanced way to know what window to pick to show a diff summary.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1885 call s:HgDiffSummary(l:path, l:args, l:revs) |
49
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1886 endfunction |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1887 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1888 function! s:HgLog_GetSelectedRev(...) abort |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1889 if a:0 == 1 |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1890 let l:line = getline(a:1) |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1891 else |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1892 let l:line = getline('.') |
dffb41c2067c
Lawrencium files changes:
Ludovic Chabant <ludovic@chabant.com>
parents:
48
diff
changeset
|
1893 endif |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1894 " Behold, Vim's look-ahead regex syntax again! WTF. |
53
b7caa6693c39
`Hglog` window improvements:
Ludovic Chabant <ludovic@chabant.com>
parents:
52
diff
changeset
|
1895 let l:rev = matchstr(l:line, '\v^(\d+)(\:)@=') |
45
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1896 if l:rev == '' |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1897 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
|
1898 endif |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1899 return l:rev |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1900 endfunction |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1901 |
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
|
1902 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
|
1903 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
|
1904 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
|
1905 " 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
|
1906 if has('win32') |
e856f8dc22a8
`Hglogexport` uses relative paths correctly on Windows, auto-completes to files.
Ludovic Chabant <ludovic@chabant.com>
parents:
91
diff
changeset
|
1907 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
|
1908 else |
e856f8dc22a8
`Hglogexport` uses relative paths correctly on Windows, auto-completes to files.
Ludovic Chabant <ludovic@chabant.com>
parents:
91
diff
changeset
|
1909 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
|
1910 endif |
e856f8dc22a8
`Hglogexport` uses relative paths correctly on Windows, auto-completes to files.
Ludovic Chabant <ludovic@chabant.com>
parents:
91
diff
changeset
|
1911 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
|
1912 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
|
1913 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
|
1914 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
|
1915 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
|
1916 |
e21a1819ab27
New command to export a patch and allow existing log command to take options.
Kannan Rajah <krajah@maprtech.com>
parents:
90
diff
changeset
|
1917 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
|
1918 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
|
1919 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
|
1920 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
|
1921 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
|
1922 |
e21a1819ab27
New command to export a patch and allow existing log command to take options.
Kannan Rajah <krajah@maprtech.com>
parents:
90
diff
changeset
|
1923 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
|
1924 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
|
1925 |
e21a1819ab27
New command to export a patch and allow existing log command to take options.
Kannan Rajah <krajah@maprtech.com>
parents:
90
diff
changeset
|
1926 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
|
1927 |
e21a1819ab27
New command to export a patch and allow existing log command to take options.
Kannan Rajah <krajah@maprtech.com>
parents:
90
diff
changeset
|
1928 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
|
1929 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
|
1930 |
68
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1931 call s:AddMainCommand("Hglogthis :call s:HgLog(0, '%:p')") |
7afcd4d37062
Added vertical `Hglog` commands.
Ludovic Chabant <ludovic@chabant.com>
parents:
67
diff
changeset
|
1932 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
|
1933 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
|
1934 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
|
1935 |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1936 " }}} |
ea0ae8f6af81
Added `Hglog` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
44
diff
changeset
|
1937 |
96
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
1938 " Hgannotate, Hgwannotate {{{ |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1939 |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1940 function! s:HgAnnotate(bang, verbose, ...) abort |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1941 " Open the file to annotate if needed. |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1942 if a:0 > 0 |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1943 call s:HgEdit(a:bang, a:1) |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1944 endif |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1945 |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1946 " Get the Lawrencium path for the annotated file. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1947 let l:path = expand('%:p') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1948 let l:bufnr = bufnr('%') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1949 let l:repo = s:hg_repo() |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1950 let l:value = a:verbose ? 'v=1' : '' |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
1951 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
|
1952 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1953 " Check if we're trying to annotate something with local changes. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1954 let l:has_local_edits = 0 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1955 let l:path_status = l:repo.RunCommand('status', l:path) |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1956 if l:path_status != '' |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1957 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
|
1958 let l:has_local_edits = 1 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1959 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1960 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1961 if l:has_local_edits |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1962 " Just open the output of the command. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1963 echom "Local edits found, will show the annotations for the parent revision." |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1964 execute 'edit ' . fnameescape(l:annotation_path) |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1965 setlocal nowrap nofoldenable |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1966 setlocal filetype=hgannotate |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1967 else |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1968 " Store some info about the current buffer. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1969 let l:cur_topline = line('w0') + &scrolloff |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1970 let l:cur_line = line('.') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1971 let l:cur_wrap = &wrap |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1972 let l:cur_foldenable = &foldenable |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1973 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1974 " 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
|
1975 " having disabled wrapping and folds on the current file. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1976 " Make both windows scroll-bound. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1977 setlocal scrollbind nowrap nofoldenable |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
1978 execute 'keepalt leftabove vsplit ' . fnameescape(l:annotation_path) |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1979 setlocal nonumber |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1980 setlocal scrollbind nowrap nofoldenable foldcolumn=0 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1981 setlocal filetype=hgannotate |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1982 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1983 " 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
|
1984 " 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
|
1985 let l:annotate_buffer = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1986 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
|
1987 call l:annotate_buffer.OnDelete('setlocal noscrollbind') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1988 if l:cur_wrap |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1989 call l:annotate_buffer.OnDelete('setlocal wrap') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1990 endif |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1991 if l:cur_foldenable |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1992 call l:annotate_buffer.OnDelete('setlocal foldenable') |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1993 endif |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1994 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
1995 " 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
|
1996 " opened the annotation window. |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1997 execute l:cur_topline |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1998 normal! zt |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
1999 execute l:cur_line |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2000 syncbind |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2001 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2002 " 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
|
2003 if a:verbose |
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
2004 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
|
2005 let l:token_end = 5 |
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
2006 else |
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
2007 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
|
2008 let l:token_end = 3 |
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
2009 endif |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2010 if l:last_token < 0 |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2011 echoerr "Can't find the end of the annotation columns." |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2012 else |
96
1ea783dd06dd
Fix typo bug, annotate window width.
Ludovic Chabant <ludovic@chabant.com>
parents:
95
diff
changeset
|
2013 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
|
2014 execute "vertical resize " . l:column_count |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2015 setlocal winfixwidth |
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2016 endif |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2017 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2018 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2019 " Make the annotate buffer a Lawrencium buffer. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2020 let b:mercurial_dir = l:repo.root_dir |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2021 let b:lawrencium_annotated_path = l:path |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2022 let b:lawrencium_annotated_bufnr = l:bufnr |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2023 call s:DefineMainCommands() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2024 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2025 " Add some other nice commands and mappings. |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2026 command! -buffer Hgannotatediffsum :call s:HgAnnotate_DiffSummary() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2027 if g:lawrencium_define_mappings |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2028 nnoremap <buffer> <silent> <cr> :Hgannotatediffsum<cr> |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2029 endif |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2030 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2031 " Clean up when the annotate buffer is deleted. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2032 let l:bufobj = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2033 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
|
2034 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2035 |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2036 function! s:HgAnnotate_Delete(bufnr) abort |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2037 if g:lawrencium_auto_close_buffers |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2038 call s:delete_dependency_buffers('lawrencium_diff_for', a:bufnr) |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2039 endif |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2040 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2041 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2042 function! s:HgAnnotate_DiffSummary() abort |
61
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2043 " 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
|
2044 let l:line = getline('.') |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2045 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
|
2046 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2047 " 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
|
2048 " annotation. |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2049 let l:repo = s:hg_repo() |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2050 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
|
2051 let l:annotate_buffer = s:buffer_obj() |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2052 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2053 " 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
|
2054 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
|
2055 if l:diff_winnr == -1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2056 " 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
|
2057 " split with the diff for the specified revision. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2058 execute bufwinnr(b:lawrencium_annotated_bufnr) . 'wincmd w' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2059 execute 'rightbelow split ' . fnameescape(l:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2060 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
|
2061 let b:lawrencium_quit_on_delete = 1 |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2062 else |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2063 " Found! Use that window to open the diff. |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2064 execute l:diff_winnr . 'wincmd w' |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2065 execute 'edit ' . fnameescape(l:path) |
ea794e48d4e2
Better way to handle buffer actions:
Ludovic Chabant <ludovic@chabant.com>
parents:
59
diff
changeset
|
2066 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
|
2067 endif |
59
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2068 endfunction |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2069 |
95
d38be34b403b
`Hgannotate` improvements.
Ludovic Chabant <ludovic@chabant.com>
parents:
94
diff
changeset
|
2070 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
|
2071 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
|
2072 |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2073 " }}} |
396da6e76952
Added `Hgannotate` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
58
diff
changeset
|
2074 |
71 | 2075 " Hgqseries {{{ |
2076 | |
2077 function! s:HgQSeries() abort | |
2078 " Open the MQ series in the preview window and jump to it. | |
2079 let l:repo = s:hg_repo() | |
2080 let l:path = l:repo.GetLawrenciumPath('', 'qseries', '') | |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
2081 execute 'pedit ' . fnameescape(l:path) |
71 | 2082 wincmd P |
2083 | |
2084 " Make the series buffer a Lawrencium buffer. | |
2085 let b:mercurial_dir = l:repo.root_dir | |
2086 call s:DefineMainCommands() | |
2087 | |
2088 " Add some commands and mappings. | |
2089 command! -buffer Hgqseriesgoto :call s:HgQSeries_Goto() | |
2090 command! -buffer Hgqserieseditmessage :call s:HgQSeries_EditMessage() | |
2091 command! -buffer -nargs=+ Hgqseriesrename :call s:HgQSeries_Rename(<f-args>) | |
2092 if g:lawrencium_define_mappings | |
2093 nnoremap <buffer> <silent> <C-g> :Hgqseriesgoto<cr> | |
2094 nnoremap <buffer> <silent> <C-e> :Hgqserieseditmessage<cr> | |
2095 nnoremap <buffer> <silent> q :bdelete!<cr> | |
2096 endif | |
2097 endfunction | |
2098 | |
2099 function! s:HgQSeries_GetCurrentPatchName() abort | |
2100 let l:pos = getpos('.') | |
2101 return getbufvar('%', 'lawrencium_patchname_' . l:pos[1]) | |
2102 endfunction | |
2103 | |
2104 function! s:HgQSeries_Goto() abort | |
2105 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
2106 let l:patchname = s:HgQSeries_GetCurrentPatchName() |
71 | 2107 if len(l:patchname) == 0 |
2108 call s:error("No patch to go to here.") | |
2109 return | |
2110 endif | |
2111 call l:repo.RunCommand('qgoto', l:patchname) | |
2112 edit | |
2113 endfunction | |
2114 | |
2115 function! s:HgQSeries_Rename(...) abort | |
2116 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
2117 let l:current_name = s:HgQSeries_GetCurrentPatchName() |
71 | 2118 if len(l:current_name) == 0 |
2119 call s:error("No patch to rename here.") | |
2120 return | |
2121 endif | |
2122 let l:new_name = '"' . join(a:000, ' ') . '"' | |
2123 call l:repo.RunCommand('qrename', l:current_name, l:new_name) | |
2124 edit | |
2125 endfunction | |
2126 | |
2127 function! s:HgQSeries_EditMessage() abort | |
2128 let l:repo = s:hg_repo() | |
78
e42f813b4a39
Fixed some bugs with the `Hgqseries` window.
Ludovic Chabant <ludovic@chabant.com>
parents:
76
diff
changeset
|
2129 let l:patchname = getbufvar('%', 'lawrencium_patchname_top') |
71 | 2130 if len(l:patchname) == 0 |
2131 call s:error("No patch to edit here.") | |
2132 return | |
2133 endif | |
2134 let l:current = split(l:repo.RunCommand('qheader', l:patchname), '\n') | |
2135 | |
2136 " Open a temp file to write the commit message. | |
2137 let l:temp_file = s:tempname('hg-qrefedit-', '.txt') | |
2138 split | |
122
a9136d95cf47
Escape paths to fix issues with repository paths with spaces in them.
Ludovic Chabant <ludovic@chabant.com>
parents:
121
diff
changeset
|
2139 execute 'edit ' . fnameescape(l:temp_file) |
71 | 2140 call append(0, 'HG: Enter the new commit message for patch "' . l:patchname . '" here.\n') |
2141 call append(0, '') | |
2142 call append(0, l:current) | |
2143 call cursor(1, 1) | |
2144 | |
2145 " Make it a temp buffer that will actually change the commit message | |
2146 " when it is saved and closed. | |
2147 let b:mercurial_dir = l:repo.root_dir | |
2148 let b:lawrencium_patchname = l:patchname | |
2149 setlocal bufhidden=delete | |
2150 setlocal filetype=hgcommit | |
2151 autocmd BufDelete <buffer> call s:HgQSeries_EditMessage_Execute(expand('<afile>:p')) | |
2152 | |
2153 call s:DefineMainCommands() | |
2154 endfunction | |
2155 | |
2156 function! s:HgQSeries_EditMessage_Execute(log_file) abort | |
2157 if !filereadable(a:log_file) | |
2158 call s:error("abort: Commit message not saved") | |
2159 return | |
2160 endif | |
2161 | |
2162 " Clean all the 'HG:' lines. | |
2163 let l:is_valid = s:clean_commit_file(a:log_file) | |
2164 if !l:is_valid | |
2165 call s:error("abort: Empty commit message") | |
2166 return | |
2167 endif | |
2168 | |
2169 " Get the repo and edit the given patch. | |
2170 let l:repo = s:hg_repo() | |
2171 let l:hg_args = ['-s', '-l', a:log_file] | |
2172 call l:repo.RunCommand('qref', l:hg_args) | |
2173 endfunction | |
2174 | |
108
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2175 call s:AddMainCommand("Hgqseries call s:HgQSeries()") |
71 | 2176 |
108
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2177 " }}} |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2178 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2179 " Hgrecord {{{ |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2180 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2181 function! s:HgRecord(split) abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2182 let l:repo = s:hg_repo() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2183 let l:orig_buf = s:buffer_obj() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2184 let l:tmp_path = l:orig_buf.GetName(':p') . '~record' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2185 let l:diff_id = localtime() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2186 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2187 " Start diffing on the current file, enable some commands. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2188 call l:orig_buf.DefineCommand('Hgrecordabort', ':call s:HgRecord_Abort()') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2189 call l:orig_buf.DefineCommand('Hgrecordcommit', ':call s:HgRecord_Execute()') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2190 call s:HgDiff_DiffThis(l:diff_id) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2191 setlocal foldmethod=marker |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2192 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2193 " Split the window and open the parent revision in the right or bottom |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2194 " window. Keep the current buffer in the left or top window... we're going |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2195 " to 'move' those changes into the parent revision. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2196 let l:cmd = 'keepalt rightbelow split ' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2197 if a:split == 1 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2198 let l:cmd = 'keepalt rightbelow vsplit ' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2199 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2200 let l:rev_path = l:repo.GetLawrenciumPath(expand('%'), 'rev', '') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2201 execute l:cmd . fnameescape(l:rev_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2202 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2203 " This new buffer with the parent revision is set as a Lawrencium buffer. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2204 " Let's save it to an actual file and reopen it like that (somehow we |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2205 " could probably do it with `:saveas` instead but we'd need to reset a |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2206 " bunch of other buffer settings, and Vim weirdly creates another backup |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2207 " buffer when you do that). |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2208 execute 'keepalt write! ' . fnameescape(l:tmp_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2209 execute 'keepalt edit! ' . fnameescape(l:tmp_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2210 setlocal bufhidden=delete |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2211 let b:mercurial_dir = l:repo.root_dir |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2212 let b:lawrencium_record_for = l:orig_buf.GetName(':p') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2213 let b:lawrencium_record_other_nr = l:orig_buf.nr |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2214 let b:lawrencium_record_commit_split = !a:split |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2215 call setbufvar(l:orig_buf.nr, 'lawrencium_record_for', '%') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2216 call setbufvar(l:orig_buf.nr, 'lawrencium_record_other_nr', bufnr('%')) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2217 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2218 " Hookup the commit and abort commands. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2219 let l:rec_buf = s:buffer_obj() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2220 call l:rec_buf.OnDelete('call s:HgRecord_Execute()') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2221 call l:rec_buf.DefineCommand('Hgrecordcommit', ':quit') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2222 call l:rec_buf.DefineCommand('Hgrecordabort', ':call s:HgRecord_Abort()') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2223 call s:DefineMainCommands() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2224 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2225 " Make it the other part of the diff. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2226 call s:HgDiff_DiffThis(l:diff_id) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2227 setlocal foldmethod=marker |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2228 call l:rec_buf.SetVar('&filetype', l:orig_buf.GetVar('&filetype')) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2229 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2230 if g:lawrencium_record_start_in_working_buffer |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2231 wincmd p |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2232 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2233 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2234 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2235 function! s:HgRecord_Execute() abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2236 if exists('b:lawrencium_record_abort') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2237 " Abort flag is set, let's just cleanup. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2238 let l:buf_nr = b:lawrencium_record_for == '%' ? bufnr('%') : |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2239 \b:lawrencium_record_other_nr |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2240 call s:HgRecord_CleanUp(l:buf_nr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2241 call s:error("abort: User requested aborting the record operation.") |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2242 return |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2243 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2244 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2245 if !exists('b:lawrencium_record_for') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2246 call s:throw("This doesn't seem like a record buffer, something's wrong!") |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2247 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2248 if b:lawrencium_record_for == '%' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2249 " Switch to the 'recording' buffer's window. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2250 let l:buf_obj = s:buffer_obj(b:lawrencium_record_other_nr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2251 call l:buf_obj.MoveToFirstWindow() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2252 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2253 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2254 " Setup the commit operation. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2255 let l:split = b:lawrencium_record_commit_split |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2256 let l:working_bufnr = b:lawrencium_record_other_nr |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2257 let l:working_path = fnameescape(b:lawrencium_record_for) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2258 let l:record_path = fnameescape(expand('%:p')) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2259 let l:callbacks = [ |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2260 \'call s:HgRecord_PostExecutePre('.l:working_bufnr.', "'. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2261 \escape(l:working_path, '\').'", "'. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2262 \escape(l:record_path, '\').'")', |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2263 \'call s:HgRecord_PostExecutePost('.l:working_bufnr.', "'. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2264 \escape(l:working_path, '\').'")', |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2265 \'call s:HgRecord_PostExecuteAbort('.l:working_bufnr.', "'. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2266 \escape(l:record_path, '\').'")' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2267 \] |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2268 call s:trace("Starting commit flow with callbacks: ".string(l:callbacks)) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2269 call s:HgCommit(0, l:split, l:callbacks, b:lawrencium_record_for) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2270 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2271 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2272 function! s:HgRecord_PostExecutePre(working_bufnr, working_path, record_path) abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2273 " Just before committing, we switch the original file with the record |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2274 " file... we'll restore things in the post-callback below. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2275 " We also switch on 'autoread' temporarily on the working buffer so that |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2276 " we don't have an annoying popup in gVim. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2277 if has('dialog_gui') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2278 call setbufvar(a:working_bufnr, '&autoread', 1) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2279 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2280 call s:trace("Backuping original file: ".a:working_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2281 silent call rename(a:working_path, a:working_path.'~working') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2282 call s:trace("Committing recorded changes using: ".a:record_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2283 silent call rename(a:record_path, a:working_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2284 sleep 200m |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2285 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2286 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2287 function! s:HgRecord_PostExecutePost(working_bufnr, working_path) abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2288 " Recover the back-up file from underneath the buffer. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2289 call s:trace("Recovering original file: ".a:working_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2290 silent call rename(a:working_path.'~working', a:working_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2291 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2292 " Clean up! |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2293 call s:HgRecord_CleanUp(a:working_bufnr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2294 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2295 " Restore default 'autoread'. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2296 if has('dialog_gui') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2297 set autoread< |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2298 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2299 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2300 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2301 function! s:HgRecord_PostExecuteAbort(working_bufnr, record_path) abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2302 call s:HgRecord_CleanUp(a:working_bufnr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2303 call s:trace("Delete discarded record file: ".a:record_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2304 silent call delete(a:record_path) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2305 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2306 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2307 function! s:HgRecord_Abort() abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2308 if b:lawrencium_record_for == '%' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2309 " We're in the working directory buffer. Switch to the 'recording' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2310 " buffer and quit. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2311 let l:buf_obj = s:buffer_obj(b:lawrencium_record_other_nr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2312 call l:buf_obj.MoveToFirstWindow() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2313 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2314 " We're now in the 'recording' buffer... set the abort flag and quit, |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2315 " which will run the execution (it will early out and clean things up). |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2316 let b:lawrencium_record_abort = 1 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2317 quit! |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2318 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2319 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2320 function! s:HgRecord_CleanUp(buf_nr) abort |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2321 " Get in the original buffer and clean the local commands/variables. |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2322 let l:buf_obj = s:buffer_obj(a:buf_nr) |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2323 call l:buf_obj.MoveToFirstWindow() |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2324 if !exists('b:lawrencium_record_for') || b:lawrencium_record_for != '%' |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2325 call s:throw("Cleaning up something else than the original buffer ". |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2326 \"for a record operation. That's suspiciously incorrect! ". |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2327 \"Aborting.") |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2328 endif |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2329 call l:buf_obj.DeleteCommand('Hgrecordabort') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2330 call l:buf_obj.DeleteCommand('Hgrecordcommit') |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2331 unlet b:lawrencium_record_for |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2332 unlet b:lawrencium_record_other_nr |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2333 endfunction |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2334 |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2335 call s:AddMainCommand("Hgrecord call s:HgRecord(0)") |
497f7a481599
Added new `Hgrecord` command.
Ludovic Chabant <ludovic@chabant.com>
parents:
107
diff
changeset
|
2336 call s:AddMainCommand("Hgvrecord call s:HgRecord(1)") |
71 | 2337 |
2338 " }}} | |
2339 | |
0 | 2340 " Autoload Functions {{{ |
2341 | |
2342 " Prints a summary of the current repo (if any) that's appropriate for | |
2343 " displaying on the status line. | |
2344 function! lawrencium#statusline(...) | |
2345 if !exists('b:mercurial_dir') | |
2346 return '' | |
2347 endif | |
83
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2348 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
|
2349 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
|
2350 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
|
2351 let l:branch = 'default' |
83
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2352 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
|
2353 if filereadable(l:branch_file) |
35d097b9513c
Fixed a bug with the status line indicator.
Ludovic Chabant <ludovic@chabant.com>
parents:
28
diff
changeset
|
2354 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
|
2355 endif |
83
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2356 let l:bookmarks = '' |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2357 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
|
2358 if filereadable(l:bookmarks_file) |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2359 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
|
2360 endif |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2361 let l:line = l:prefix . l:branch |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2362 if strlen(l:bookmarks) > 0 |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2363 let l:line = l:line . ' - ' . l:bookmarks |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2364 endif |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2365 let l:line = l:line . l:suffix |
a383a816d975
Adding bookmark information to the status line.
Ludovic Chabant <ludovic@chabant.com>
parents:
82
diff
changeset
|
2366 return l:line |
0 | 2367 endfunction |
2368 | |
2369 " Rescans the current buffer for setting up Mercurial commands. | |
2370 " Passing '1' as the parameter enables debug traces temporarily. | |
2371 function! lawrencium#rescan(...) | |
2372 if exists('b:mercurial_dir') | |
2373 unlet b:mercurial_dir | |
2374 endif | |
2375 if a:0 && a:1 | |
2376 let l:trace_backup = g:lawrencium_trace | |
2377 let g:lawrencium_trace = 1 | |
2378 endif | |
2379 call s:setup_buffer_commands() | |
2380 if a:0 && a:1 | |
2381 let g:lawrencium_trace = l:trace_backup | |
2382 endif | |
2383 endfunction | |
2384 | |
2385 " Enables/disables the debug trace. | |
2386 function! lawrencium#debugtrace(...) | |
2387 let g:lawrencium_trace = (a:0 == 0 || (a:0 && a:1)) | |
2388 echom "Lawrencium debug trace is now " . (g:lawrencium_trace ? "enabled." : "disabled.") | |
2389 endfunction | |
2390 | |
2391 " }}} | |
2392 |