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