Mercurial > vim
comparison runtime/ftplugin/ocaml.vim @ 3312:b7811ab264bf v7.3.423
updated for version 7.3.423
Problem: Small mistakes in comments, proto and indent.
Solution: Fix the mistakes.
Also update runtime files
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 04 Feb 2012 21:59:01 +0100 |
parents | 8b8ef1fed009 |
children | c458ff35497e |
comparison
equal
deleted
inserted
replaced
3311:54d1536a1c8b | 3312:b7811ab264bf |
---|---|
1 " Language: OCaml | 1 " Language: OCaml |
2 " Maintainer: David Baelde <firstname.name@ens-lyon.org> | 2 " Maintainer: David Baelde <firstname.name@ens-lyon.org> |
3 " Mike Leary <leary@nwlink.com> | 3 " Mike Leary <leary@nwlink.com> |
4 " Markus Mottl <markus.mottl@gmail.com> | 4 " Markus Mottl <markus.mottl@gmail.com> |
5 " Pierre Vittet <pierre-vittet@pvittet.com> | |
5 " Stefano Zacchiroli <zack@bononia.it> | 6 " Stefano Zacchiroli <zack@bononia.it> |
6 " Vincent Aravantinos <firstname.name@imag.fr> | 7 " Vincent Aravantinos <firstname.name@imag.fr> |
7 " URL: http://www.ocaml.info/vim/ftplugin/ocaml.vim | 8 " URL: http://www.ocaml.info/vim/ftplugin/ocaml.vim |
8 " Last Change: 2010 Jul 10 - Bugfix, thanks to Pat Rondon | 9 " Last Change: |
10 " 2012 Jan 15 - Bugfix :reloading .annot file does not close | |
11 " splitted view (Pierre Vittet) | |
12 " 2011 Nov 28 - Bugfix + support of multiple ml annotation file | |
13 " (Pierre Vittet) | |
14 " 2010 Jul 10 - Bugfix, thanks to Pat Rondon | |
9 " 2008 Jul 17 - Bugfix related to fnameescape (VA) | 15 " 2008 Jul 17 - Bugfix related to fnameescape (VA) |
10 " 2007 Sep 09 - Added .annot support for ocamlbuild, python not | 16 |
11 " needed anymore (VA) | |
12 " 2006 May 01 - Added .annot support for file.whateverext (SZ) | |
13 " 2006 Apr 11 - Fixed an initialization bug; fixed ASS abbrev (MM) | |
14 " 2005 Oct 13 - removed GPL; better matchit support (MM, SZ) | |
15 " | |
16 if exists("b:did_ftplugin") | 17 if exists("b:did_ftplugin") |
17 finish | 18 finish |
18 endif | 19 endif |
19 let b:did_ftplugin=1 | 20 let b:did_ftplugin=1 |
20 | 21 |
285 endwhile | 286 endwhile |
286 return temp | 287 return temp |
287 endfun | 288 endfun |
288 | 289 |
289 " After call: | 290 " After call: |
290 " - b:annot_file_path : | 291 " |
292 " Following information have been put in s:annot_file_list, using | |
293 " annot_file_name name as key: | |
294 " - annot_file_path : | |
291 " path to the .annot file corresponding to the | 295 " path to the .annot file corresponding to the |
292 " source file (dealing with ocamlbuild stuff) | 296 " source file (dealing with ocamlbuild stuff) |
293 " - b:_build_path: | 297 " - _build_path: |
294 " path to the build directory even if this one is | 298 " path to the build directory even if this one is |
295 " not named '_build' | 299 " not named '_build' |
300 " - date_of_last annot: | |
301 " Set to 0 until we load the file. It contains the | |
302 " date at which the file has been loaded. | |
296 function! s:Locate_annotation() | 303 function! s:Locate_annotation() |
297 if !b:annotation_file_located | 304 let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot' |
298 | 305 if !exists ("s:annot_file_list[annot_file_name]") |
299 silent exe 'cd' s:Fnameescape(expand('%:p:h')) | 306 silent exe 'cd' s:Fnameescape(expand('%:p:h')) |
300 | |
301 let annot_file_name = s:Fnameescape(expand('%:r')).'.annot' | |
302 | |
303 " 1st case : the annot file is in the same directory as the buffer (no ocamlbuild) | 307 " 1st case : the annot file is in the same directory as the buffer (no ocamlbuild) |
304 let b:annot_file_path = findfile(annot_file_name,'.') | 308 let annot_file_path = findfile(annot_file_name,'.') |
305 if b:annot_file_path != '' | 309 if annot_file_path != '' |
306 let b:annot_file_path = getcwd().'/'.b:annot_file_path | 310 let annot_file_path = getcwd().'/'.annot_file_path |
307 let b:_build_path = '' | 311 let _build_path = '' |
308 else | 312 else |
309 " 2nd case : the buffer and the _build directory are in the same directory | 313 " 2nd case : the buffer and the _build directory are in the same directory |
310 " .. | 314 " .. |
311 " / \ | 315 " / \ |
312 " / \ | 316 " / \ |
313 " _build .ml | 317 " _build .ml |
314 " | 318 " |
315 let b:_build_path = finddir('_build','.') | 319 let _build_path = finddir('_build','.') |
316 if b:_build_path != '' | 320 if _build_path != '' |
317 let b:_build_path = getcwd().'/'.b:_build_path | 321 let _build_path = getcwd().'/'._build_path |
318 let b:annot_file_path = findfile(annot_file_name,'_build') | 322 let annot_file_path = findfile(annot_file_name,'_build') |
319 if b:annot_file_path != '' | 323 if annot_file_path != '' |
320 let b:annot_file_path = getcwd().'/'.b:annot_file_path | 324 let annot_file_path = getcwd().'/'.annot_file_path |
321 endif | 325 endif |
322 else | 326 else |
323 " 3rd case : the _build directory is in a directory higher in the file hierarchy | 327 " 3rd case : the _build directory is in a directory higher in the file hierarchy |
324 " (it can't be deeper by ocamlbuild requirements) | 328 " (it can't be deeper by ocamlbuild requirements) |
325 " .. | 329 " .. |
328 " _build ... | 332 " _build ... |
329 " \ | 333 " \ |
330 " \ | 334 " \ |
331 " .ml | 335 " .ml |
332 " | 336 " |
333 let b:_build_path = finddir('_build',';') | 337 let _build_path = finddir('_build',';') |
334 if b:_build_path != '' | 338 if _build_path != '' |
335 let project_path = substitute(b:_build_path,'/_build$','','') | 339 let project_path = substitute(_build_path,'/_build$','','') |
336 let path_relative_to_project = s:Fnameescape(substitute(expand('%:p:h'),project_path.'/','','')) | 340 let path_relative_to_project = s:Fnameescape(substitute(expand('%:p:h'),project_path.'/','','')) |
337 let b:annot_file_path = findfile(annot_file_name,project_path.'/_build/'.path_relative_to_project) | 341 let annot_file_path = findfile(annot_file_name,project_path.'/_build/'.path_relative_to_project) |
338 else | 342 else |
339 let b:annot_file_path = findfile(annot_file_name,'**') | 343 let annot_file_path = findfile(annot_file_name,'**') |
340 "4th case : what if the user decided to change the name of the _build directory ? | 344 "4th case : what if the user decided to change the name of the _build directory ? |
341 " -> we relax the constraints, it should work in most cases | 345 " -> we relax the constraints, it should work in most cases |
342 if b:annot_file_path != '' | 346 if annot_file_path != '' |
343 " 4a. we suppose the renamed _build directory is in the current directory | 347 " 4a. we suppose the renamed _build directory is in the current directory |
344 let b:_build_path = matchstr(b:annot_file_path,'^[^/]*') | 348 let _build_path = matchstr(annot_file_path,'^[^/]*') |
345 if b:annot_file_path != '' | 349 if annot_file_path != '' |
346 let b:annot_file_path = getcwd().'/'.b:annot_file_path | 350 let annot_file_path = getcwd().'/'.annot_file_path |
347 let b:_build_path = getcwd().'/'.b:_build_path | 351 let _build_path = getcwd().'/'._build_path |
348 endif | 352 endif |
349 else | 353 else |
354 let annot_file_name = '' | |
355 "(Pierre Vittet: I have commented 4b because this was chrashing | |
356 "my vim (it produced infinite loop)) | |
357 " | |
350 " 4b. anarchy : the renamed _build directory may be higher in the hierarchy | 358 " 4b. anarchy : the renamed _build directory may be higher in the hierarchy |
351 " this will work if the file for which we are looking annotations has a unique name in the whole project | 359 " this will work if the file for which we are looking annotations has a unique name in the whole project |
352 " if this is not the case, it may still work, but no warranty here | 360 " if this is not the case, it may still work, but no warranty here |
353 let b:annot_file_path = findfile(annot_file_name,'**;') | 361 "let annot_file_path = findfile(annot_file_name,'**;') |
354 let project_path = s:Find_common_path(b:annot_file_path,expand('%:p:h')) | 362 "let project_path = s:Find_common_path(annot_file_path,expand('%:p:h')) |
355 let b:_build_path = matchstr(b:annot_file_path,project_path.'/[^/]*') | 363 "let _build_path = matchstr(annot_file_path,project_path.'/[^/]*') |
356 endif | 364 endif |
357 endif | 365 endif |
358 endif | 366 endif |
359 endif | 367 endif |
360 | 368 |
361 if b:annot_file_path == '' | 369 if annot_file_path == '' |
362 throw 'E484: no annotation file found' | 370 throw 'E484: no annotation file found' |
363 endif | 371 endif |
364 | 372 |
365 silent exe 'cd' '-' | 373 silent exe 'cd' '-' |
366 | 374 let s:annot_file_list[annot_file_name]= [annot_file_path, _build_path, 0] |
367 let b:annotation_file_located = 1 | |
368 endif | 375 endif |
369 endfun | 376 endfun |
370 | 377 |
371 " This in order to locate the .annot file only once | 378 " This variable contain a dictionnary of list. Each element of the dictionnary |
372 let b:annotation_file_located = 0 | 379 " represent an annotation system. An annotation system is a list with : |
380 " - annotation file name as it's key | |
381 " - annotation file path as first element of the contained list | |
382 " - build path as second element of the contained list | |
383 " - annot_file_last_mod (contain the date of .annot file) as third element | |
384 let s:annot_file_list = {} | |
373 | 385 |
374 " 2. Finding the type information in the annotation file | 386 " 2. Finding the type information in the annotation file |
375 | 387 |
376 " a. The annotation file is opened in vim as a buffer that | 388 " a. The annotation file is opened in vim as a buffer that |
377 " should be (almost) invisible to the user. | 389 " should be (almost) invisible to the user. |
378 | 390 |
379 " After call: | 391 " After call: |
380 " The current buffer is now the one containing the .annot file. | 392 " The current buffer is now the one containing the .annot file. |
381 " We manage to keep all this hidden to the user's eye. | 393 " We manage to keep all this hidden to the user's eye. |
382 function! s:Enter_annotation_buffer() | 394 function! s:Enter_annotation_buffer(annot_file_path) |
383 let s:current_pos = getpos('.') | 395 let s:current_pos = getpos('.') |
384 let s:current_hidden = &l:hidden | 396 let s:current_hidden = &l:hidden |
385 set hidden | 397 set hidden |
386 let s:current_buf = bufname('%') | 398 let s:current_buf = bufname('%') |
387 if bufloaded(b:annot_file_path) | 399 if bufloaded(a:annot_file_path) |
388 silent exe 'keepj keepalt' 'buffer' s:Fnameescape(b:annot_file_path) | 400 silent exe 'keepj keepalt' 'buffer' s:Fnameescape(a:annot_file_path) |
389 else | 401 else |
390 silent exe 'keepj keepalt' 'view' s:Fnameescape(b:annot_file_path) | 402 silent exe 'keepj keepalt' 'view' s:Fnameescape(a:annot_file_path) |
391 endif | 403 endif |
404 call setpos(".", [0, 0 , 0 , 0]) | |
392 endfun | 405 endfun |
393 | 406 |
394 " After call: | 407 " After call: |
395 " The original buffer has been restored in the exact same state as before. | 408 " The original buffer has been restored in the exact same state as before. |
396 function! s:Exit_annotation_buffer() | 409 function! s:Exit_annotation_buffer() |
400 endfun | 413 endfun |
401 | 414 |
402 " After call: | 415 " After call: |
403 " The annot file is loaded and assigned to a buffer. | 416 " The annot file is loaded and assigned to a buffer. |
404 " This also handles the modification date of the .annot file, eg. after a | 417 " This also handles the modification date of the .annot file, eg. after a |
405 " compilation. | 418 " compilation (return an updated annot_file_list). |
406 function! s:Load_annotation() | 419 function! s:Load_annotation(annot_file_name) |
407 if bufloaded(b:annot_file_path) && b:annot_file_last_mod < getftime(b:annot_file_path) | 420 let annot = s:annot_file_list[a:annot_file_name] |
408 call s:Enter_annotation_buffer() | 421 let annot_file_path = annot[0] |
409 silent exe "bunload" | 422 let annot_file_last_mod = 0 |
410 call s:Exit_annotation_buffer() | 423 if exists("annot[2]") |
411 endif | 424 let annot_file_last_mod = annot[2] |
412 if !bufloaded(b:annot_file_path) | 425 endif |
413 call s:Enter_annotation_buffer() | 426 if bufloaded(annot_file_path) && annot_file_last_mod < getftime(annot_file_path) |
427 " if there is a more recent file | |
428 let nr = bufnr(annot_file_path) | |
429 silent exe 'keepj keepalt' 'bunload' nr | |
430 endif | |
431 if !bufloaded(annot_file_path) | |
432 call s:Enter_annotation_buffer(annot_file_path) | |
414 setlocal nobuflisted | 433 setlocal nobuflisted |
415 setlocal bufhidden=hide | 434 setlocal bufhidden=hide |
416 setlocal noswapfile | 435 setlocal noswapfile |
417 setlocal buftype=nowrite | 436 setlocal buftype=nowrite |
418 call s:Exit_annotation_buffer() | 437 call s:Exit_annotation_buffer() |
419 let b:annot_file_last_mod = getftime(b:annot_file_path) | 438 let annot[2] = getftime(annot_file_path) |
439 " List updated with the new date | |
440 let s:annot_file_list[a:annot_file_name] = annot | |
420 endif | 441 endif |
421 endfun | 442 endfun |
422 | 443 |
423 "b. 'search' and 'match' work to find the type information | 444 "b. 'search' and 'match' work to find the type information |
424 | 445 |
464 endfun | 485 endfun |
465 | 486 |
466 "In: the pattern to look for in order to match the block | 487 "In: the pattern to look for in order to match the block |
467 "Out: the type information (calls s:Match_data) | 488 "Out: the type information (calls s:Match_data) |
468 " Should be called in the annotation buffer | 489 " Should be called in the annotation buffer |
469 function! s:Extract_type_data(block_pattern) | 490 function! s:Extract_type_data(block_pattern, annot_file_name) |
470 call s:Enter_annotation_buffer() | 491 let annot_file_path = s:annot_file_list[a:annot_file_name][0] |
492 call s:Enter_annotation_buffer(annot_file_path) | |
471 try | 493 try |
472 if search(a:block_pattern,'e') == 0 | 494 if search(a:block_pattern,'e') == 0 |
473 throw "no_annotation" | 495 throw "no_annotation" |
474 endif | 496 endif |
475 call cursor(line(".") + 1,1) | 497 call cursor(line(".") + 1,1) |
525 endif | 547 endif |
526 endfun | 548 endfun |
527 | 549 |
528 "In: the current mode (eg. "visual", "normal", etc.) | 550 "In: the current mode (eg. "visual", "normal", etc.) |
529 "Out: the type information (calls s:Extract_type_data) | 551 "Out: the type information (calls s:Extract_type_data) |
530 function! s:Get_type(mode) | 552 function! s:Get_type(mode, annot_file_name) |
531 let [lin1,lin2,col1,col2] = s:Match_borders(a:mode) | 553 let [lin1,lin2,col1,col2] = s:Match_borders(a:mode) |
532 return s:Extract_type_data(s:Block_pattern(lin1,lin2,col1,col2)) | 554 return s:Extract_type_data(s:Block_pattern(lin1,lin2,col1,col2), a:annot_file_name) |
533 endfun | 555 endfun |
534 | 556 |
535 "d. main | 557 "d. main |
536 "In: the current mode (eg. "visual", "normal", etc.) | 558 "In: the current mode (eg. "visual", "normal", etc.) |
537 "After call: the type information is displayed | 559 "After call: the type information is displayed |
538 if !exists("*Ocaml_get_type") | 560 if !exists("*Ocaml_get_type") |
539 function Ocaml_get_type(mode) | 561 function Ocaml_get_type(mode) |
562 let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot' | |
540 call s:Locate_annotation() | 563 call s:Locate_annotation() |
541 call s:Load_annotation() | 564 call s:Load_annotation(annot_file_name) |
542 return s:Get_type(a:mode) | 565 return s:Get_type(a:mode, annot_file_name) |
543 endfun | 566 endfun |
544 endif | 567 endif |
545 | 568 |
546 if !exists("*Ocaml_get_type_or_not") | 569 if !exists("*Ocaml_get_type_or_not") |
547 function Ocaml_get_type_or_not(mode) | 570 function Ocaml_get_type_or_not(mode) |