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