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