##// END OF EJS Templates
hgcommand.vim: cleanup of doc self-install code
Christian Ebert -
r2734:0b7206a6 default
parent child Browse files
Show More
@@ -353,13 +353,13 b' function! s:HGGetStatusVars(revisionVar,'
353 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b "
353 let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents -b "
354 let statustext=system(hgCommand)
354 let statustext=system(hgCommand)
355 if(v:shell_error)
355 if(v:shell_error)
356 return ""
356 return ""
357 endif
357 endif
358 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
358 let revision=substitute(statustext, '^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")
359
359
360 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
360 if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
361 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
361 let branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
362 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
362 let returnExpression=returnExpression . " | let " . a:branchVar . "='" . branch . "'"
363 endif
363 endif
364 endif
364 endif
365 if (exists('revision'))
365 if (exists('revision'))
@@ -478,111 +478,96 b' endfunction'
478 " 1 if new document installed, 0 otherwise.
478 " 1 if new document installed, 0 otherwise.
479 " Note: Cleaned and generalized by guo-peng Wen
479 " Note: Cleaned and generalized by guo-peng Wen
480 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
480 "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
481 " Helper function to make mkdir as portable as possible
482 function! s:HGFlexiMkdir(dir)
483 if exists("*mkdir") " we can use Vim's own mkdir()
484 call mkdir(a:dir)
485 elseif !exists("+shellslash")
486 call system('mkdir -p "'.a:dir.'"')
487 else " M$
488 let l:ssl = &shellslash
489 try
490 set shellslash
491 call system('mkdir "'.a:dir.'"')
492 finally
493 let &shellslash = l:ssl
494 endtry
495 endif
496 endfunction
481
497
482 function! s:HGInstallDocumentation(full_name, revision)
498 function! s:HGInstallDocumentation(full_name, revision)
483 " Name of the document path based on the system we use:
499 " Figure out document path based on full name of this script:
484 if (has("unix"))
500 let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
485 " On UNIX like system, using forward slash:
501 let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . "/doc"
486 let l:slash_char = '/'
502 if filewritable(l:vim_doc_path) != 2
487 let l:mkdir_cmd = ':silent !mkdir -p '
503 echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
488 else
504 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
489 " On M$ system, use backslash. Also mkdir syntax is different.
505 if filewritable(l:vim_doc_path) != 2
490 " This should only work on W2K and up.
506 " Try first item in 'runtimepath':
491 let l:slash_char = '\'
507 let l:vimfiles = matchstr(&runtimepath, '[^,]\+\ze,')
492 let l:mkdir_cmd = ':silent !mkdir '
508 let l:vim_doc_path = l:vimfiles . "/doc"
509 if filewritable(l:vim_doc_path) != 2
510 echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
511 silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
512 if filewritable(l:vim_doc_path) != 2
513 " Put a warning:
514 echomsg "Unable to open documentation directory"
515 echomsg " type `:help add-local-help' for more information."
516 return 0
517 endif
518 endif
493 endif
519 endif
494
520 endif
495 let l:doc_path = l:slash_char . 'doc'
496 let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc'
497
521
498 " Figure out document path based on full name of this script:
522 " Full name of script and documentation file:
499 let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
523 let l:script_name = fnamemodify(a:full_name, ':t')
500 let l:vim_doc_path = fnamemodify(a:full_name, ':h:h') . l:doc_path
524 let l:doc_name = fnamemodify(a:full_name, ':t:r') . '.txt'
501 if (!(filewritable(l:vim_doc_path) == 2))
525 let l:doc_file = l:vim_doc_path . "/" . l:doc_name
502 echomsg "Doc path: " . l:vim_doc_path
503 execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
504 if (!(filewritable(l:vim_doc_path) == 2))
505 " Try a default configuration in user home:
506 let l:vim_doc_path = expand("~") . l:doc_home
507 if (!(filewritable(l:vim_doc_path) == 2))
508 execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
509 if (!(filewritable(l:vim_doc_path) == 2))
510 " Put a warning:
511 echomsg "Unable to open documentation directory"
512 echomsg " type :help add-local-help for more informations."
513 return 0
514 endif
515 endif
516 endif
517 endif
518
526
519 " Exit if we have problem to access the document directory:
527 " Bail out if document file is still up to date:
520 if (!isdirectory(l:vim_plugin_path)
528 if filereadable(l:doc_file) && getftime(a:full_name) < getftime(l:doc_file)
521 \ || !isdirectory(l:vim_doc_path)
529 return 0
522 \ || filewritable(l:vim_doc_path) != 2)
530 endif
523 return 0
524 endif
525
526 " Full name of script and documentation file:
527 let l:script_name = fnamemodify(a:full_name, ':t')
528 let l:doc_name = fnamemodify(a:full_name, ':t:r') . '.txt'
529 let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name
530 let l:doc_file = l:vim_doc_path . l:slash_char . l:doc_name
531
531
532 " Bail out if document file is still up to date:
532 " Create a new buffer & read in the plugin file (me):
533 if (filereadable(l:doc_file) &&
533 setl nomodeline
534 \ getftime(l:plugin_file) < getftime(l:doc_file))
534 1 new!
535 return 0
535 setl noswapfile modifiable
536 endif
536 sil exe 'read ' . a:full_name
537
537
538 " Prepare window position restoring command:
538 setl modeline
539 if (strlen(@%))
539 let l:buf = bufnr("%")
540 let l:go_back = 'b ' . bufnr("%")
541 else
542 let l:go_back = 'enew!'
543 endif
544
540
545 " Create a new buffer & read in the plugin file (me):
541 norm zR
546 setl nomodeline
542 norm gg
547 exe 'enew!'
548 exe 'r ' . l:plugin_file
549
543
550 setl modeline
544 " Delete from first line to a line starts with
551 let l:buf = bufnr("%")
545 " === START_DOC
552 setl noswapfile modifiable
546 sil 1,/^=\{3,}\s\+START_DOC\C/ d
553
554 norm zR
555 norm gg
556
547
557 " Delete from first line to a line starts with
548 " Delete from a line starts with
558 " === START_DOC
549 " === END_DOC
559 1,/^=\{3,}\s\+START_DOC\C/ d
550 " to the end of the documents:
551 sil /^=\{3,}\s\+END_DOC\C/,$ d
560
552
561 " Delete from a line starts with
553 " Remove fold marks:
562 " === END_DOC
554 sil %s/{\{3}[1-9]/ /e
563 " to the end of the documents:
564 /^=\{3,}\s\+END_DOC\C/,$ d
565
566 " Remove fold marks:
567 %s/{\{3}[1-9]/ /
568
555
569 " Add modeline for help doc: the modeline string is mangled intentionally
556 " Add modeline for help doc: the modeline string is mangled intentionally
570 " to avoid it be recognized by VIM:
557 " to avoid it be recognized by VIM:
571 call append(line('$'), '')
558 call append(line('$'), '')
572 call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
559 call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
573
560
574 " Replace revision:
561 " Replace revision:
575 exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
562 sil exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
576
563
577 " Save the help document:
564 " Save the help document and wipe out buffer:
578 exe 'w! ' . l:doc_file
565 sil exe 'wq! ' . l:doc_file . ' | bw ' . l:buf
579 exe l:go_back
580 exe 'bw ' . l:buf
581
566
582 " Build help tags:
567 " Build help tags:
583 exe 'helptags ' . l:vim_doc_path
568 sil exe 'helptags ' . l:vim_doc_path
584
569
585 return 1
570 return 1
586 endfunction
571 endfunction
587
572
588 " Section: Public functions {{{1
573 " Section: Public functions {{{1
@@ -1185,13 +1170,16 b' endif'
1185 " Section: Doc installation {{{1
1170 " Section: Doc installation {{{1
1186 "
1171 "
1187 let s:revision="0.1"
1172 let s:revision="0.1"
1188 silent! let s:install_status =
1173 if s:HGInstallDocumentation(escape(expand('<sfile>:p'), ' '), s:revision)
1189 \ s:HGInstallDocumentation(expand('<sfile>:p'), s:revision)
1174 echom expand('<sfile>:t:r') . ' v' . s:revision .
1190 if (s:install_status == 1)
1175 \ ': Help-documentation installed.'
1191 echom expand("<sfile>:t:r") . ' v' . s:revision .
1192 \ ': Help-documentation installed.'
1193 endif
1176 endif
1194
1177
1178 " delete one-time vars and functions
1179 delfunction <SID>HGInstallDocumentation
1180 delfunction <SID>HGFlexiMkdir
1181 unlet s:revision
1182
1195
1183
1196 " Section: Plugin completion {{{1
1184 " Section: Plugin completion {{{1
1197
1185
@@ -1638,7 +1626,7 b' 5.5 HGCommand buffer management\t\t '
1638 status' will be invoked at each entry into a buffer (during the |BufEnter|
1626 status' will be invoked at each entry into a buffer (during the |BufEnter|
1639 autocommand).
1627 autocommand).
1640
1628
1641 This mode is enablmed by default. In order to disable it, set the
1629 This mode is enabled by default. In order to disable it, set the
1642 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
1630 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
1643 this mode simply provides the buffer variables mentioned above. The user
1631 this mode simply provides the buffer variables mentioned above. The user
1644 must explicitly include those in the |'statusline'| option if they are to
1632 must explicitly include those in the |'statusline'| option if they are to
General Comments 0
You need to be logged in to leave comments. Login now