Show More
This diff has been collapsed as it changes many lines, (721 lines changed) Show them Hide them | |||
@@ -1,1265 +1,1984 b'' | |||
|
1 | 1 | " vim600: set foldmethod=marker: |
|
2 | 2 | " |
|
3 | 3 | " Vim plugin to assist in working with HG-controlled files. |
|
4 | 4 | " |
|
5 | 5 | " Last Change: 2006/02/22 |
|
6 | 6 | " Version: 1.76 |
|
7 | 7 | " Maintainer: Mathieu Clabaut <mathieu.clabaut@gmail.com> |
|
8 | 8 | " License: This file is placed in the public domain. |
|
9 | 9 | " Credits: {{{1 |
|
10 | 10 | " Bob Hiestand <bob.hiestand@gmail.com> for the fabulous |
|
11 | 11 | " cvscommand.vim from which this script was directly created by |
|
12 | 12 | " means of sed commands and minor tweaks. |
|
13 | 13 | |
|
14 | " Section: Documentation {{{1 | |
|
14 | """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
|
15 | " | |
|
16 | " Section: Documentation | |
|
17 | "---------------------------- | |
|
18 | " | |
|
19 | " Documentation should be available by ":help hgcommand" command, once the | |
|
20 | " script has been copied in you .vim/plugin directory. | |
|
21 | " | |
|
22 | " You still can read the documentation at the end of this file. Locate it by | |
|
23 | " searching the "hgcommand-contents" string (and set ft=help to have | |
|
24 | " appropriate syntaxic coloration). | |
|
25 | " | |
|
26 | " Section: Documentation : detail {{{1 | |
|
15 | 27 | " |
|
16 | 28 | " Provides functions to invoke various HG commands on the current file |
|
17 | 29 | " (either the current buffer, or, in the case of an directory buffer, the file |
|
18 | 30 | " on the current line). The output of the commands is captured in a new |
|
19 | 31 | " scratch window. For convenience, if the functions are invoked on a HG |
|
20 | 32 | " output window, the original file is used for the hg operation instead after |
|
21 | 33 | " the window is split. This is primarily useful when running HGCommit and |
|
22 | 34 | " you need to see the changes made, so that HGDiff is usable and shows up in |
|
23 | 35 | " another window. |
|
24 | 36 | " |
|
25 | 37 | " Command documentation {{{2 |
|
26 | 38 | " |
|
27 | 39 | " HGAdd Performs "hg add" on the current file. |
|
28 | 40 | " |
|
29 | 41 | " HGAnnotate Performs "hg annotate" on the current file. If an |
|
30 | 42 | " argument is given, the argument is used as a revision |
|
31 | 43 | " number to display. If not given an argument, it uses the |
|
32 | 44 | " most recent version of the file on the current branch. |
|
33 | 45 | " Additionally, if the current buffer is a HGAnnotate buffer |
|
34 | 46 | " already, the version number on the current line is used. |
|
35 | 47 | " |
|
36 | 48 | " If the 'HGCommandAnnotateParent' variable is set to a |
|
37 | 49 | " non-zero value, the version previous to the one on the |
|
38 | 50 | " current line is used instead. This allows one to navigate |
|
39 | 51 | " back to examine the previous version of a line. |
|
40 | 52 | " |
|
41 | 53 | " HGCommit[!] If called with arguments, this performs "hg commit" using |
|
42 | 54 | " the arguments as the log message. |
|
43 | 55 | " |
|
44 | 56 | " If '!' is used, an empty log message is committed. |
|
45 | 57 | " |
|
46 | 58 | " If called with no arguments, this is a two-step command. |
|
47 | 59 | " The first step opens a buffer to accept a log message. |
|
48 | 60 | " When that buffer is written, it is automatically closed and |
|
49 | 61 | " the file is committed using the information from that log |
|
50 | 62 | " message. The commit can be abandoned if the log message |
|
51 | 63 | " buffer is deleted or wiped before being written. |
|
52 | 64 | " |
|
53 | 65 | " HGDiff With no arguments, this performs "hg diff" on the current |
|
54 | 66 | " file. With one argument, "hg diff" is performed on the |
|
55 | 67 | " current file against the specified revision. With two |
|
56 | 68 | " arguments, hg diff is performed between the specified |
|
57 | 69 | " revisions of the current file. This command uses the |
|
58 | 70 | " 'HGCommandDiffOpt' variable to specify diff options. If |
|
59 | 71 | " that variable does not exist, then 'wbBc' is assumed. If |
|
60 | 72 | " you wish to have no options, then set it to the empty |
|
61 | 73 | " string. |
|
62 | 74 | " |
|
63 | 75 | " HGGotoOriginal Returns the current window to the source buffer if the |
|
64 | 76 | " current buffer is a HG output buffer. |
|
65 | 77 | " |
|
66 | 78 | " HGLog Performs "hg log" on the current file. |
|
67 | 79 | " |
|
68 | 80 | " HGRevert Replaces the modified version of the current file with the |
|
69 | 81 | " most recent version from the repository. |
|
70 | 82 | " |
|
71 | 83 | " HGReview Retrieves a particular version of the current file. If no |
|
72 | 84 | " argument is given, the most recent version of the file on |
|
73 | 85 | " the current branch is retrieved. The specified revision is |
|
74 | 86 | " retrieved into a new buffer. |
|
75 | 87 | " |
|
76 | 88 | " HGStatus Performs "hg status" on the current file. |
|
77 | 89 | " |
|
78 | 90 | " HGUpdate Performs "hg update" on the current file. |
|
79 | 91 | " |
|
80 | 92 | " HGVimDiff With no arguments, this prompts the user for a revision and |
|
81 | 93 | " then uses vimdiff to display the differences between the |
|
82 | 94 | " current file and the specified revision. If no revision is |
|
83 | 95 | " specified, the most recent version of the file on the |
|
84 | 96 | " current branch is used. With one argument, that argument |
|
85 | 97 | " is used as the revision as above. With two arguments, the |
|
86 | 98 | " differences between the two revisions is displayed using |
|
87 | 99 | " vimdiff. |
|
88 | 100 | " |
|
89 | 101 | " With either zero or one argument, the original buffer is used |
|
90 | 102 | " to perform the vimdiff. When the other buffer is closed, the |
|
91 | 103 | " original buffer will be returned to normal mode. |
|
92 | 104 | " |
|
93 | 105 | " Once vimdiff mode is started using the above methods, |
|
94 | 106 | " additional vimdiff buffers may be added by passing a single |
|
95 | 107 | " version argument to the command. There may be up to 4 |
|
96 | 108 | " vimdiff buffers total. |
|
97 | 109 | " |
|
98 | 110 | " Using the 2-argument form of the command resets the vimdiff |
|
99 | 111 | " to only those 2 versions. Additionally, invoking the |
|
100 | 112 | " command on a different file will close the previous vimdiff |
|
101 | 113 | " buffers. |
|
102 | 114 | " |
|
103 | 115 | " |
|
104 | 116 | " Mapping documentation: {{{2 |
|
105 | 117 | " |
|
106 | 118 | " By default, a mapping is defined for each command. User-provided mappings |
|
107 | 119 | " can be used instead by mapping to <Plug>CommandName, for instance: |
|
108 | 120 | " |
|
109 | 121 | " nnoremap ,ca <Plug>HGAdd |
|
110 | 122 | " |
|
111 | 123 | " The default mappings are as follow: |
|
112 | 124 | " |
|
113 | 125 | " <Leader>hga HGAdd |
|
114 | 126 | " <Leader>hgn HGAnnotate |
|
115 | 127 | " <Leader>hgc HGCommit |
|
116 | 128 | " <Leader>hgd HGDiff |
|
117 | 129 | " <Leader>hgg HGGotoOriginal |
|
118 | 130 | " <Leader>hgG HGGotoOriginal! |
|
119 | 131 | " <Leader>hgl HGLog |
|
120 | 132 | " <Leader>hgr HGReview |
|
121 | 133 | " <Leader>hgs HGStatus |
|
122 | 134 | " <Leader>hgu HGUpdate |
|
123 | 135 | " <Leader>hgv HGVimDiff |
|
124 | 136 | " |
|
125 | 137 | " Options documentation: {{{2 |
|
126 | 138 | " |
|
127 | 139 | " Several variables are checked by the script to determine behavior as follow: |
|
128 | 140 | " |
|
129 | 141 | " HGCommandAnnotateParent |
|
130 | 142 | " This variable, if set to a non-zero value, causes the zero-argument form |
|
131 | 143 | " of HGAnnotate when invoked on a HGAnnotate buffer to go to the version |
|
132 | 144 | " previous to that displayed on the current line. If not set, it defaults |
|
133 | 145 | " to 0. |
|
134 | 146 | " |
|
135 | 147 | " HGCommandCommitOnWrite |
|
136 | 148 | " This variable, if set to a non-zero value, causes the pending hg commit |
|
137 | 149 | " to take place immediately as soon as the log message buffer is written. |
|
138 | 150 | " If set to zero, only the HGCommit mapping will cause the pending commit |
|
139 | 151 | " to occur. If not set, it defaults to 1. |
|
140 | 152 | " |
|
141 | 153 | " HGCommandDeleteOnHide |
|
142 | 154 | " This variable, if set to a non-zero value, causes the temporary HG result |
|
143 | 155 | " buffers to automatically delete themselves when hidden. |
|
144 | 156 | " |
|
145 | 157 | " HGCommandDiffOpt |
|
146 | 158 | " This variable, if set, determines the options passed to the diff command |
|
147 | 159 | " of HG. If not set, it defaults to 'wbBc'. |
|
148 | 160 | " |
|
149 | 161 | " HGCommandDiffSplit |
|
150 | 162 | " This variable overrides the HGCommandSplit variable, but only for buffers |
|
151 | 163 | " created with HGVimDiff. |
|
152 | 164 | " |
|
153 | 165 | " HGCommandEdit |
|
154 | 166 | " This variable controls whether the original buffer is replaced ('edit') or |
|
155 | 167 | " split ('split'). If not set, it defaults to 'edit'. |
|
156 | 168 | " |
|
157 | 169 | " HGCommandEnableBufferSetup |
|
158 | 170 | " This variable, if set to a non-zero value, activates HG buffer management |
|
159 | 171 | " mode. This mode means that two buffer variables, 'HGRevision' and |
|
160 | 172 | " 'HGBranch', are set if the file is HG-controlled. This is useful for |
|
161 | 173 | " displaying version information in the status bar. |
|
162 | 174 | " |
|
163 | 175 | " HGCommandInteractive |
|
164 | 176 | " This variable, if set to a non-zero value, causes appropriate functions (for |
|
165 | 177 | " the moment, only HGReview) to query the user for a revision to use |
|
166 | 178 | " instead of the current revision if none is specified. |
|
167 | 179 | " |
|
168 | 180 | " HGCommandNameMarker |
|
169 | 181 | " This variable, if set, configures the special attention-getting characters |
|
170 | 182 | " that appear on either side of the hg buffer type in the buffer name. |
|
171 | 183 | " This has no effect unless 'HGCommandNameResultBuffers' is set to a true |
|
172 | 184 | " value. If not set, it defaults to '_'. |
|
173 | 185 | " |
|
174 | 186 | " HGCommandNameResultBuffers |
|
175 | 187 | " This variable, if set to a true value, causes the hg result buffers to be |
|
176 | 188 | " named in the old way ('<source file name> _<hg command>_'). If not set |
|
177 | 189 | " or set to a false value, the result buffer is nameless. |
|
178 | 190 | " |
|
179 | 191 | " HGCommandSplit |
|
180 | 192 | " This variable controls the orientation of the various window splits that |
|
181 | 193 | " may occur (such as with HGVimDiff, when using a HG command on a HG |
|
182 | 194 | " command buffer, or when the 'HGCommandEdit' variable is set to 'split'. |
|
183 | 195 | " If set to 'horizontal', the resulting windows will be on stacked on top of |
|
184 | 196 | " one another. If set to 'vertical', the resulting windows will be |
|
185 | 197 | " side-by-side. If not set, it defaults to 'horizontal' for all but |
|
186 | 198 | " HGVimDiff windows. |
|
187 | 199 | " |
|
188 | 200 | " Event documentation {{{2 |
|
189 | 201 | " For additional customization, hgcommand.vim uses User event autocommand |
|
190 | 202 | " hooks. Each event is in the HGCommand group, and different patterns |
|
191 | 203 | " match the various hooks. |
|
192 | 204 | " |
|
193 | 205 | " For instance, the following could be added to the vimrc to provide a 'q' |
|
194 | 206 | " mapping to quit a HG buffer: |
|
195 | 207 | " |
|
196 | 208 | " augroup HGCommand |
|
197 | 209 | " au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q :bwipeout<cr> |
|
198 | 210 | " augroup END |
|
199 | 211 | " |
|
200 | 212 | " The following hooks are available: |
|
201 | 213 | " |
|
202 | 214 | " HGBufferCreated This event is fired just after a hg command |
|
203 | 215 | " result buffer is created and filled with the |
|
204 | 216 | " result of a hg command. It is executed within |
|
205 | 217 | " the context of the new buffer. |
|
206 | 218 | " |
|
207 | 219 | " HGBufferSetup This event is fired just after HG buffer setup |
|
208 | 220 | " occurs, if enabled. |
|
209 | 221 | " |
|
210 | 222 | " HGPluginInit This event is fired when the HGCommand plugin |
|
211 | 223 | " first loads. |
|
212 | 224 | " |
|
213 | 225 | " HGPluginFinish This event is fired just after the HGCommand |
|
214 | 226 | " plugin loads. |
|
215 | 227 | " |
|
216 | 228 | " HGVimDiffFinish This event is fired just after the HGVimDiff |
|
217 | 229 | " command executes to allow customization of, |
|
218 | 230 | " for instance, window placement and focus. |
|
219 | 231 | " |
|
220 | 232 | " Section: Plugin header {{{1 |
|
221 | 233 | |
|
222 | 234 | " loaded_hgcommand is set to 1 when the initialization begins, and 2 when it |
|
223 | 235 | " completes. This allows various actions to only be taken by functions after |
|
224 | 236 | " system initialization. |
|
225 | 237 | |
|
226 | 238 | if exists("loaded_hgcommand") |
|
227 | 239 | finish |
|
228 | 240 | endif |
|
229 | 241 | let loaded_hgcommand = 1 |
|
230 | 242 | |
|
231 | 243 | if v:version < 602 |
|
232 | 244 | echohl WarningMsg|echomsg "HGCommand 1.69 or later requires VIM 6.2 or later"|echohl None |
|
233 | 245 | finish |
|
234 | 246 | endif |
|
235 | 247 | |
|
236 | 248 | " Section: Event group setup {{{1 |
|
237 | 249 | |
|
238 | 250 | augroup HGCommand |
|
239 | 251 | augroup END |
|
240 | 252 | |
|
241 | 253 | " Section: Plugin initialization {{{1 |
|
242 | 254 | silent do HGCommand User HGPluginInit |
|
243 | 255 | |
|
244 | 256 | " Section: Script variable initialization {{{1 |
|
245 | 257 | |
|
246 | 258 | let s:HGCommandEditFileRunning = 0 |
|
247 | 259 | unlet! s:vimDiffRestoreCmd |
|
248 | 260 | unlet! s:vimDiffSourceBuffer |
|
249 | 261 | unlet! s:vimDiffBufferCount |
|
250 | 262 | unlet! s:vimDiffScratchList |
|
251 | 263 | |
|
252 | 264 | " Section: Utility functions {{{1 |
|
253 | 265 | |
|
254 | 266 | " Function: s:HGResolveLink() {{{2 |
|
255 | 267 | " Fully resolve the given file name to remove shortcuts or symbolic links. |
|
256 | 268 | |
|
257 | 269 | function! s:HGResolveLink(fileName) |
|
258 | 270 | let resolved = resolve(a:fileName) |
|
259 | 271 | if resolved != a:fileName |
|
260 | 272 | let resolved = s:HGResolveLink(resolved) |
|
261 | 273 | endif |
|
262 | 274 | return resolved |
|
263 | 275 | endfunction |
|
264 | 276 | |
|
265 | 277 | " Function: s:HGChangeToCurrentFileDir() {{{2 |
|
266 | 278 | " Go to the directory in which the current HG-controlled file is located. |
|
267 | 279 | " If this is a HG command buffer, first switch to the original file. |
|
268 | 280 | |
|
269 | 281 | function! s:HGChangeToCurrentFileDir(fileName) |
|
270 | 282 | let oldCwd=getcwd() |
|
271 | 283 | let fileName=s:HGResolveLink(a:fileName) |
|
272 | 284 | let newCwd=fnamemodify(fileName, ':h') |
|
273 | 285 | if strlen(newCwd) > 0 |
|
274 | 286 | execute 'cd' escape(newCwd, ' ') |
|
275 | 287 | endif |
|
276 | 288 | return oldCwd |
|
277 | 289 | endfunction |
|
278 | 290 | |
|
279 | 291 | " Function: s:HGGetOption(name, default) {{{2 |
|
280 | 292 | " Grab a user-specified option to override the default provided. Options are |
|
281 | 293 | " searched in the window, buffer, then global spaces. |
|
282 | 294 | |
|
283 | 295 | function! s:HGGetOption(name, default) |
|
284 | 296 | if exists("s:" . a:name . "Override") |
|
285 | 297 | execute "return s:".a:name."Override" |
|
286 | 298 | elseif exists("w:" . a:name) |
|
287 | 299 | execute "return w:".a:name |
|
288 | 300 | elseif exists("b:" . a:name) |
|
289 | 301 | execute "return b:".a:name |
|
290 | 302 | elseif exists("g:" . a:name) |
|
291 | 303 | execute "return g:".a:name |
|
292 | 304 | else |
|
293 | 305 | return a:default |
|
294 | 306 | endif |
|
295 | 307 | endfunction |
|
296 | 308 | |
|
297 | 309 | " Function: s:HGEditFile(name, origBuffNR) {{{2 |
|
298 | 310 | " Wrapper around the 'edit' command to provide some helpful error text if the |
|
299 | 311 | " current buffer can't be abandoned. If name is provided, it is used; |
|
300 | 312 | " otherwise, a nameless scratch buffer is used. |
|
301 | 313 | " Returns: 0 if successful, -1 if an error occurs. |
|
302 | 314 | |
|
303 | 315 | function! s:HGEditFile(name, origBuffNR) |
|
304 | 316 | "Name parameter will be pasted into expression. |
|
305 | 317 | let name = escape(a:name, ' *?\') |
|
306 | 318 | |
|
307 | 319 | let editCommand = s:HGGetOption('HGCommandEdit', 'edit') |
|
308 | 320 | if editCommand != 'edit' |
|
309 | 321 | if s:HGGetOption('HGCommandSplit', 'horizontal') == 'horizontal' |
|
310 | 322 | if name == "" |
|
311 | 323 | let editCommand = 'rightbelow new' |
|
312 | 324 | else |
|
313 | 325 | let editCommand = 'rightbelow split ' . name |
|
314 | 326 | endif |
|
315 | 327 | else |
|
316 | 328 | if name == "" |
|
317 | 329 | let editCommand = 'vert rightbelow new' |
|
318 | 330 | else |
|
319 | 331 | let editCommand = 'vert rightbelow split ' . name |
|
320 | 332 | endif |
|
321 | 333 | endif |
|
322 | 334 | else |
|
323 | 335 | if name == "" |
|
324 | 336 | let editCommand = 'enew' |
|
325 | 337 | else |
|
326 | 338 | let editCommand = 'edit ' . name |
|
327 | 339 | endif |
|
328 | 340 | endif |
|
329 | 341 | |
|
330 | 342 | " Protect against useless buffer set-up |
|
331 | 343 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1 |
|
332 | 344 | try |
|
333 | 345 | execute editCommand |
|
334 | 346 | finally |
|
335 | 347 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1 |
|
336 | 348 | endtry |
|
337 | 349 | |
|
338 | 350 | let b:HGOrigBuffNR=a:origBuffNR |
|
339 | 351 | let b:HGCommandEdit='split' |
|
340 | 352 | endfunction |
|
341 | 353 | |
|
342 | 354 | " Function: s:HGCreateCommandBuffer(cmd, cmdName, statusText, filename) {{{2 |
|
343 | 355 | " Creates a new scratch buffer and captures the output from execution of the |
|
344 | 356 | " given command. The name of the scratch buffer is returned. |
|
345 | 357 | |
|
346 | 358 | function! s:HGCreateCommandBuffer(cmd, cmdName, statusText, origBuffNR) |
|
347 | 359 | let fileName=bufname(a:origBuffNR) |
|
348 | 360 | |
|
349 | 361 | let resultBufferName='' |
|
350 | 362 | |
|
351 | 363 | if s:HGGetOption("HGCommandNameResultBuffers", 0) |
|
352 | 364 | let nameMarker = s:HGGetOption("HGCommandNameMarker", '_') |
|
353 | 365 | if strlen(a:statusText) > 0 |
|
354 | 366 | let bufName=a:cmdName . ' -- ' . a:statusText |
|
355 | 367 | else |
|
356 | 368 | let bufName=a:cmdName |
|
357 | 369 | endif |
|
358 | 370 | let bufName=fileName . ' ' . nameMarker . bufName . nameMarker |
|
359 | 371 | let counter=0 |
|
360 | 372 | let resultBufferName = bufName |
|
361 | 373 | while buflisted(resultBufferName) |
|
362 | 374 | let counter=counter + 1 |
|
363 | 375 | let resultBufferName=bufName . ' (' . counter . ')' |
|
364 | 376 | endwhile |
|
365 | 377 | endif |
|
366 | 378 | |
|
367 | 379 | let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " " . a:cmd |
|
368 | 380 | echomsg "DBG :".hgCommand |
|
369 | 381 | let hgOut = system(hgCommand) |
|
370 | 382 | " HACK: diff command does not return proper error codes |
|
371 | 383 | if v:shell_error && a:cmdName != 'hgdiff' |
|
372 | 384 | if strlen(hgOut) == 0 |
|
373 | 385 | echoerr "HG command failed" |
|
374 | 386 | else |
|
375 | 387 | echoerr "HG command failed: " . hgOut |
|
376 | 388 | endif |
|
377 | 389 | return -1 |
|
378 | 390 | endif |
|
379 | 391 | if strlen(hgOut) == 0 |
|
380 | 392 | " Handle case of no output. In this case, it is important to check the |
|
381 | 393 | " file status, especially since hg edit/unedit may change the attributes |
|
382 | 394 | " of the file with no visible output. |
|
383 | 395 | |
|
384 | 396 | echomsg "No output from HG command" |
|
385 | 397 | checktime |
|
386 | 398 | return -1 |
|
387 | 399 | endif |
|
388 | 400 | |
|
389 | 401 | if s:HGEditFile(resultBufferName, a:origBuffNR) == -1 |
|
390 | 402 | return -1 |
|
391 | 403 | endif |
|
392 | 404 | |
|
393 | 405 | set buftype=nofile |
|
394 | 406 | set noswapfile |
|
395 | 407 | set filetype= |
|
396 | 408 | |
|
397 | 409 | if s:HGGetOption("HGCommandDeleteOnHide", 0) |
|
398 | 410 | set bufhidden=delete |
|
399 | 411 | endif |
|
400 | 412 | |
|
401 | 413 | silent 0put=hgOut |
|
402 | 414 | |
|
403 | 415 | " The last command left a blank line at the end of the buffer. If the |
|
404 | 416 | " last line is folded (a side effect of the 'put') then the attempt to |
|
405 | 417 | " remove the blank line will kill the last fold. |
|
406 | 418 | " |
|
407 | 419 | " This could be fixed by explicitly detecting whether the last line is |
|
408 | 420 | " within a fold, but I prefer to simply unfold the result buffer altogether. |
|
409 | 421 | |
|
410 | 422 | if has('folding') |
|
411 | 423 | normal zR |
|
412 | 424 | endif |
|
413 | 425 | |
|
414 | 426 | $d |
|
415 | 427 | 1 |
|
416 | 428 | |
|
417 | 429 | " Define the environment and execute user-defined hooks. |
|
418 | 430 | |
|
419 | 431 | let b:HGSourceFile=fileName |
|
420 | 432 | let b:HGCommand=a:cmdName |
|
421 | 433 | if a:statusText != "" |
|
422 | 434 | let b:HGStatusText=a:statusText |
|
423 | 435 | endif |
|
424 | 436 | |
|
425 | 437 | silent do HGCommand User HGBufferCreated |
|
426 | 438 | return bufnr("%") |
|
427 | 439 | endfunction |
|
428 | 440 | |
|
429 | 441 | " Function: s:HGBufferCheck(hgBuffer) {{{2 |
|
430 | 442 | " Attempts to locate the original file to which HG operations were applied |
|
431 | 443 | " for a given buffer. |
|
432 | 444 | |
|
433 | 445 | function! s:HGBufferCheck(hgBuffer) |
|
434 | 446 | let origBuffer = getbufvar(a:hgBuffer, "HGOrigBuffNR") |
|
435 | 447 | if origBuffer |
|
436 | 448 | if bufexists(origBuffer) |
|
437 | 449 | return origBuffer |
|
438 | 450 | else |
|
439 | 451 | " Original buffer no longer exists. |
|
440 | 452 | return -1 |
|
441 | 453 | endif |
|
442 | 454 | else |
|
443 | 455 | " No original buffer |
|
444 | 456 | return a:hgBuffer |
|
445 | 457 | endif |
|
446 | 458 | endfunction |
|
447 | 459 | |
|
448 | 460 | " Function: s:HGCurrentBufferCheck() {{{2 |
|
449 | 461 | " Attempts to locate the original file to which HG operations were applied |
|
450 | 462 | " for the current buffer. |
|
451 | 463 | |
|
452 | 464 | function! s:HGCurrentBufferCheck() |
|
453 | 465 | return s:HGBufferCheck(bufnr("%")) |
|
454 | 466 | endfunction |
|
455 | 467 | |
|
456 | 468 | " Function: s:HGToggleDeleteOnHide() {{{2 |
|
457 | 469 | " Toggles on and off the delete-on-hide behavior of HG buffers |
|
458 | 470 | |
|
459 | 471 | function! s:HGToggleDeleteOnHide() |
|
460 | 472 | if exists("g:HGCommandDeleteOnHide") |
|
461 | 473 | unlet g:HGCommandDeleteOnHide |
|
462 | 474 | else |
|
463 | 475 | let g:HGCommandDeleteOnHide=1 |
|
464 | 476 | endif |
|
465 | 477 | endfunction |
|
466 | 478 | |
|
467 | 479 | " Function: s:HGDoCommand(hgcmd, cmdName, statusText) {{{2 |
|
468 | 480 | " General skeleton for HG function execution. |
|
469 | 481 | " Returns: name of the new command buffer containing the command results |
|
470 | 482 | |
|
471 | 483 | function! s:HGDoCommand(cmd, cmdName, statusText) |
|
472 | 484 | let hgBufferCheck=s:HGCurrentBufferCheck() |
|
473 | 485 | if hgBufferCheck == -1 |
|
474 | 486 | echo "Original buffer no longer exists, aborting." |
|
475 | 487 | return -1 |
|
476 | 488 | endif |
|
477 | 489 | |
|
478 | 490 | let fileName=bufname(hgBufferCheck) |
|
479 | 491 | if isdirectory(fileName) |
|
480 | 492 | let fileName=fileName . "/" . getline(".") |
|
481 | 493 | endif |
|
482 | 494 | let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t') |
|
483 | 495 | let oldCwd=s:HGChangeToCurrentFileDir(fileName) |
|
484 | 496 | try |
|
485 | 497 | " TODO |
|
486 | 498 | "if !filereadable('HG/Root') |
|
487 | 499 | "throw fileName . ' is not a HG-controlled file.' |
|
488 | 500 | "endif |
|
489 | 501 | let fullCmd = a:cmd . ' "' . realFileName . '"' |
|
490 | 502 | "echomsg "DEBUG".fullCmd |
|
491 | 503 | let resultBuffer=s:HGCreateCommandBuffer(fullCmd, a:cmdName, a:statusText, hgBufferCheck) |
|
492 | 504 | return resultBuffer |
|
493 | 505 | catch |
|
494 | 506 | echoerr v:exception |
|
495 | 507 | return -1 |
|
496 | 508 | finally |
|
497 | 509 | execute 'cd' escape(oldCwd, ' ') |
|
498 | 510 | endtry |
|
499 | 511 | endfunction |
|
500 | 512 | |
|
501 | 513 | |
|
502 | 514 | " Function: s:HGGetStatusVars(revision, branch, repository) {{{2 |
|
503 | 515 | " |
|
504 | 516 | " Obtains a HG revision number and branch name. The 'revisionVar', |
|
505 | 517 | " 'branchVar'and 'repositoryVar' arguments, if non-empty, contain the names of variables to hold |
|
506 | 518 | " the corresponding results. |
|
507 | 519 | " |
|
508 | 520 | " Returns: string to be exec'd that sets the multiple return values. |
|
509 | 521 | |
|
510 | 522 | function! s:HGGetStatusVars(revisionVar, branchVar, repositoryVar) |
|
511 | 523 | let hgBufferCheck=s:HGCurrentBufferCheck() |
|
512 | 524 | if hgBufferCheck == -1 |
|
513 | 525 | return "" |
|
514 | 526 | endif |
|
515 | 527 | let fileName=bufname(hgBufferCheck) |
|
516 | 528 | let realFileName = fnamemodify(s:HGResolveLink(fileName), ':t') |
|
517 | 529 | let oldCwd=s:HGChangeToCurrentFileDir(fileName) |
|
518 | 530 | try |
|
519 | 531 | ""TODO |
|
520 | 532 | "if !filereadable('HG/Root') |
|
521 | 533 | "return "" |
|
522 | 534 | "endif |
|
523 | 535 | let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " status -mardui " . fileName |
|
524 | 536 | let statustext=system(hgCommand) |
|
525 | 537 | if(v:shell_error) |
|
526 | 538 | return "" |
|
527 | 539 | endif |
|
528 | 540 | if match(statustext, '^[?I]') >= 0 |
|
529 | 541 | let revision="NEW" |
|
530 | 542 | elseif match(statustext, '^[R]') >= 0 |
|
531 | 543 | let revision="REMOVED" |
|
532 | 544 | elseif match(statustext, '^[D]') >= 0 |
|
533 | 545 | let revision="DELETED" |
|
534 | 546 | elseif match(statustext, '^[A]') >= 0 |
|
535 | 547 | let revision="ADDED" |
|
536 | 548 | endif |
|
537 | 549 | |
|
538 | 550 | let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b " |
|
539 | 551 | let statustext=system(hgCommand) |
|
540 | 552 | if(v:shell_error) |
|
541 | 553 | return "" |
|
542 | 554 | endif |
|
543 | 555 | if exists('revision') |
|
544 | 556 | let returnExpression = "let " . a:revisionVar . "='" . revision . "'" |
|
545 | 557 | else |
|
546 | 558 | let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "") |
|
547 | 559 | let returnExpression = "let " . a:revisionVar . "='" . revision . "'" |
|
548 | 560 | endif |
|
549 | 561 | |
|
550 | 562 | if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0 |
|
551 | 563 | let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "") |
|
552 | 564 | let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'" |
|
553 | 565 | endif |
|
554 | 566 | if a:repositoryVar != "" |
|
555 | 567 | let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " root " |
|
556 | 568 | let roottext=system(hgCommand) |
|
557 | 569 | let repository=substitute(roottext,'^.*/\([^/\n\r]*\)\n\_.*$','\1','') |
|
558 | 570 | let returnExpression=returnExpression . " | let " . a:repositoryVar . "='" . repository . "'" |
|
559 | 571 | endif |
|
560 | 572 | |
|
561 | 573 | |
|
562 | 574 | |
|
563 | 575 | return returnExpression |
|
564 | 576 | finally |
|
565 | 577 | execute 'cd' escape(oldCwd, ' ') |
|
566 | 578 | endtry |
|
567 | 579 | endfunction |
|
568 | 580 | |
|
569 | 581 | " Function: s:HGSetupBuffer() {{{2 |
|
570 | 582 | " Attempts to set the b:HGBranch, b:HGRevision and b:HGRepository variables. |
|
571 | 583 | |
|
572 | 584 | function! s:HGSetupBuffer() |
|
573 | 585 | if (exists("b:HGBufferSetup") && b:HGBufferSetup) |
|
574 | 586 | " This buffer is already set up. |
|
575 | 587 | return |
|
576 | 588 | endif |
|
577 | 589 | |
|
578 | 590 | if !s:HGGetOption("HGCommandEnableBufferSetup", 0) |
|
579 | 591 | \ || @% == "" |
|
580 | 592 | \ || s:HGCommandEditFileRunning > 0 |
|
581 | 593 | \ || exists("b:HGOrigBuffNR") |
|
582 | 594 | unlet! b:HGRevision |
|
583 | 595 | unlet! b:HGBranch |
|
584 | 596 | unlet! b:HGRepository |
|
585 | 597 | return |
|
586 | 598 | endif |
|
587 | 599 | |
|
588 | 600 | if !filereadable(expand("%")) |
|
589 | 601 | return -1 |
|
590 | 602 | endif |
|
591 | 603 | |
|
592 | 604 | let revision="" |
|
593 | 605 | let branch="" |
|
594 | 606 | let repository="" |
|
595 | 607 | |
|
596 | 608 | exec s:HGGetStatusVars('revision', 'branch', 'repository') |
|
597 | 609 | "echomsg "DBG ".revision."#".branch."#".repository |
|
598 | 610 | if revision != "" |
|
599 | 611 | let b:HGRevision=revision |
|
600 | 612 | else |
|
601 | 613 | unlet! b:HGRevision |
|
602 | 614 | endif |
|
603 | 615 | if branch != "" |
|
604 | 616 | let b:HGBranch=branch |
|
605 | 617 | else |
|
606 | 618 | unlet! b:HGBranch |
|
607 | 619 | endif |
|
608 | 620 | if repository != "" |
|
609 | 621 | let b:HGRepository=repository |
|
610 | 622 | else |
|
611 | 623 | unlet! b:HGRepository |
|
612 | 624 | endif |
|
613 | 625 | silent do HGCommand User HGBufferSetup |
|
614 | 626 | let b:HGBufferSetup=1 |
|
615 | 627 | endfunction |
|
616 | 628 | |
|
617 | 629 | " Function: s:HGMarkOrigBufferForSetup(hgbuffer) {{{2 |
|
618 | 630 | " Resets the buffer setup state of the original buffer for a given HG buffer. |
|
619 | 631 | " Returns: The HG buffer number in a passthrough mode. |
|
620 | 632 | |
|
621 | 633 | function! s:HGMarkOrigBufferForSetup(hgBuffer) |
|
622 | 634 | checktime |
|
623 | 635 | if a:hgBuffer != -1 |
|
624 | 636 | let origBuffer = s:HGBufferCheck(a:hgBuffer) |
|
625 | 637 | "This should never not work, but I'm paranoid |
|
626 | 638 | if origBuffer != a:hgBuffer |
|
627 | 639 | call setbufvar(origBuffer, "HGBufferSetup", 0) |
|
628 | 640 | endif |
|
629 | 641 | endif |
|
630 | 642 | return a:hgBuffer |
|
631 | 643 | endfunction |
|
632 | 644 | |
|
633 | 645 | " Function: s:HGOverrideOption(option, [value]) {{{2 |
|
634 | 646 | " Provides a temporary override for the given HG option. If no value is |
|
635 | 647 | " passed, the override is disabled. |
|
636 | 648 | |
|
637 | 649 | function! s:HGOverrideOption(option, ...) |
|
638 | 650 | if a:0 == 0 |
|
639 | 651 | unlet! s:{a:option}Override |
|
640 | 652 | else |
|
641 | 653 | let s:{a:option}Override = a:1 |
|
642 | 654 | endif |
|
643 | 655 | endfunction |
|
644 | 656 | |
|
645 | 657 | " Function: s:HGWipeoutCommandBuffers() {{{2 |
|
646 | 658 | " Clears all current HG buffers of the specified type for a given source. |
|
647 | 659 | |
|
648 | 660 | function! s:HGWipeoutCommandBuffers(originalBuffer, hgCommand) |
|
649 | 661 | let buffer = 1 |
|
650 | 662 | while buffer <= bufnr('$') |
|
651 | 663 | if getbufvar(buffer, 'HGOrigBuffNR') == a:originalBuffer |
|
652 | 664 | if getbufvar(buffer, 'HGCommand') == a:hgCommand |
|
653 | 665 | execute 'bw' buffer |
|
654 | 666 | endif |
|
655 | 667 | endif |
|
656 | 668 | let buffer = buffer + 1 |
|
657 | 669 | endwhile |
|
658 | 670 | endfunction |
|
659 | 671 | |
|
672 | " Function: s:HGInstallDocumentation(full_name, revision) {{{2 | |
|
673 | " Install help documentation. | |
|
674 | " Arguments: | |
|
675 | " full_name: Full name of this vim plugin script, including path name. | |
|
676 | " revision: Revision of the vim script. #version# mark in the document file | |
|
677 | " will be replaced with this string with 'v' prefix. | |
|
678 | " Return: | |
|
679 | " 1 if new document installed, 0 otherwise. | |
|
680 | " Note: Cleaned and generalized by guo-peng Wen | |
|
681 | "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | |
|
682 | ||
|
683 | function! s:HGInstallDocumentation(full_name, revision) | |
|
684 | " Name of the document path based on the system we use: | |
|
685 | if (has("unix")) | |
|
686 | " On UNIX like system, using forward slash: | |
|
687 | let l:slash_char = '/' | |
|
688 | let l:mkdir_cmd = ':silent !mkdir -p ' | |
|
689 | else | |
|
690 | " On M$ system, use backslash. Also mkdir syntax is different. | |
|
691 | " This should only work on W2K and up. | |
|
692 | let l:slash_char = '\' | |
|
693 | let l:mkdir_cmd = ':silent !mkdir ' | |
|
694 | endif | |
|
695 | ||
|
696 | let l:doc_path = l:slash_char . 'doc' | |
|
697 | let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc' | |
|
698 | ||
|
699 | " Figure out document path based on full name of this script: | |
|
700 | let l:vim_plugin_path = fnamemodify(a:full_name, ':h') | |
|
701 | let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path | |
|
702 | if (!(filewritable(l:vim_doc_path) == 2)) | |
|
703 | echomsg "Doc path: " . l:vim_doc_path | |
|
704 | execute l:mkdir_cmd . '"' . l:vim_doc_path . '"' | |
|
705 | if (!(filewritable(l:vim_doc_path) == 2)) | |
|
706 | " Try a default configuration in user home: | |
|
707 | let l:vim_doc_path = expand("~") . l:doc_home | |
|
708 | if (!(filewritable(l:vim_doc_path) == 2)) | |
|
709 | execute l:mkdir_cmd . '"' . l:vim_doc_path . '"' | |
|
710 | if (!(filewritable(l:vim_doc_path) == 2)) | |
|
711 | " Put a warning: | |
|
712 | echomsg "Unable to open documentation directory" | |
|
713 | echomsg " type :help add-local-help for more informations." | |
|
714 | return 0 | |
|
715 | endif | |
|
716 | endif | |
|
717 | endif | |
|
718 | endif | |
|
719 | ||
|
720 | " Exit if we have problem to access the document directory: | |
|
721 | if (!isdirectory(l:vim_plugin_path) | |
|
722 | \ || !isdirectory(l:vim_doc_path) | |
|
723 | \ || filewritable(l:vim_doc_path) != 2) | |
|
724 | return 0 | |
|
725 | endif | |
|
726 | ||
|
727 | " Full name of script and documentation file: | |
|
728 | let l:script_name = fnamemodify(a:full_name, ':t') | |
|
729 | let l:doc_name = fnamemodify(a:full_name, ':t:r') . '.txt' | |
|
730 | let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name | |
|
731 | let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name | |
|
732 | ||
|
733 | " Bail out if document file is still up to date: | |
|
734 | if (filereadable(l:doc_file) && | |
|
735 | \ getftime(l:plugin_file) < getftime(l:doc_file)) | |
|
736 | return 0 | |
|
737 | endif | |
|
738 | ||
|
739 | " Prepare window position restoring command: | |
|
740 | if (strlen(@%)) | |
|
741 | let l:go_back = 'b ' . bufnr("%") | |
|
742 | else | |
|
743 | let l:go_back = 'enew!' | |
|
744 | endif | |
|
745 | ||
|
746 | " Create a new buffer & read in the plugin file (me): | |
|
747 | setl nomodeline | |
|
748 | exe 'enew!' | |
|
749 | exe 'r ' . l:plugin_file | |
|
750 | ||
|
751 | setl modeline | |
|
752 | let l:buf = bufnr("%") | |
|
753 | setl noswapfile modifiable | |
|
754 | ||
|
755 | norm zR | |
|
756 | norm gg | |
|
757 | ||
|
758 | " Delete from first line to a line starts with | |
|
759 | " === START_DOC | |
|
760 | 1,/^=\{3,}\s\+START_DOC\C/ d | |
|
761 | ||
|
762 | " Delete from a line starts with | |
|
763 | " === END_DOC | |
|
764 | " to the end of the documents: | |
|
765 | /^=\{3,}\s\+END_DOC\C/,$ d | |
|
766 | ||
|
767 | " Remove fold marks: | |
|
768 | %s/{\{3}[1-9]/ / | |
|
769 | ||
|
770 | " Add modeline for help doc: the modeline string is mangled intentionally | |
|
771 | " to avoid it be recognized by VIM: | |
|
772 | call append(line('$'), '') | |
|
773 | call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:') | |
|
774 | ||
|
775 | " Replace revision: | |
|
776 | exe "normal :1s/#version#/ v" . a:revision . "/\<CR>" | |
|
777 | ||
|
778 | " Save the help document: | |
|
779 | exe 'w! ' . l:doc_file | |
|
780 | exe l:go_back | |
|
781 | exe 'bw ' . l:buf | |
|
782 | ||
|
783 | " Build help tags: | |
|
784 | exe 'helptags ' . l:vim_doc_path | |
|
785 | ||
|
786 | return 1 | |
|
787 | endfunction | |
|
788 | ||
|
660 | 789 | " Section: Public functions {{{1 |
|
661 | 790 | |
|
662 | 791 | " Function: HGGetRevision() {{{2 |
|
663 | 792 | " Global function for retrieving the current buffer's HG revision number. |
|
664 | 793 | " Returns: Revision number or an empty string if an error occurs. |
|
665 | 794 | |
|
666 | 795 | function! HGGetRevision() |
|
667 | 796 | let revision="" |
|
668 | 797 | exec s:HGGetStatusVars('revision', '', '') |
|
669 | 798 | return revision |
|
670 | 799 | endfunction |
|
671 | 800 | |
|
672 | 801 | " Function: HGDisableBufferSetup() {{{2 |
|
673 | 802 | " Global function for deactivating the buffer autovariables. |
|
674 | 803 | |
|
675 | 804 | function! HGDisableBufferSetup() |
|
676 | 805 | let g:HGCommandEnableBufferSetup=0 |
|
677 | 806 | silent! augroup! HGCommandPlugin |
|
678 | 807 | endfunction |
|
679 | 808 | |
|
680 | 809 | " Function: HGEnableBufferSetup() {{{2 |
|
681 | 810 | " Global function for activating the buffer autovariables. |
|
682 | 811 | |
|
683 | 812 | function! HGEnableBufferSetup() |
|
684 | 813 | let g:HGCommandEnableBufferSetup=1 |
|
685 | 814 | augroup HGCommandPlugin |
|
686 | 815 | au! |
|
687 | 816 | au BufEnter * call s:HGSetupBuffer() |
|
688 | 817 | augroup END |
|
689 | 818 | |
|
690 | 819 | " Only auto-load if the plugin is fully loaded. This gives other plugins a |
|
691 | 820 | " chance to run. |
|
692 | 821 | if g:loaded_hgcommand == 2 |
|
693 | 822 | call s:HGSetupBuffer() |
|
694 | 823 | endif |
|
695 | 824 | endfunction |
|
696 | 825 | |
|
697 | 826 | " Function: HGGetStatusLine() {{{2 |
|
698 | 827 | " Default (sample) status line entry for HG files. This is only useful if |
|
699 | 828 | " HG-managed buffer mode is on (see the HGCommandEnableBufferSetup variable |
|
700 | 829 | " for how to do this). |
|
701 | 830 | |
|
702 | 831 | function! HGGetStatusLine() |
|
703 | 832 | if exists('b:HGSourceFile') |
|
704 | 833 | " This is a result buffer |
|
705 | 834 | let value='[' . b:HGCommand . ' ' . b:HGSourceFile |
|
706 | 835 | if exists('b:HGStatusText') |
|
707 | 836 | let value=value . ' ' . b:HGStatusText |
|
708 | 837 | endif |
|
709 | 838 | let value = value . ']' |
|
710 | 839 | return value |
|
711 | 840 | endif |
|
712 | 841 | |
|
713 | 842 | if exists('b:HGRevision') |
|
714 | 843 | \ && b:HGRevision != '' |
|
715 | 844 | \ && exists('b:HGBranch') |
|
716 | 845 | \ && b:HGBranch != '' |
|
717 | 846 | \ && exists('b:HGRepository') |
|
718 | 847 | \ && b:HGRepository != '' |
|
719 | 848 | \ && exists('g:HGCommandEnableBufferSetup') |
|
720 | 849 | \ && g:HGCommandEnableBufferSetup |
|
721 | 850 | return '[HG ' . b:HGRepository . '/' . b:HGBranch .'/' . b:HGRevision . ']' |
|
722 | 851 | else |
|
723 | 852 | return '' |
|
724 | 853 | endif |
|
725 | 854 | endfunction |
|
726 | 855 | |
|
727 | 856 | " Section: HG command functions {{{1 |
|
728 | 857 | |
|
729 | 858 | " Function: s:HGAdd() {{{2 |
|
730 | 859 | function! s:HGAdd() |
|
731 | 860 | return s:HGMarkOrigBufferForSetup(s:HGDoCommand('add', 'hgadd', '')) |
|
732 | 861 | endfunction |
|
733 | 862 | |
|
734 | 863 | " Function: s:HGAnnotate(...) {{{2 |
|
735 | 864 | function! s:HGAnnotate(...) |
|
736 | 865 | if a:0 == 0 |
|
737 | 866 | if &filetype == "HGAnnotate" |
|
738 | 867 | " This is a HGAnnotate buffer. Perform annotation of the version |
|
739 | 868 | " indicated by the current line. |
|
740 | 869 | let revision = substitute(getline("."),'\(^[0-9]*\):.*','\1','') |
|
741 | 870 | if s:HGGetOption('HGCommandAnnotateParent', 0) != 0 && revision > 0 |
|
742 | 871 | let revision = revision - 1 |
|
743 | 872 | endif |
|
744 | 873 | else |
|
745 | 874 | let revision=HGGetRevision() |
|
746 | 875 | if revision == "" |
|
747 | 876 | echoerr "Unable to obtain HG version information." |
|
748 | 877 | return -1 |
|
749 | 878 | endif |
|
750 | 879 | endif |
|
751 | 880 | else |
|
752 | 881 | let revision=a:1 |
|
753 | 882 | endif |
|
754 | 883 | |
|
755 | 884 | if revision == "NEW" |
|
756 | 885 | echo "No annotatation available for new file." |
|
757 | 886 | return -1 |
|
758 | 887 | endif |
|
759 | 888 | |
|
760 | 889 | let resultBuffer=s:HGDoCommand('annotate -ndu -r ' . revision, 'hgannotate', revision) |
|
761 | 890 | echomsg "DBG: ".resultBuffer |
|
762 | 891 | if resultBuffer != -1 |
|
763 | 892 | set filetype=HGAnnotate |
|
764 | 893 | endif |
|
765 | 894 | |
|
766 | 895 | return resultBuffer |
|
767 | 896 | endfunction |
|
768 | 897 | |
|
769 | 898 | " Function: s:HGCommit() {{{2 |
|
770 | 899 | function! s:HGCommit(...) |
|
771 | 900 | " Handle the commit message being specified. If a message is supplied, it |
|
772 | 901 | " is used; if bang is supplied, an empty message is used; otherwise, the |
|
773 | 902 | " user is provided a buffer from which to edit the commit message. |
|
774 | 903 | if a:2 != "" || a:1 == "!" |
|
775 | 904 | return s:HGMarkOrigBufferForSetup(s:HGDoCommand('commit -m "' . a:2 . '"', 'hgcommit', '')) |
|
776 | 905 | endif |
|
777 | 906 | |
|
778 | 907 | let hgBufferCheck=s:HGCurrentBufferCheck() |
|
779 | 908 | if hgBufferCheck == -1 |
|
780 | 909 | echo "Original buffer no longer exists, aborting." |
|
781 | 910 | return -1 |
|
782 | 911 | endif |
|
783 | 912 | |
|
784 | 913 | " Protect against windows' backslashes in paths. They confuse exec'd |
|
785 | 914 | " commands. |
|
786 | 915 | |
|
787 | 916 | let shellSlashBak = &shellslash |
|
788 | 917 | try |
|
789 | 918 | set shellslash |
|
790 | 919 | |
|
791 | 920 | let messageFileName = tempname() |
|
792 | 921 | |
|
793 | 922 | let fileName=bufname(hgBufferCheck) |
|
794 | 923 | let realFilePath=s:HGResolveLink(fileName) |
|
795 | 924 | let newCwd=fnamemodify(realFilePath, ':h') |
|
796 | 925 | if strlen(newCwd) == 0 |
|
797 | 926 | " Account for autochdir being in effect, which will make this blank, but |
|
798 | 927 | " we know we'll be in the current directory for the original file. |
|
799 | 928 | let newCwd = getcwd() |
|
800 | 929 | endif |
|
801 | 930 | |
|
802 | 931 | let realFileName=fnamemodify(realFilePath, ':t') |
|
803 | 932 | |
|
804 | 933 | if s:HGEditFile(messageFileName, hgBufferCheck) == -1 |
|
805 | 934 | return |
|
806 | 935 | endif |
|
807 | 936 | |
|
808 | 937 | " Protect against case and backslash issues in Windows. |
|
809 | 938 | let autoPattern = '\c' . messageFileName |
|
810 | 939 | |
|
811 | 940 | " Ensure existance of group |
|
812 | 941 | augroup HGCommit |
|
813 | 942 | augroup END |
|
814 | 943 | |
|
815 | 944 | execute 'au HGCommit BufDelete' autoPattern 'call delete("' . messageFileName . '")' |
|
816 | 945 | execute 'au HGCommit BufDelete' autoPattern 'au! HGCommit * ' autoPattern |
|
817 | 946 | |
|
818 | 947 | " Create a commit mapping. The mapping must clear all autocommands in case |
|
819 | 948 | " it is invoked when HGCommandCommitOnWrite is active, as well as to not |
|
820 | 949 | " invoke the buffer deletion autocommand. |
|
821 | 950 | |
|
822 | 951 | execute 'nnoremap <silent> <buffer> <Plug>HGCommit '. |
|
823 | 952 | \ ':au! HGCommit * ' . autoPattern . '<CR>'. |
|
824 | 953 | \ ':g/^HG:/d<CR>'. |
|
825 | 954 | \ ':update<CR>'. |
|
826 | 955 | \ ':call <SID>HGFinishCommit("' . messageFileName . '",' . |
|
827 | 956 | \ '"' . newCwd . '",' . |
|
828 | 957 | \ '"' . realFileName . '",' . |
|
829 | 958 | \ hgBufferCheck . ')<CR>' |
|
830 | 959 | |
|
831 | 960 | silent 0put ='HG: ----------------------------------------------------------------------' |
|
832 | 961 | silent put =\"HG: Enter Log. Lines beginning with `HG:' are removed automatically\" |
|
833 | 962 | silent put ='HG: Type <leader>cc (or your own <Plug>HGCommit mapping)' |
|
834 | 963 | |
|
835 | 964 | if s:HGGetOption('HGCommandCommitOnWrite', 1) == 1 |
|
836 | 965 | execute 'au HGCommit BufWritePre' autoPattern 'g/^HG:/d' |
|
837 | 966 | execute 'au HGCommit BufWritePost' autoPattern 'call s:HGFinishCommit("' . messageFileName . '", "' . newCwd . '", "' . realFileName . '", ' . hgBufferCheck . ') | au! * ' autoPattern |
|
838 | 967 | silent put ='HG: or write this buffer' |
|
839 | 968 | endif |
|
840 | 969 | |
|
841 | 970 | silent put ='HG: to finish this commit operation' |
|
842 | 971 | silent put ='HG: ----------------------------------------------------------------------' |
|
843 | 972 | $ |
|
844 | 973 | let b:HGSourceFile=fileName |
|
845 | 974 | let b:HGCommand='HGCommit' |
|
846 | 975 | set filetype=hg |
|
847 | 976 | finally |
|
848 | 977 | let &shellslash = shellSlashBak |
|
849 | 978 | endtry |
|
850 | 979 | |
|
851 | 980 | endfunction |
|
852 | 981 | |
|
853 | 982 | " Function: s:HGDiff(...) {{{2 |
|
854 | 983 | function! s:HGDiff(...) |
|
855 | 984 | if a:0 == 1 |
|
856 | 985 | let revOptions = '-r' . a:1 |
|
857 | 986 | let caption = a:1 . ' -> current' |
|
858 | 987 | elseif a:0 == 2 |
|
859 | 988 | let revOptions = '-r' . a:1 . ' -r' . a:2 |
|
860 | 989 | let caption = a:1 . ' -> ' . a:2 |
|
861 | 990 | else |
|
862 | 991 | let revOptions = '' |
|
863 | 992 | let caption = '' |
|
864 | 993 | endif |
|
865 | 994 | |
|
866 | 995 | let hgdiffopt=s:HGGetOption('HGCommandDiffOpt', 'w') |
|
867 | 996 | |
|
868 | 997 | if hgdiffopt == "" |
|
869 | 998 | let diffoptionstring="" |
|
870 | 999 | else |
|
871 | 1000 | let diffoptionstring=" -" . hgdiffopt . " " |
|
872 | 1001 | endif |
|
873 | 1002 | |
|
874 | 1003 | let resultBuffer = s:HGDoCommand('diff ' . diffoptionstring . revOptions , 'hgdiff', caption) |
|
875 | 1004 | if resultBuffer != -1 |
|
876 | 1005 | set filetype=diff |
|
877 | 1006 | endif |
|
878 | 1007 | return resultBuffer |
|
879 | 1008 | endfunction |
|
880 | 1009 | |
|
881 | 1010 | |
|
882 | 1011 | " Function: s:HGGotoOriginal(["!]) {{{2 |
|
883 | 1012 | function! s:HGGotoOriginal(...) |
|
884 | 1013 | let origBuffNR = s:HGCurrentBufferCheck() |
|
885 | 1014 | if origBuffNR > 0 |
|
886 | 1015 | let origWinNR = bufwinnr(origBuffNR) |
|
887 | 1016 | if origWinNR == -1 |
|
888 | 1017 | execute 'buffer' origBuffNR |
|
889 | 1018 | else |
|
890 | 1019 | execute origWinNR . 'wincmd w' |
|
891 | 1020 | endif |
|
892 | 1021 | if a:0 == 1 |
|
893 | 1022 | if a:1 == "!" |
|
894 | 1023 | let buffnr = 1 |
|
895 | 1024 | let buffmaxnr = bufnr("$") |
|
896 | 1025 | while buffnr <= buffmaxnr |
|
897 | 1026 | if getbufvar(buffnr, "HGOrigBuffNR") == origBuffNR |
|
898 | 1027 | execute "bw" buffnr |
|
899 | 1028 | endif |
|
900 | 1029 | let buffnr = buffnr + 1 |
|
901 | 1030 | endwhile |
|
902 | 1031 | endif |
|
903 | 1032 | endif |
|
904 | 1033 | endif |
|
905 | 1034 | endfunction |
|
906 | 1035 | |
|
907 | 1036 | " Function: s:HGFinishCommit(messageFile, targetDir, targetFile) {{{2 |
|
908 | 1037 | function! s:HGFinishCommit(messageFile, targetDir, targetFile, origBuffNR) |
|
909 | 1038 | if filereadable(a:messageFile) |
|
910 | 1039 | let oldCwd=getcwd() |
|
911 | 1040 | if strlen(a:targetDir) > 0 |
|
912 | 1041 | execute 'cd' escape(a:targetDir, ' ') |
|
913 | 1042 | endif |
|
914 | 1043 | let resultBuffer=s:HGCreateCommandBuffer('commit -F "' . a:messageFile . '" "'. a:targetFile . '"', 'hgcommit', '', a:origBuffNR) |
|
915 | 1044 | execute 'cd' escape(oldCwd, ' ') |
|
916 | 1045 | execute 'bw' escape(a:messageFile, ' *?\') |
|
917 | 1046 | silent execute 'call delete("' . a:messageFile . '")' |
|
918 | 1047 | return s:HGMarkOrigBufferForSetup(resultBuffer) |
|
919 | 1048 | else |
|
920 | 1049 | echoerr "Can't read message file; no commit is possible." |
|
921 | 1050 | return -1 |
|
922 | 1051 | endif |
|
923 | 1052 | endfunction |
|
924 | 1053 | |
|
925 | 1054 | " Function: s:HGLog() {{{2 |
|
926 | 1055 | function! s:HGLog(...) |
|
927 | 1056 | if a:0 == 0 |
|
928 | 1057 | let versionOption = "" |
|
929 | 1058 | let caption = '' |
|
930 | 1059 | else |
|
931 | 1060 | let versionOption=" -r" . a:1 |
|
932 | 1061 | let caption = a:1 |
|
933 | 1062 | endif |
|
934 | 1063 | |
|
935 | 1064 | let resultBuffer=s:HGDoCommand('log' . versionOption, 'hglog', caption) |
|
936 | 1065 | if resultBuffer != "" |
|
937 | 1066 | set filetype=rcslog |
|
938 | 1067 | endif |
|
939 | 1068 | return resultBuffer |
|
940 | 1069 | endfunction |
|
941 | 1070 | |
|
942 | 1071 | " Function: s:HGRevert() {{{2 |
|
943 | 1072 | function! s:HGRevert() |
|
944 | 1073 | return s:HGMarkOrigBufferForSetup(s:HGDoCommand('revert', 'hgrevert', '')) |
|
945 | 1074 | endfunction |
|
946 | 1075 | |
|
947 | 1076 | " Function: s:HGReview(...) {{{2 |
|
948 | 1077 | function! s:HGReview(...) |
|
949 | 1078 | if a:0 == 0 |
|
950 | 1079 | let versiontag="" |
|
951 | 1080 | if s:HGGetOption('HGCommandInteractive', 0) |
|
952 | 1081 | let versiontag=input('Revision: ') |
|
953 | 1082 | endif |
|
954 | 1083 | if versiontag == "" |
|
955 | 1084 | let versiontag="(current)" |
|
956 | 1085 | let versionOption="" |
|
957 | 1086 | else |
|
958 | 1087 | let versionOption=" -r " . versiontag . " " |
|
959 | 1088 | endif |
|
960 | 1089 | else |
|
961 | 1090 | let versiontag=a:1 |
|
962 | 1091 | let versionOption=" -r " . versiontag . " " |
|
963 | 1092 | endif |
|
964 | 1093 | |
|
965 | 1094 | let resultBuffer = s:HGDoCommand('cat' . versionOption, 'hgreview', versiontag) |
|
966 | 1095 | if resultBuffer > 0 |
|
967 | 1096 | let &filetype=getbufvar(b:HGOrigBuffNR, '&filetype') |
|
968 | 1097 | endif |
|
969 | 1098 | |
|
970 | 1099 | return resultBuffer |
|
971 | 1100 | endfunction |
|
972 | 1101 | |
|
973 | 1102 | " Function: s:HGStatus() {{{2 |
|
974 | 1103 | function! s:HGStatus() |
|
975 | 1104 | return s:HGDoCommand('status', 'hgstatus', '') |
|
976 | 1105 | endfunction |
|
977 | 1106 | |
|
978 | 1107 | |
|
979 | 1108 | " Function: s:HGUpdate() {{{2 |
|
980 | 1109 | function! s:HGUpdate() |
|
981 | 1110 | return s:HGMarkOrigBufferForSetup(s:HGDoCommand('update', 'update', '')) |
|
982 | 1111 | endfunction |
|
983 | 1112 | |
|
984 | 1113 | " Function: s:HGVimDiff(...) {{{2 |
|
985 | 1114 | function! s:HGVimDiff(...) |
|
986 | 1115 | let originalBuffer = s:HGCurrentBufferCheck() |
|
987 | 1116 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1 |
|
988 | 1117 | try |
|
989 | 1118 | " If there's already a VimDiff'ed window, restore it. |
|
990 | 1119 | " There may only be one HGVimDiff original window at a time. |
|
991 | 1120 | |
|
992 | 1121 | if exists("s:vimDiffSourceBuffer") && s:vimDiffSourceBuffer != originalBuffer |
|
993 | 1122 | " Clear the existing vimdiff setup by removing the result buffers. |
|
994 | 1123 | call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff') |
|
995 | 1124 | endif |
|
996 | 1125 | |
|
997 | 1126 | " Split and diff |
|
998 | 1127 | if(a:0 == 2) |
|
999 | 1128 | " Reset the vimdiff system, as 2 explicit versions were provided. |
|
1000 | 1129 | if exists('s:vimDiffSourceBuffer') |
|
1001 | 1130 | call s:HGWipeoutCommandBuffers(s:vimDiffSourceBuffer, 'vimdiff') |
|
1002 | 1131 | endif |
|
1003 | 1132 | let resultBuffer = s:HGReview(a:1) |
|
1004 | 1133 | if resultBuffer < 0 |
|
1005 | 1134 | echomsg "Can't open HG revision " . a:1 |
|
1006 | 1135 | return resultBuffer |
|
1007 | 1136 | endif |
|
1008 | 1137 | let b:HGCommand = 'vimdiff' |
|
1009 | 1138 | diffthis |
|
1010 | 1139 | let s:vimDiffBufferCount = 1 |
|
1011 | 1140 | let s:vimDiffScratchList = '{'. resultBuffer . '}' |
|
1012 | 1141 | " If no split method is defined, cheat, and set it to vertical. |
|
1013 | 1142 | try |
|
1014 | 1143 | call s:HGOverrideOption('HGCommandSplit', s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical'))) |
|
1015 | 1144 | let resultBuffer=s:HGReview(a:2) |
|
1016 | 1145 | finally |
|
1017 | 1146 | call s:HGOverrideOption('HGCommandSplit') |
|
1018 | 1147 | endtry |
|
1019 | 1148 | if resultBuffer < 0 |
|
1020 | 1149 | echomsg "Can't open HG revision " . a:1 |
|
1021 | 1150 | return resultBuffer |
|
1022 | 1151 | endif |
|
1023 | 1152 | let b:HGCommand = 'vimdiff' |
|
1024 | 1153 | diffthis |
|
1025 | 1154 | let s:vimDiffBufferCount = 2 |
|
1026 | 1155 | let s:vimDiffScratchList = s:vimDiffScratchList . '{'. resultBuffer . '}' |
|
1027 | 1156 | else |
|
1028 | 1157 | " Add new buffer |
|
1029 | 1158 | try |
|
1030 | 1159 | " Force splitting behavior, otherwise why use vimdiff? |
|
1031 | 1160 | call s:HGOverrideOption("HGCommandEdit", "split") |
|
1032 | 1161 | call s:HGOverrideOption("HGCommandSplit", s:HGGetOption('HGCommandDiffSplit', s:HGGetOption('HGCommandSplit', 'vertical'))) |
|
1033 | 1162 | if(a:0 == 0) |
|
1034 | 1163 | let resultBuffer=s:HGReview() |
|
1035 | 1164 | else |
|
1036 | 1165 | let resultBuffer=s:HGReview(a:1) |
|
1037 | 1166 | endif |
|
1038 | 1167 | finally |
|
1039 | 1168 | call s:HGOverrideOption("HGCommandEdit") |
|
1040 | 1169 | call s:HGOverrideOption("HGCommandSplit") |
|
1041 | 1170 | endtry |
|
1042 | 1171 | if resultBuffer < 0 |
|
1043 | 1172 | echomsg "Can't open current HG revision" |
|
1044 | 1173 | return resultBuffer |
|
1045 | 1174 | endif |
|
1046 | 1175 | let b:HGCommand = 'vimdiff' |
|
1047 | 1176 | diffthis |
|
1048 | 1177 | |
|
1049 | 1178 | if !exists('s:vimDiffBufferCount') |
|
1050 | 1179 | " New instance of vimdiff. |
|
1051 | 1180 | let s:vimDiffBufferCount = 2 |
|
1052 | 1181 | let s:vimDiffScratchList = '{' . resultBuffer . '}' |
|
1053 | 1182 | |
|
1054 | 1183 | " This could have been invoked on a HG result buffer, not the |
|
1055 | 1184 | " original buffer. |
|
1056 | 1185 | wincmd W |
|
1057 | 1186 | execute 'buffer' originalBuffer |
|
1058 | 1187 | " Store info for later original buffer restore |
|
1059 | 1188 | let s:vimDiffRestoreCmd = |
|
1060 | 1189 | \ "call setbufvar(".originalBuffer.", \"&diff\", ".getbufvar(originalBuffer, '&diff').")" |
|
1061 | 1190 | \ . "|call setbufvar(".originalBuffer.", \"&foldcolumn\", ".getbufvar(originalBuffer, '&foldcolumn').")" |
|
1062 | 1191 | \ . "|call setbufvar(".originalBuffer.", \"&foldenable\", ".getbufvar(originalBuffer, '&foldenable').")" |
|
1063 | 1192 | \ . "|call setbufvar(".originalBuffer.", \"&foldmethod\", '".getbufvar(originalBuffer, '&foldmethod')."')" |
|
1064 | 1193 | \ . "|call setbufvar(".originalBuffer.", \"&scrollbind\", ".getbufvar(originalBuffer, '&scrollbind').")" |
|
1065 | 1194 | \ . "|call setbufvar(".originalBuffer.", \"&wrap\", ".getbufvar(originalBuffer, '&wrap').")" |
|
1066 | 1195 | \ . "|if &foldmethod=='manual'|execute 'normal zE'|endif" |
|
1067 | 1196 | diffthis |
|
1068 | 1197 | wincmd w |
|
1069 | 1198 | else |
|
1070 | 1199 | " Adding a window to an existing vimdiff |
|
1071 | 1200 | let s:vimDiffBufferCount = s:vimDiffBufferCount + 1 |
|
1072 | 1201 | let s:vimDiffScratchList = s:vimDiffScratchList . '{' . resultBuffer . '}' |
|
1073 | 1202 | endif |
|
1074 | 1203 | endif |
|
1075 | 1204 | |
|
1076 | 1205 | let s:vimDiffSourceBuffer = originalBuffer |
|
1077 | 1206 | |
|
1078 | 1207 | " Avoid executing the modeline in the current buffer after the autocommand. |
|
1079 | 1208 | |
|
1080 | 1209 | let currentBuffer = bufnr('%') |
|
1081 | 1210 | let saveModeline = getbufvar(currentBuffer, '&modeline') |
|
1082 | 1211 | try |
|
1083 | 1212 | call setbufvar(currentBuffer, '&modeline', 0) |
|
1084 | 1213 | silent do HGCommand User HGVimDiffFinish |
|
1085 | 1214 | finally |
|
1086 | 1215 | call setbufvar(currentBuffer, '&modeline', saveModeline) |
|
1087 | 1216 | endtry |
|
1088 | 1217 | return resultBuffer |
|
1089 | 1218 | finally |
|
1090 | 1219 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1 |
|
1091 | 1220 | endtry |
|
1092 | 1221 | endfunction |
|
1093 | 1222 | |
|
1094 | 1223 | " Section: Command definitions {{{1 |
|
1095 | 1224 | " Section: Primary commands {{{2 |
|
1096 | 1225 | com! HGAdd call s:HGAdd() |
|
1097 | 1226 | com! -nargs=? HGAnnotate call s:HGAnnotate(<f-args>) |
|
1098 | 1227 | com! -bang -nargs=? HGCommit call s:HGCommit(<q-bang>, <q-args>) |
|
1099 | 1228 | com! -nargs=* HGDiff call s:HGDiff(<f-args>) |
|
1100 | 1229 | com! -bang HGGotoOriginal call s:HGGotoOriginal(<q-bang>) |
|
1101 | 1230 | com! -nargs=? HGLog call s:HGLog(<f-args>) |
|
1102 | 1231 | com! HGRevert call s:HGRevert() |
|
1103 | 1232 | com! -nargs=? HGReview call s:HGReview(<f-args>) |
|
1104 | 1233 | com! HGStatus call s:HGStatus() |
|
1105 | 1234 | com! HGUpdate call s:HGUpdate() |
|
1106 | 1235 | com! -nargs=* HGVimDiff call s:HGVimDiff(<f-args>) |
|
1107 | 1236 | |
|
1108 | 1237 | " Section: HG buffer management commands {{{2 |
|
1109 | 1238 | com! HGDisableBufferSetup call HGDisableBufferSetup() |
|
1110 | 1239 | com! HGEnableBufferSetup call HGEnableBufferSetup() |
|
1111 | 1240 | |
|
1112 | 1241 | " Allow reloading hgcommand.vim |
|
1113 | 1242 | com! HGReload unlet! loaded_hgcommand | runtime plugin/hgcommand.vim |
|
1114 | 1243 | |
|
1115 | 1244 | " Section: Plugin command mappings {{{1 |
|
1116 | 1245 | nnoremap <silent> <Plug>HGAdd :HGAdd<CR> |
|
1117 | 1246 | nnoremap <silent> <Plug>HGAnnotate :HGAnnotate<CR> |
|
1118 | 1247 | nnoremap <silent> <Plug>HGCommit :HGCommit<CR> |
|
1119 | 1248 | nnoremap <silent> <Plug>HGDiff :HGDiff<CR> |
|
1120 | 1249 | nnoremap <silent> <Plug>HGGotoOriginal :HGGotoOriginal<CR> |
|
1121 | 1250 | nnoremap <silent> <Plug>HGClearAndGotoOriginal :HGGotoOriginal!<CR> |
|
1122 | 1251 | nnoremap <silent> <Plug>HGLog :HGLog<CR> |
|
1123 | 1252 | nnoremap <silent> <Plug>HGRevert :HGRevert<CR> |
|
1124 | 1253 | nnoremap <silent> <Plug>HGReview :HGReview<CR> |
|
1125 | 1254 | nnoremap <silent> <Plug>HGStatus :HGStatus<CR> |
|
1126 | 1255 | nnoremap <silent> <Plug>HGUpdate :HGUpdate<CR> |
|
1127 | 1256 | nnoremap <silent> <Plug>HGVimDiff :HGVimDiff<CR> |
|
1128 | 1257 | nnoremap <silent> <Plug>HGWatchers :HGWatchers<CR> |
|
1129 | 1258 | nnoremap <silent> <Plug>HGWatchAdd :HGWatchAdd<CR> |
|
1130 | 1259 | nnoremap <silent> <Plug>HGWatchOn :HGWatchOn<CR> |
|
1131 | 1260 | nnoremap <silent> <Plug>HGWatchOff :HGWatchOff<CR> |
|
1132 | 1261 | nnoremap <silent> <Plug>HGWatchRemove :HGWatchRemove<CR> |
|
1133 | 1262 | |
|
1134 | 1263 | " Section: Default mappings {{{1 |
|
1135 | 1264 | if !hasmapto('<Plug>HGAdd') |
|
1136 | 1265 | nmap <unique> <Leader>hga <Plug>HGAdd |
|
1137 | 1266 | endif |
|
1138 | 1267 | if !hasmapto('<Plug>HGAnnotate') |
|
1139 | 1268 | nmap <unique> <Leader>hgn <Plug>HGAnnotate |
|
1140 | 1269 | endif |
|
1141 | 1270 | if !hasmapto('<Plug>HGClearAndGotoOriginal') |
|
1142 | 1271 | nmap <unique> <Leader>hgG <Plug>HGClearAndGotoOriginal |
|
1143 | 1272 | endif |
|
1144 | 1273 | if !hasmapto('<Plug>HGCommit') |
|
1145 | 1274 | nmap <unique> <Leader>hgc <Plug>HGCommit |
|
1146 | 1275 | endif |
|
1147 | 1276 | if !hasmapto('<Plug>HGDiff') |
|
1148 | 1277 | nmap <unique> <Leader>hgd <Plug>HGDiff |
|
1149 | 1278 | endif |
|
1150 | 1279 | if !hasmapto('<Plug>HGGotoOriginal') |
|
1151 | 1280 | nmap <unique> <Leader>hgg <Plug>HGGotoOriginal |
|
1152 | 1281 | endif |
|
1153 | 1282 | if !hasmapto('<Plug>HGLog') |
|
1154 | 1283 | nmap <unique> <Leader>hgl <Plug>HGLog |
|
1155 | 1284 | endif |
|
1156 | 1285 | if !hasmapto('<Plug>HGRevert') |
|
1157 | 1286 | nmap <unique> <Leader>hgq <Plug>HGRevert |
|
1158 | 1287 | endif |
|
1159 | 1288 | if !hasmapto('<Plug>HGReview') |
|
1160 | 1289 | nmap <unique> <Leader>hgr <Plug>HGReview |
|
1161 | 1290 | endif |
|
1162 | 1291 | if !hasmapto('<Plug>HGStatus') |
|
1163 | 1292 | nmap <unique> <Leader>hgs <Plug>HGStatus |
|
1164 | 1293 | endif |
|
1165 | 1294 | if !hasmapto('<Plug>HGUpdate') |
|
1166 | 1295 | nmap <unique> <Leader>hgu <Plug>HGUpdate |
|
1167 | 1296 | endif |
|
1168 | 1297 | if !hasmapto('<Plug>HGVimDiff') |
|
1169 | 1298 | nmap <unique> <Leader>hgv <Plug>HGVimDiff |
|
1170 | 1299 | endif |
|
1171 | 1300 | |
|
1172 | 1301 | " Section: Menu items {{{1 |
|
1173 | 1302 | silent! aunmenu Plugin.HG |
|
1174 | 1303 | amenu <silent> &Plugin.HG.&Add <Plug>HGAdd |
|
1175 | 1304 | amenu <silent> &Plugin.HG.A&nnotate <Plug>HGAnnotate |
|
1176 | 1305 | amenu <silent> &Plugin.HG.&Commit <Plug>HGCommit |
|
1177 | 1306 | amenu <silent> &Plugin.HG.&Diff <Plug>HGDiff |
|
1178 | 1307 | amenu <silent> &Plugin.HG.&Log <Plug>HGLog |
|
1179 | 1308 | amenu <silent> &Plugin.HG.Revert <Plug>HGRevert |
|
1180 | 1309 | amenu <silent> &Plugin.HG.&Review <Plug>HGReview |
|
1181 | 1310 | amenu <silent> &Plugin.HG.&Status <Plug>HGStatus |
|
1182 | 1311 | amenu <silent> &Plugin.HG.&Update <Plug>HGUpdate |
|
1183 | 1312 | amenu <silent> &Plugin.HG.&VimDiff <Plug>HGVimDiff |
|
1184 | 1313 | amenu <silent> &Plugin.HG.&Watchers <Plug>HGWatchers |
|
1185 | 1314 | amenu <silent> &Plugin.HG.WatchAdd <Plug>HGWatchAdd |
|
1186 | 1315 | amenu <silent> &Plugin.HG.WatchOn <Plug>HGWatchOn |
|
1187 | 1316 | amenu <silent> &Plugin.HG.WatchOff <Plug>HGWatchOff |
|
1188 | 1317 | amenu <silent> &Plugin.HG.WatchRemove <Plug>HGWatchRemove |
|
1189 | 1318 | |
|
1190 | 1319 | " Section: Autocommands to restore vimdiff state {{{1 |
|
1191 | 1320 | function! s:HGVimDiffRestore(vimDiffBuff) |
|
1192 | 1321 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning + 1 |
|
1193 | 1322 | try |
|
1194 | 1323 | if exists("s:vimDiffSourceBuffer") |
|
1195 | 1324 | if a:vimDiffBuff == s:vimDiffSourceBuffer |
|
1196 | 1325 | " Original file is being removed. |
|
1197 | 1326 | unlet! s:vimDiffSourceBuffer |
|
1198 | 1327 | unlet! s:vimDiffBufferCount |
|
1199 | 1328 | unlet! s:vimDiffRestoreCmd |
|
1200 | 1329 | unlet! s:vimDiffScratchList |
|
1201 | 1330 | elseif match(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}') >= 0 |
|
1202 | 1331 | let s:vimDiffScratchList = substitute(s:vimDiffScratchList, '{' . a:vimDiffBuff . '}', '', '') |
|
1203 | 1332 | let s:vimDiffBufferCount = s:vimDiffBufferCount - 1 |
|
1204 | 1333 | if s:vimDiffBufferCount == 1 && exists('s:vimDiffRestoreCmd') |
|
1205 | 1334 | " All scratch buffers are gone, reset the original. |
|
1206 | 1335 | " Only restore if the source buffer is still in Diff mode |
|
1207 | 1336 | |
|
1208 | 1337 | let sourceWinNR=bufwinnr(s:vimDiffSourceBuffer) |
|
1209 | 1338 | if sourceWinNR != -1 |
|
1210 | 1339 | " The buffer is visible in at least one window |
|
1211 | 1340 | let currentWinNR = winnr() |
|
1212 | 1341 | while winbufnr(sourceWinNR) != -1 |
|
1213 | 1342 | if winbufnr(sourceWinNR) == s:vimDiffSourceBuffer |
|
1214 | 1343 | execute sourceWinNR . 'wincmd w' |
|
1215 | 1344 | if getwinvar('', "&diff") |
|
1216 | 1345 | execute s:vimDiffRestoreCmd |
|
1217 | 1346 | endif |
|
1218 | 1347 | endif |
|
1219 | 1348 | let sourceWinNR = sourceWinNR + 1 |
|
1220 | 1349 | endwhile |
|
1221 | 1350 | execute currentWinNR . 'wincmd w' |
|
1222 | 1351 | else |
|
1223 | 1352 | " The buffer is hidden. It must be visible in order to set the |
|
1224 | 1353 | " diff option. |
|
1225 | 1354 | let currentBufNR = bufnr('') |
|
1226 | 1355 | execute "hide buffer" s:vimDiffSourceBuffer |
|
1227 | 1356 | if getwinvar('', "&diff") |
|
1228 | 1357 | execute s:vimDiffRestoreCmd |
|
1229 | 1358 | endif |
|
1230 | 1359 | execute "hide buffer" currentBufNR |
|
1231 | 1360 | endif |
|
1232 | 1361 | |
|
1233 | 1362 | unlet s:vimDiffRestoreCmd |
|
1234 | 1363 | unlet s:vimDiffSourceBuffer |
|
1235 | 1364 | unlet s:vimDiffBufferCount |
|
1236 | 1365 | unlet s:vimDiffScratchList |
|
1237 | 1366 | elseif s:vimDiffBufferCount == 0 |
|
1238 | 1367 | " All buffers are gone. |
|
1239 | 1368 | unlet s:vimDiffSourceBuffer |
|
1240 | 1369 | unlet s:vimDiffBufferCount |
|
1241 | 1370 | unlet s:vimDiffScratchList |
|
1242 | 1371 | endif |
|
1243 | 1372 | endif |
|
1244 | 1373 | endif |
|
1245 | 1374 | finally |
|
1246 | 1375 | let s:HGCommandEditFileRunning = s:HGCommandEditFileRunning - 1 |
|
1247 | 1376 | endtry |
|
1248 | 1377 | endfunction |
|
1249 | 1378 | |
|
1250 | 1379 | augroup HGVimDiffRestore |
|
1251 | 1380 | au! |
|
1252 | 1381 | au BufUnload * call s:HGVimDiffRestore(expand("<abuf>")) |
|
1253 | 1382 | augroup END |
|
1254 | 1383 | |
|
1255 | 1384 | " Section: Optional activation of buffer management {{{1 |
|
1256 | 1385 | |
|
1257 | 1386 | if s:HGGetOption('HGCommandEnableBufferSetup', 0) |
|
1258 | 1387 | call HGEnableBufferSetup() |
|
1259 | 1388 | endif |
|
1260 | 1389 | |
|
1390 | " Section: Doc installation {{{1 | |
|
1391 | " | |
|
1392 | let s:revision="0.1" | |
|
1393 | silent! let s:install_status = | |
|
1394 | \ s:HGInstallDocumentation(expand('<sfile>:p'), s:revision) | |
|
1395 | if (s:install_status == 1) | |
|
1396 | echom expand("<sfile>:t:r") . ' v' . s:revision . | |
|
1397 | \ ': Help-documentation installed.' | |
|
1398 | endif | |
|
1399 | ||
|
1400 | ||
|
1261 | 1401 | " Section: Plugin completion {{{1 |
|
1262 | 1402 | |
|
1263 | 1403 | let loaded_hgcommand=2 |
|
1264 | 1404 | silent do HGCommand User HGPluginFinish |
|
1265 | 1405 | " vim:se expandtab sts=2 sw=2: |
|
1406 | finish | |
|
1407 | ||
|
1408 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
|
1409 | " Section: Documentation content {{{1 | |
|
1410 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
|
1411 | === START_DOC | |
|
1412 | *hgcommand.txt* Mercurial vim integration #version# | |
|
1413 | ||
|
1414 | ||
|
1415 | HGCOMMAND REFERENCE MANUAL~ | |
|
1416 | ||
|
1417 | ||
|
1418 | Author: Mathieu Clabaut <mathieu.clabaut@gmail.com> | |
|
1419 | Credits: Bob Hiestand <bob.hiestand@gmail.com> | |
|
1420 | Mercurial: http://www.selenic.com/mercurial | |
|
1421 | Mercurial (noted Hg) is a fast, lightweight Source Control Management | |
|
1422 | system designed for efficient handling of very large distributed projects. | |
|
1423 | ||
|
1424 | ============================================================================== | |
|
1425 | 1. Contents *hgcommand-contents* | |
|
1426 | ||
|
1427 | Installation : |hgcommand-install| | |
|
1428 | HGCommand Intro : |hgcommand| | |
|
1429 | HGCommand Manual : |hgcommand-manual| | |
|
1430 | Customization : |hgcommand-customize| | |
|
1431 | SSH "integration" : |hgcommand-ssh| | |
|
1432 | Bugs : |hgcommand-bugs| | |
|
1433 | ||
|
1434 | ============================================================================== | |
|
1435 | *hgcommand-install* | |
|
1436 | 2. HGCommand Installation | |
|
1437 | ||
|
1438 | In order to install the plugin, place the hgcommand.vim file into a plugin' | |
|
1439 | directory in your runtime path (please see |add-global-plugin| and | |
|
1440 | |'runtimepath'|. | |
|
1441 | ||
|
1442 | HGCommand may be customized by setting variables, creating maps, and | |
|
1443 | specifying event handlers. Please see |hgcommand-customize| for more | |
|
1444 | details. | |
|
1445 | ||
|
1446 | *hgcommand-auto-help* | |
|
1447 | The help file is automagically generated when the |vimspell| script is | |
|
1448 | loaded for the first time. | |
|
1449 | ||
|
1450 | ============================================================================== | |
|
1451 | ||
|
1452 | 3. HGCommand Intro *hgcommand* | |
|
1453 | *hgcommand-intro* | |
|
1454 | ||
|
1455 | The HGCommand plugin provides global ex commands for manipulating | |
|
1456 | HG-controlled source files. In general, each command operates on the current | |
|
1457 | buffer and accomplishes a separate hg function, such as update, commit, log, | |
|
1458 | and others (please see |hgcommand-commands| for a list of all available | |
|
1459 | commands). The results of each operation are displayed in a scratch buffer. | |
|
1460 | Several buffer variables are defined for those scratch buffers (please see | |
|
1461 | |hgcommand-buffer-variables|). | |
|
1462 | ||
|
1463 | The notion of "current file" means either the current buffer, or, in the case | |
|
1464 | of a directory buffer, the file on the current line within the buffer. | |
|
1465 | ||
|
1466 | For convenience, any HGCommand invoked on a HGCommand scratch buffer acts as | |
|
1467 | though it was invoked on the original file and splits the screen so that the | |
|
1468 | output appears in a new window. | |
|
1469 | ||
|
1470 | Many of the commands accept revisions as arguments. By default, most operate | |
|
1471 | on the most recent revision on the current branch if no revision is specified | |
|
1472 | (though see |HGCommandInteractive| to prompt instead). | |
|
1473 | ||
|
1474 | Each HGCommand is mapped to a key sequence starting with the <Leader> | |
|
1475 | keystroke. The default mappings may be overridden by supplying different | |
|
1476 | mappings before the plugin is loaded, such as in the vimrc, in the standard | |
|
1477 | fashion for plugin mappings. For examples, please see | |
|
1478 | |hgcommand-mappings-override|. | |
|
1479 | ||
|
1480 | The HGCommand plugin may be configured in several ways. For more details, | |
|
1481 | please see |hgcommand-customize|. | |
|
1482 | ||
|
1483 | ============================================================================== | |
|
1484 | ||
|
1485 | 4. HGCommand Manual *hgcommand-manual* | |
|
1486 | ||
|
1487 | 4.1 HGCommand commands *hgcommand-commands* | |
|
1488 | ||
|
1489 | HGCommand defines the following commands: | |
|
1490 | ||
|
1491 | |:HGAdd| | |
|
1492 | |:HGAnnotate| | |
|
1493 | |:HGCommit| | |
|
1494 | |:HGDiff| | |
|
1495 | |:HGGotoOriginal| | |
|
1496 | |:HGLog| | |
|
1497 | |:HGRevert| | |
|
1498 | |:HGReview| | |
|
1499 | |:HGStatus| | |
|
1500 | |:HGUnedit| | |
|
1501 | |:HGUpdate| | |
|
1502 | |:HGVimDiff| | |
|
1503 | ||
|
1504 | :HGAdd *:HGAdd* | |
|
1505 | ||
|
1506 | This command performs "hg add" on the current file. Please note, this does | |
|
1507 | not commit the newly-added file. | |
|
1508 | ||
|
1509 | :HGAnnotate *:HGAnnotate* | |
|
1510 | ||
|
1511 | This command performs "hg annotate" on the current file. If an argument is | |
|
1512 | given, the argument is used as a revision number to display. If not given an | |
|
1513 | argument, it uses the most recent version of the file on the current branch. | |
|
1514 | Additionally, if the current buffer is a HGAnnotate buffer already, the | |
|
1515 | version number on the current line is used. | |
|
1516 | ||
|
1517 | If the |HGCommandAnnotateParent| variable is set to a non-zero value, the | |
|
1518 | version previous to the one on the current line is used instead. This allows | |
|
1519 | one to navigate back to examine the previous version of a line. | |
|
1520 | ||
|
1521 | The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to take | |
|
1522 | advantage of the bundled syntax file. | |
|
1523 | ||
|
1524 | ||
|
1525 | :HGCommit[!] *:HGCommit* | |
|
1526 | ||
|
1527 | If called with arguments, this performs "hg commit" using the arguments as | |
|
1528 | the log message. | |
|
1529 | ||
|
1530 | If '!' is used with no arguments, an empty log message is committed. | |
|
1531 | ||
|
1532 | If called with no arguments, this is a two-step command. The first step opens | |
|
1533 | a buffer to accept a log message. When that buffer is written, it is | |
|
1534 | automatically closed and the file is committed using the information from that | |
|
1535 | log message. The commit can be abandoned if the log message buffer is deleted | |
|
1536 | or wiped before being written. | |
|
1537 | ||
|
1538 | Alternatively, the mapping that is used to invoke :HGCommit (by default | |
|
1539 | <Leader>hgc) can be used in the log message buffer to immediately commit. | |
|
1540 | This | |
|
1541 | is useful if the |HGCommandCommitOnWrite| variable is set to 0 to disable the | |
|
1542 | normal commit-on-write behavior. | |
|
1543 | ||
|
1544 | :HGDiff *:HGDiff* | |
|
1545 | ||
|
1546 | With no arguments, this performs "hg diff" on the current file against the | |
|
1547 | current repository version. | |
|
1548 | ||
|
1549 | With one argument, "hg diff" is performed on the current file against the | |
|
1550 | specified revision. | |
|
1551 | ||
|
1552 | With two arguments, hg diff is performed between the specified | |
|
1553 | revisions of the current file. | |
|
1554 | ||
|
1555 | This command uses the 'HGCommandDiffOpt' variable to specify diff options. | |
|
1556 | If that variable does not exist, then 'wbBc' is assumed. If you wish to have | |
|
1557 | no options, then set it to the empty string. | |
|
1558 | ||
|
1559 | ||
|
1560 | This command performs "hg edit" on the current file. | |
|
1561 | ||
|
1562 | :HGGotoOriginal *:HGGotoOriginal* | |
|
1563 | ||
|
1564 | This command returns the current window to the source buffer, if the current | |
|
1565 | buffer is a HG command output buffer. | |
|
1566 | ||
|
1567 | :HGGotoOriginal! | |
|
1568 | ||
|
1569 | Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command | |
|
1570 | output buffers for the source buffer. | |
|
1571 | ||
|
1572 | :HGLog *:HGLog* | |
|
1573 | ||
|
1574 | Performs "hg log" on the current file. | |
|
1575 | ||
|
1576 | If an argument is given, it is passed as an argument to the "-r" option of | |
|
1577 | "hg log". | |
|
1578 | ||
|
1579 | :HGRevert *:HGRevert* | |
|
1580 | ||
|
1581 | Replaces the current file with the most recent version from the repository in | |
|
1582 | order to wipe out any undesired changes. | |
|
1583 | ||
|
1584 | :HGReview *:HGReview* | |
|
1585 | ||
|
1586 | Retrieves a particular version of the current file. If no argument is given, | |
|
1587 | the most recent version of the file on the current branch is retrieved. | |
|
1588 | Otherwise, the specified version is retrieved. | |
|
1589 | ||
|
1590 | :HGStatus *:HGStatus* | |
|
1591 | ||
|
1592 | Performs "hg status" on the current file. | |
|
1593 | ||
|
1594 | :HGUnedit *:HGUnedit* | |
|
1595 | ||
|
1596 | Performs "hg unedit" on the current file. Again, yes, the output buffer here | |
|
1597 | is basically useless. | |
|
1598 | ||
|
1599 | :HGUpdate *:HGUpdate* | |
|
1600 | ||
|
1601 | Performs "hg update" on the current file. This intentionally does not | |
|
1602 | automatically reload the current buffer, though vim should prompt the user to | |
|
1603 | do so if the underlying file is altered by this command. | |
|
1604 | ||
|
1605 | :HGVimDiff *:HGVimDiff* | |
|
1606 | ||
|
1607 | With no arguments, this prompts the user for a revision and then uses vimdiff | |
|
1608 | to display the differences between the current file and the specified | |
|
1609 | revision. If no revision is specified, the most recent version of the file on | |
|
1610 | the current branch is used. | |
|
1611 | ||
|
1612 | With one argument, that argument is used as the revision as above. With two | |
|
1613 | arguments, the differences between the two revisions is displayed using | |
|
1614 | vimdiff. | |
|
1615 | ||
|
1616 | With either zero or one argument, the original buffer is used to perform the | |
|
1617 | vimdiff. When the other buffer is closed, the original buffer will be | |
|
1618 | returned to normal mode. | |
|
1619 | ||
|
1620 | Once vimdiff mode is started using the above methods, additional vimdiff | |
|
1621 | buffers may be added by passing a single version argument to the command. | |
|
1622 | There may be up to 4 vimdiff buffers total. | |
|
1623 | ||
|
1624 | Using the 2-argument form of the command resets the vimdiff to only those 2 | |
|
1625 | versions. Additionally, invoking the command on a different file will close | |
|
1626 | the previous vimdiff buffers. | |
|
1627 | ||
|
1628 | ||
|
1629 | 4.2 Mappings *hgcommand-mappings* | |
|
1630 | ||
|
1631 | By default, a mapping is defined for each command. These mappings execute the | |
|
1632 | default (no-argument) form of each command. | |
|
1633 | ||
|
1634 | <Leader>hga HGAdd | |
|
1635 | <Leader>hgn HGAnnotate | |
|
1636 | <Leader>hgc HGCommit | |
|
1637 | <Leader>hgd HGDiff | |
|
1638 | <Leader>hgg HGGotoOriginal | |
|
1639 | <Leader>hgG HGGotoOriginal! | |
|
1640 | <Leader>hgl HGLog | |
|
1641 | <Leader>hgr HGReview | |
|
1642 | <Leader>hgs HGStatus | |
|
1643 | <Leader>hgt HGUnedit | |
|
1644 | <Leader>hgu HGUpdate | |
|
1645 | <Leader>hgv HGVimDiff | |
|
1646 | ||
|
1647 | *hgcommand-mappings-override* | |
|
1648 | ||
|
1649 | The default mappings can be overriden by user-provided instead by mapping to | |
|
1650 | <Plug>CommandName. This is especially useful when these mappings collide with | |
|
1651 | other existing mappings (vim will warn of this during plugin initialization, | |
|
1652 | but will not clobber the existing mappings). | |
|
1653 | ||
|
1654 | For instance, to override the default mapping for :HGAdd to set it to '\add', | |
|
1655 | add the following to the vimrc: | |
|
1656 | ||
|
1657 | nmap \add <Plug>HGAdd | |
|
1658 | ||
|
1659 | 4.3 Automatic buffer variables *hgcommand-buffer-variables* | |
|
1660 | ||
|
1661 | Several buffer variables are defined in each HGCommand result buffer. These | |
|
1662 | may be useful for additional customization in callbacks defined in the event | |
|
1663 | handlers (please see |hgcommand-events|). | |
|
1664 | ||
|
1665 | The following variables are automatically defined: | |
|
1666 | ||
|
1667 | b:hgOrigBuffNR *b:hgOrigBuffNR* | |
|
1668 | ||
|
1669 | This variable is set to the buffer number of the source file. | |
|
1670 | ||
|
1671 | b:hgcmd *b:hgcmd* | |
|
1672 | ||
|
1673 | This variable is set to the name of the hg command that created the result | |
|
1674 | buffer. | |
|
1675 | ============================================================================== | |
|
1676 | ||
|
1677 | 5. Configuration and customization *hgcommand-customize* | |
|
1678 | *hgcommand-config* | |
|
1679 | ||
|
1680 | The HGCommand plugin can be configured in two ways: by setting configuration | |
|
1681 | variables (see |hgcommand-options|) or by defining HGCommand event handlers | |
|
1682 | (see |hgcommand-events|). Additionally, the HGCommand plugin provides | |
|
1683 | several option for naming the HG result buffers (see |hgcommand-naming|) and | |
|
1684 | supported a customized status line (see |hgcommand-statusline| and | |
|
1685 | |hgcommand-buffer-management|). | |
|
1686 | ||
|
1687 | 5.1 HGCommand configuration variables *hgcommand-options* | |
|
1688 | ||
|
1689 | Several variables affect the plugin's behavior. These variables are checked | |
|
1690 | at time of execution, and may be defined at the window, buffer, or global | |
|
1691 | level and are checked in that order of precedence. | |
|
1692 | ||
|
1693 | ||
|
1694 | The following variables are available: | |
|
1695 | ||
|
1696 | |HGCommandAnnotateParent| | |
|
1697 | |HGCommandCommitOnWrite| | |
|
1698 | |HGCommandHGExec| | |
|
1699 | |HGCommandDeleteOnHide| | |
|
1700 | |HGCommandDiffOpt| | |
|
1701 | |HGCommandDiffSplit| | |
|
1702 | |HGCommandEdit| | |
|
1703 | |HGCommandEnableBufferSetup| | |
|
1704 | |HGCommandInteractive| | |
|
1705 | |HGCommandNameMarker| | |
|
1706 | |HGCommandNameResultBuffers| | |
|
1707 | |HGCommandSplit| | |
|
1708 | ||
|
1709 | HGCommandAnnotateParent *HGCommandAnnotateParent* | |
|
1710 | ||
|
1711 | This variable, if set to a non-zero value, causes the zero-argument form of | |
|
1712 | HGAnnotate when invoked on a HGAnnotate buffer to go to the version previous | |
|
1713 | to that displayed on the current line. If not set, it defaults to 0. | |
|
1714 | ||
|
1715 | HGCommandCommitOnWrite *HGCommandCommitOnWrite* | |
|
1716 | ||
|
1717 | This variable, if set to a non-zero value, causes the pending hg commit | |
|
1718 | to take place immediately as soon as the log message buffer is written. | |
|
1719 | If set to zero, only the HGCommit mapping will cause the pending commit to | |
|
1720 | occur. If not set, it defaults to 1. | |
|
1721 | ||
|
1722 | HGCommandHGExec *HGCommandHGExec* | |
|
1723 | ||
|
1724 | This variable controls the executable used for all HG commands If not set, | |
|
1725 | it defaults to "hg". | |
|
1726 | ||
|
1727 | HGCommandDeleteOnHide *HGCommandDeleteOnHide* | |
|
1728 | ||
|
1729 | This variable, if set to a non-zero value, causes the temporary HG result | |
|
1730 | buffers to automatically delete themselves when hidden. | |
|
1731 | ||
|
1732 | HGCommandDiffOpt *HGCommandDiffOpt* | |
|
1733 | ||
|
1734 | This variable, if set, determines the options passed to the diff command of | |
|
1735 | HG. If not set, it defaults to 'wbBc'. | |
|
1736 | ||
|
1737 | HGCommandDiffSplit *HGCommandDiffSplit* | |
|
1738 | ||
|
1739 | This variable overrides the |HGCommandSplit| variable, but only for buffers | |
|
1740 | created with |:HGVimDiff|. | |
|
1741 | ||
|
1742 | HGCommandEdit *HGCommandEdit* | |
|
1743 | ||
|
1744 | This variable controls whether the original buffer is replaced ('edit') or | |
|
1745 | split ('split'). If not set, it defaults to 'edit'. | |
|
1746 | ||
|
1747 | HGCommandEnableBufferSetup *HGCommandEnableBufferSetup* | |
|
1748 | ||
|
1749 | This variable, if set to a non-zero value, activates HG buffer management | |
|
1750 | mode see (|hgcommand-buffer-management|). This mode means that two buffer | |
|
1751 | variables, 'HGRevision' and 'HGBranch', are set if the file is | |
|
1752 | HG-controlled. This is useful for displaying version information in the | |
|
1753 | status bar. | |
|
1754 | ||
|
1755 | HGCommandInteractive *HGCommandInteractive* | |
|
1756 | ||
|
1757 | This variable, if set to a non-zero value, causes appropriate commands (for | |
|
1758 | the moment, only |:HGReview|) to query the user for a revision to use instead | |
|
1759 | of the current revision if none is specified. | |
|
1760 | ||
|
1761 | HGCommandNameMarker *HGCommandNameMarker* | |
|
1762 | ||
|
1763 | This variable, if set, configures the special attention-getting characters | |
|
1764 | that appear on either side of the hg buffer type in the buffer name. This | |
|
1765 | has no effect unless |HGCommandNameResultBuffers| is set to a true value. If | |
|
1766 | not set, it defaults to '_'. | |
|
1767 | ||
|
1768 | HGCommandNameResultBuffers *HGCommandNameResultBuffers* | |
|
1769 | ||
|
1770 | This variable, if set to a true value, causes the hg result buffers to be | |
|
1771 | named in the old way ('<source file name> _<hg command>_'). If not set | |
|
1772 | or set to a false value, the result buffer is nameless. | |
|
1773 | ||
|
1774 | HGCommandSplit *HGCommandSplit* | |
|
1775 | ||
|
1776 | This variable controls the orientation of the various window splits that | |
|
1777 | may occur (such as with HGVimDiff, when using a HG command on a HG | |
|
1778 | command buffer, or when the |HGCommandEdit| variable is set to 'split'. | |
|
1779 | If set to 'horizontal', the resulting windows will be on stacked on top of | |
|
1780 | one another. If set to 'vertical', the resulting windows will be | |
|
1781 | side-by-side. If not set, it defaults to 'horizontal' for all but | |
|
1782 | HGVimDiff windows. | |
|
1783 | ||
|
1784 | 5.2 HGCommand events *hgcommand-events* | |
|
1785 | ||
|
1786 | For additional customization, HGCommand can trigger user-defined events. | |
|
1787 | Event handlers are provided by defining User event autocommands (see | |
|
1788 | |autocommand|, |User|) in the HGCommand group with patterns matching the | |
|
1789 | event name. | |
|
1790 | ||
|
1791 | For instance, the following could be added to the vimrc to provide a 'q' | |
|
1792 | mapping to quit a HGCommand scratch buffer: | |
|
1793 | ||
|
1794 | augroup HGCommand | |
|
1795 | au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q: bwipeout<cr> | |
|
1796 | augroup END | |
|
1797 | ||
|
1798 | The following hooks are available: | |
|
1799 | ||
|
1800 | HGBufferCreated This event is fired just after a hg command | |
|
1801 | result buffer is created and filled with the | |
|
1802 | result of a hg command. It is executed within | |
|
1803 | the context of the HG command buffer. The | |
|
1804 | HGCommand buffer variables may be useful for | |
|
1805 | handlers of this event (please see | |
|
1806 | |hgcommand-buffer-variables|). | |
|
1807 | ||
|
1808 | HGBufferSetup This event is fired just after HG buffer setup | |
|
1809 | occurs, if enabled. | |
|
1810 | ||
|
1811 | HGPluginInit This event is fired when the HGCommand plugin | |
|
1812 | first loads. | |
|
1813 | ||
|
1814 | HGPluginFinish This event is fired just after the HGCommand | |
|
1815 | plugin loads. | |
|
1816 | ||
|
1817 | HGVimDiffFinish This event is fired just after the HGVimDiff | |
|
1818 | command executes to allow customization of, | |
|
1819 | for instance, window placement and focus. | |
|
1820 | ||
|
1821 | 5.3 HGCommand buffer naming *hgcommand-naming* | |
|
1822 | ||
|
1823 | By default, the buffers containing the result of HG commands are nameless | |
|
1824 | scratch buffers. It is intended that buffer variables of those buffers be | |
|
1825 | used to customize the statusline option so that the user may fully control the | |
|
1826 | display of result buffers. | |
|
1827 | ||
|
1828 | If the old-style naming is desired, please enable the | |
|
1829 | |HGCommandNameResultBuffers| variable. Then, each result buffer will receive | |
|
1830 | a unique name that includes the source file name, the HG command, and any | |
|
1831 | extra data (such as revision numbers) that were part of the command. | |
|
1832 | ||
|
1833 | 5.4 HGCommand status line support *hgcommand-statusline* | |
|
1834 | ||
|
1835 | It is intended that the user will customize the |'statusline'| option to | |
|
1836 | include HG result buffer attributes. A sample function that may be used in | |
|
1837 | the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In | |
|
1838 | order to use that function in the status line, do something like the | |
|
1839 | following: | |
|
1840 | ||
|
1841 | set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P | |
|
1842 | ||
|
1843 | of which %{HGGetStatusLine()} is the relevant portion. | |
|
1844 | ||
|
1845 | The sample HGGetStatusLine() function handles both HG result buffers and | |
|
1846 | HG-managed files if HGCommand buffer management is enabled (please see | |
|
1847 | |hgcommand-buffer-management|). | |
|
1848 | ||
|
1849 | 5.5 HGCommand buffer management *hgcommand-buffer-management* | |
|
1850 | ||
|
1851 | The HGCommand plugin can operate in buffer management mode, which means that | |
|
1852 | it attempts to set two buffer variables ('HGRevision' and 'HGBranch') upon | |
|
1853 | entry into a buffer. This is rather slow because it means that 'hg status' | |
|
1854 | will be invoked at each entry into a buffer (during the |BufEnter| | |
|
1855 | autocommand). | |
|
1856 | ||
|
1857 | This mode is disabled by default. In order to enable it, set the | |
|
1858 | |HGCommandEnableBufferSetup| variable to a true (non-zero) value. Enabling | |
|
1859 | this mode simply provides the buffer variables mentioned above. The user must | |
|
1860 | explicitly include those in the |'statusline'| option if they are to appear in | |
|
1861 | the status line (but see |hgcommand-statusline| for a simple way to do that). | |
|
1862 | ||
|
1863 | ============================================================================== | |
|
1864 | ||
|
1865 | 6. SSH "integration" *hgcommand-ssh* | |
|
1866 | ||
|
1867 | The following instructions are intended for use in integrating the | |
|
1868 | hgcommand.vim plugin with an SSH-based HG environment. | |
|
1869 | ||
|
1870 | Familiarity with SSH and HG are assumed. | |
|
1871 | ||
|
1872 | These instructions assume that the intent is to have a message box pop up in | |
|
1873 | order to allow the user to enter a passphrase. If, instead, the user is | |
|
1874 | comfortable using certificate-based authentication, then only instructions | |
|
1875 | 6.1.1 and 6.1.2 (and optionally 6.1.4) need to be followed; ssh should then | |
|
1876 | work transparently. | |
|
1877 | ||
|
1878 | 6.1 Environment settings *hgcommand-ssh-env* | |
|
1879 | ||
|
1880 | 6.1.1 HGROOT should be set to something like: | |
|
1881 | ||
|
1882 | :ext:user@host:/path_to_repository | |
|
1883 | ||
|
1884 | 6.1.2 HG_RSH should be set to: | |
|
1885 | ||
|
1886 | ssh | |
|
1887 | ||
|
1888 | Together, those settings tell HG to use ssh as the transport when | |
|
1889 | performing HG calls. | |
|
1890 | ||
|
1891 | 6.1.3 SSH_ASKPASS should be set to the password-dialog program. In my case, | |
|
1892 | running gnome, it's set to: | |
|
1893 | ||
|
1894 | /usr/libexec/openssh/gnome-ssh-askpass | |
|
1895 | ||
|
1896 | This tells SSH how to get passwords if no input is available. | |
|
1897 | ||
|
1898 | 6.1.4 OPTIONAL. You may need to set SSH_SERVER to the location of the hg | |
|
1899 | executable on the remote (server) machine. | |
|
1900 | ||
|
1901 | 6.2 HG wrapper program *hgcommand-ssh-wrapper* | |
|
1902 | ||
|
1903 | Now you need to convince SSH to use the password-dialog program. This means | |
|
1904 | you need to execute SSH (and therefore HG) without standard input. The | |
|
1905 | following script is a simple perl wrapper that dissasociates the HG command | |
|
1906 | from the current terminal. Specific steps to do this may vary from system to | |
|
1907 | system; the following example works for me on linux. | |
|
1908 | ||
|
1909 | #!/usr/bin/perl -w | |
|
1910 | use strict; | |
|
1911 | use POSIX qw(setsid); | |
|
1912 | open STDIN, '/dev/null'; | |
|
1913 | fork and do {wait; exit;}; | |
|
1914 | setsid; | |
|
1915 | exec('hg', @ARGV); | |
|
1916 | ||
|
1917 | 6.3 Configuring hgcommand.vim *hgcommand-ssh-config* | |
|
1918 | ||
|
1919 | At this point, you should be able to use your wrapper script to invoke HG with | |
|
1920 | various commands, and get the password dialog. All that's left is to make HG | |
|
1921 | use your newly-created wrapper script. | |
|
1922 | ||
|
1923 | 6.3.1 Tell hgcommand.vim what HG executable to use. The easiest way to do this | |
|
1924 | is globally, by putting the following in your .vimrc: | |
|
1925 | ||
|
1926 | let HGCommandHGExec=/path/to/hg/wrapper/script | |
|
1927 | ||
|
1928 | 6.4 Where to go from here *hgcommand-ssh-other* | |
|
1929 | ||
|
1930 | The script given above works even when non-SSH HG connections are used, | |
|
1931 | except possibly when interactively entering the message for HG commit log | |
|
1932 | (depending on the editor you use... VIM works fine). Since the hgcommand.vim | |
|
1933 | plugin handles that message without a terminal, the wrapper script can be used | |
|
1934 | all the time. | |
|
1935 | ||
|
1936 | This allows mixed-mode operation, where some work is done with SSH-based HG | |
|
1937 | repositories, and others with pserver or local access. | |
|
1938 | ||
|
1939 | It is possible, though beyond the scope of the plugin, to dynamically set the | |
|
1940 | HG executable based on the HGROOT for the file being edited. The user | |
|
1941 | events provided (such as HGBufferCreated and HGBufferSetup) can be used to | |
|
1942 | set a buffer-local value (b:HGCommandHGExec) to override the HG executable | |
|
1943 | on a file-by-file basis. Alternatively, much the same can be done (less | |
|
1944 | automatically) by the various project-oriented plugins out there. | |
|
1945 | ||
|
1946 | It is highly recommended for ease-of-use that certificates with no passphrase | |
|
1947 | or ssh-agent are employed so that the user is not given the password prompt | |
|
1948 | too often. | |
|
1949 | ||
|
1950 | ============================================================================== | |
|
1951 | 9. Tips *hgcommand-tips* | |
|
1952 | ||
|
1953 | 9.1 Split window annotation, by Michael Anderson | |
|
1954 | ||
|
1955 | :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR> | |
|
1956 | \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR> | |
|
1957 | \:set nowrap<CR> | |
|
1958 | ||
|
1959 | This splits the buffer vertically, puts an annotation on the left (minus the | |
|
1960 | header) with the width set to 40. An editable/normal copy is placed on the | |
|
1961 | right. The two versions are scroll locked so they move as one. and wrapping | |
|
1962 | is turned off so that the lines line up correctly. The advantages are... | |
|
1963 | ||
|
1964 | 1) You get a versioning on the right. | |
|
1965 | 2) You can still edit your own code. | |
|
1966 | 3) Your own code still has syntax highlighting. | |
|
1967 | ||
|
1968 | ============================================================================== | |
|
1969 | ||
|
1970 | 8. Known bugs *hgcommand-bugs* | |
|
1971 | ||
|
1972 | Please let me know if you run across any. | |
|
1973 | ||
|
1974 | HGVimDiff, when using the original (real) source buffer as one of the diff | |
|
1975 | buffers, uses some hacks to try to restore the state of the original buffer | |
|
1976 | when the scratch buffer containing the other version is destroyed. There may | |
|
1977 | still be bugs in here, depending on many configuration details. | |
|
1978 | ||
|
1979 | ============================================================================== | |
|
1980 | === END_DOC | |
|
1981 | """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
|
1982 | " v im:tw=78:ts=8:ft=help:norl: | |
|
1983 | " vim600: set foldmethod=marker tabstop=8 shiftwidth=2 softtabstop=2 smartindent smarttab : | |
|
1984 | "fileencoding=iso-8859-15 |
General Comments 0
You need to be logged in to leave comments.
Login now