[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mercurial
Subject:    Fwd: [PATCH] hgcommand.vim: cleanup of doc self-install code
From:       "Mathieu Clabaut" <mathieu.clabaut () gmail ! com>
Date:       2006-07-28 22:19:06
Message-ID: db9360ca0607281519n46f8f167s4e9810ddf3219452 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hereafter is a nice cleanup patch  to contrib/vim/hgcommand.vim, from
Christian Ebert. It would probably be happier in crew than in my mbox :-)

-mathieu


---------- Forwarded message ----------
From: Christian Ebert <blacktrash@gmx.net>
Date: Jul 28, 2006 9:56 PM
Subject: [PATCH] hgcommand.vim: cleanup of doc self-install code
To: Mathieu Clabaut <mathieu.clabaut@gmail.com>

# HG changeset patch
# User Christian Ebert <blacktrash@gmx.net>
# Date 1154116351 -7200
# Node ID 744ec0a1f0bfeec905426a29a688b248790ee936
# Parent  d1fa79e7b07e0b812d009fcdf78e0dbe9758aa07
hgcommand.vim: cleanup of doc self-install code

diff -r d1fa79e7b07e -r 744ec0a1f0bf contrib/vim/hgcommand.vim
--- a/contrib/vim/hgcommand.vim Fri Jul 28 10:47:02 2006 -0700
+++ b/contrib/vim/hgcommand.vim Fri Jul 28 21:52:31 2006 +0200
@@ -353,13 +353,13 @@ function! s:HGGetStatusVars(revisionVar,
       let hgCommand = s:HGGetOption("HGCommandHGExec", "hg") . " parents
-b  "
       let statustext=system(hgCommand)
       if(v:shell_error)
-         return ""
+          return ""
       endif
       let revision=substitute(statustext,
'^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', "")

       if a:branchVar != "" && match(statustext, '^\_.*\_^branch:') >= 0
-       let branch=substitute(statustext,
'^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
-       let returnExpression=returnExpression . " | let " . a:branchVar .
"='" . branch . "'"
+        let branch=substitute(statustext,
'^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', "")
+        let returnExpression=returnExpression . " | let " . a:branchVar .
"='" . branch . "'"
       endif
     endif
     if (exists('revision'))
@@ -478,111 +478,96 @@ endfunction
"   1 if new document installed, 0 otherwise.
" Note: Cleaned and generalized by guo-peng Wen
"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+" Helper function to make mkdir as portable as possible
+function! s:HGFlexiMkdir(dir)
+  if exists("*mkdir") " we can use Vim's own mkdir()
+    call mkdir(a:dir)
+  elseif !exists("+shellslash")
+    call system('mkdir -p "'.a:dir.'"')
+  else " M$
+    let l:ssl = &shellslash
+    try
+      set shellslash
+      call system('mkdir "'.a:dir.'"')
+    finally
+      let &shellslash = l:ssl
+    endtry
+  endif
+endfunction

function! s:HGInstallDocumentation(full_name, revision)
-    " Name of the document path based on the system we use:
-    if (has("unix"))
-        " On UNIX like system, using forward slash:
-        let l:slash_char = '/'
-        let l:mkdir_cmd  = ':silent !mkdir -p '
-    else
-        " On M$ system, use backslash. Also mkdir syntax is different.
-        " This should only work on W2K and up.
-        let l:slash_char = '\'
-        let l:mkdir_cmd  = ':silent !mkdir '
-    endif
-
-    let l:doc_path = l:slash_char . 'doc'
-    let l:doc_home = l:slash_char . '.vim' . l:slash_char . 'doc'
-
-    " Figure out document path based on full name of this script:
-    let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
-    let l:vim_doc_path    = fnamemodify(a:full_name, ':h:h') . l:doc_path
-    if (!(filewritable(l:vim_doc_path) == 2))
-        echomsg "Doc path: " . l:vim_doc_path
-        execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
-        if (!(filewritable(l:vim_doc_path) == 2))
-            " Try a default configuration in user home:
-            let l:vim_doc_path = expand("~") . l:doc_home
-            if (!(filewritable(l:vim_doc_path) == 2))
-                execute l:mkdir_cmd . '"' . l:vim_doc_path . '"'
-                if (!(filewritable(l:vim_doc_path) == 2))
-                    " Put a warning:
-                    echomsg "Unable to open documentation directory"
-                    echomsg " type :help add-local-help for more
informations."
-                    return 0
-                endif
-            endif
+  " Figure out document path based on full name of this script:
+  let l:vim_plugin_path = fnamemodify(a:full_name, ':h')
+  let l:vim_doc_path  = fnamemodify(a:full_name, ':h:h') . "/doc"
+  if filewritable(l:vim_doc_path) != 2
+    echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
+    silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
+    if filewritable(l:vim_doc_path) != 2
+      " Try first item in 'runtimepath':
+      let l:vimfiles = matchstr(&runtimepath, '[^,]\+\ze,')
+      let l:vim_doc_path = l:vimfiles . "/doc"
+      if filewritable(l:vim_doc_path) != 2
+        echomsg "hgcommand: Trying to update docs at: " . l:vim_doc_path
+        silent! call <SID>HGFlexiMkdir(l:vim_doc_path)
+        if filewritable(l:vim_doc_path) != 2
+          " Put a warning:
+          echomsg "Unable to open documentation directory"
+          echomsg " type `:help add-local-help' for more information."
+          return 0
         endif
-    endif
-
-    " Exit if we have problem to access the document directory:
-    if (!isdirectory(l:vim_plugin_path)
-        \ || !isdirectory(l:vim_doc_path)
-        \ || filewritable(l:vim_doc_path) != 2)
-        return 0
-    endif
-
-    " Full name of script and documentation file:
-    let l:script_name = fnamemodify(a:full_name, ':t')
-    let l:doc_name    = fnamemodify(a:full_name, ':t:r') . '.txt'
-    let l:plugin_file = l:vim_plugin_path . l:slash_char . l:script_name
-    let l:doc_file    = l:vim_doc_path    . l:slash_char . l:doc_name
-
-    " Bail out if document file is still up to date:
-    if (filereadable(l:doc_file)  &&
-        \ getftime(l:plugin_file) < getftime(l:doc_file))
-        return 0
-    endif
-
-    " Prepare window position restoring command:
-    if (strlen(@%))
-        let l:go_back = 'b ' . bufnr("%")
-    else
-        let l:go_back = 'enew!'
-    endif
-
-    " Create a new buffer & read in the plugin file (me):
-    setl nomodeline
-    exe 'enew!'
-    exe 'r ' . l:plugin_file
-
-    setl modeline
-    let l:buf = bufnr("%")
-    setl noswapfile modifiable
-
-    norm zR
-    norm gg
-
-    " Delete from first line to a line starts with
-    " === START_DOC
-    1,/^=\{3,}\s\+START_DOC\C/ d
-
-    " Delete from a line starts with
-    " === END_DOC
-    " to the end of the documents:
-    /^=\{3,}\s\+END_DOC\C/,$ d
-
-    " Remove fold marks:
-    %s/{\{3}[1-9]/    /
-
-    " Add modeline for help doc: the modeline string is mangled
intentionally
-    " to avoid it be recognized by VIM:
-    call append(line('$'), '')
-    call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
-
-    " Replace revision:
-    exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
-
-    " Save the help document:
-    exe 'w! ' . l:doc_file
-    exe l:go_back
-    exe 'bw ' . l:buf
-
-    " Build help tags:
-    exe 'helptags ' . l:vim_doc_path
-
-    return 1
+      endif
+    endif
+  endif
+
+  " Full name of script and documentation file:
+  let l:script_name = fnamemodify(a:full_name, ':t')
+  let l:doc_name  = fnamemodify(a:full_name, ':t:r') . '.txt'
+  let l:doc_file  = l:vim_doc_path . "/" . l:doc_name
+
+  " Bail out if document file is still up to date:
+  if filereadable(l:doc_file)  && getftime(a:full_name) <
getftime(l:doc_file)
+    return 0
+  endif
+
+  " Create a new buffer & read in the plugin file (me):
+  setl nomodeline
+  1 new!
+  setl noswapfile modifiable
+  sil exe 'read ' . a:full_name
+
+  setl modeline
+  let l:buf = bufnr("%")
+
+  norm zR
+  norm gg
+
+  " Delete from first line to a line starts with
+  " === START_DOC
+  sil 1,/^=\{3,}\s\+START_DOC\C/ d
+
+  " Delete from a line starts with
+  " === END_DOC
+  " to the end of the documents:
+  sil /^=\{3,}\s\+END_DOC\C/,$ d
+
+  " Remove fold marks:
+  sil %s/{\{3}[1-9]/  /e
+
+  " Add modeline for help doc: the modeline string is mangled intentionally
+  " to avoid it be recognized by VIM:
+  call append(line('$'), '')
+  call append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')
+
+  " Replace revision:
+  sil exe "normal :1s/#version#/ v" . a:revision . "/\<CR>"
+
+  " Save the help document and wipe out buffer:
+  sil exe 'wq! ' . l:doc_file . ' | bw ' . l:buf
+
+  " Build help tags:
+  sil exe 'helptags ' . l:vim_doc_path
+
+  return 1
endfunction

" Section: Public functions {{{1
@@ -1185,12 +1170,15 @@ endif
" Section: Doc installation {{{1
"
   let s:revision="0.1"
-  silent! let s:install_status =
-      \ s:HGInstallDocumentation(expand('<sfile>:p'), s:revision)
-  if (s:install_status == 1)
-      echom expand("<sfile>:t:r") . ' v' . s:revision .
-               \ ': Help-documentation installed.'
-  endif
+  if s:HGInstallDocumentation(escape(expand('<sfile>:p'), ' '), s:revision)
+      echom expand('<sfile>:t:r') . ' v' . s:revision .
+                \ ': Help-documentation installed.'
+  endif
+
+  " delete one-time vars and functions
+  delfunction <SID>HGInstallDocumentation
+  delfunction <SID>HGFlexiMkdir
+  unlet s:revision


" Section: Plugin completion {{{1
@@ -1638,7 +1626,7 @@ 5.5 HGCommand buffer management
    status' will be invoked at each entry into a buffer (during the
|BufEnter|
    autocommand).

-   This mode is enablmed by default.  In order to disable it, set the
+   This mode is enabled by default.  In order to disable it, set the
    |HGCommandEnableBufferSetup| variable to a false (zero) value.  Enabling
    this mode simply provides the buffer variables mentioned above.  The
user
    must explicitly include those in the |'statusline'| option if they are
to

[Attachment #5 (text/html)]

Hereafter is a nice cleanup patch&nbsp; to contrib/vim/hgcommand.vim, from Christian \
Ebert. It would probably be happier in crew than in my mbox \
:-)<br><br>-mathieu<br><br><br>---------- Forwarded message ----------<br><span \
                class="gmail_quote">
From: <b class="gmail_sendername">Christian Ebert</b> &lt;<a \
href="mailto:blacktrash@gmx.net">blacktrash@gmx.net</a>&gt;<br>Date: Jul 28, 2006 \
                9:56 PM<br>Subject: [PATCH] hgcommand.vim: cleanup of doc \
                self-install code<br>
To: Mathieu Clabaut &lt;<a \
href="mailto:mathieu.clabaut@gmail.com">mathieu.clabaut@gmail.com</a>&gt;<br><br></span># \
HG changeset patch<br># User Christian Ebert &lt;<a \
href="mailto:blacktrash@gmx.net">blacktrash@gmx.net</a> &gt;<br># Date 1154116351 \
-7200<br># Node ID 744ec0a1f0bfeec905426a29a688b248790ee936<br># \
Parent&nbsp;&nbsp;d1fa79e7b07e0b812d009fcdf78e0dbe9758aa07<br>hgcommand.vim: cleanup \
of doc self-install code<br><br>diff -r d1fa79e7b07e -r 744ec0a1f0bf \
contrib/vim/hgcommand.vim <br>--- a/contrib/vim/hgcommand.vim Fri Jul 28 10:47:02 \
2006 -0700<br>+++ b/contrib/vim/hgcommand.vim Fri Jul 28 21:52:31 2006 +0200<br>@@ \
-353,13 +353,13 @@ function! \
s:HGGetStatusVars(revisionVar,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let hgCommand \
= s:HGGetOption(&quot;HGCommandHGExec&quot;, &quot;hg&quot;) . &quot; parents \
-b&nbsp;&nbsp;&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let \
statustext=system(hgCommand)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
if(v:shell_error)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return \
&quot;&quot;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return \
&quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
endif<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let revision=substitute(statustext, \
'^changeset:\s*\(\d\+\):.*\_$\_.*$', '\1', &quot;&quot;) \
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if a:branchVar != &quot;&quot; \
&amp;&amp; match(statustext, '^\_.*\_^branch:') &gt;= \
0<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let branch=substitute(statustext, \
'^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', \
&quot;&quot;)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let \
returnExpression=returnExpression . &quot; | let &quot; . a:branchVar . \
&quot;='&quot; . branch . &quot;'&quot; \
<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
branch=substitute(statustext, '^\_.*\_^branch:\s*\(\S\+\)\n\_.*$', '\1', \
&quot;&quot;)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
returnExpression=returnExpression . &quot; | let &quot; . a:branchVar . \
&quot;='&quot; . branch . &quot;'&quot; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
endif<br>&nbsp;&nbsp;&nbsp;&nbsp; endif<br>&nbsp;&nbsp;&nbsp;&nbsp; if \
(exists('revision'))<br>@@ -478,111 +478,96 @@ endfunction<br> &quot;&nbsp;&nbsp; 1 \
if new document installed, 0 otherwise.<br> &quot; Note: Cleaned and generalized by \
guo-peng Wen<br> &quot;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 <br>+&quot; Helper function to make mkdir as portable as possible<br>+function! \
s:HGFlexiMkdir(dir)<br>+&nbsp;&nbsp;if exists(&quot;*mkdir&quot;) &quot; we can use \
Vim's own mkdir()<br>+&nbsp;&nbsp;&nbsp;&nbsp;call \
mkdir(a:dir)<br>+&nbsp;&nbsp;elseif !exists(&quot;+shellslash&quot;) \
<br>+&nbsp;&nbsp;&nbsp;&nbsp;call system('mkdir -p \
&quot;'.a:dir.'&quot;')<br>+&nbsp;&nbsp;else &quot; \
M$<br>+&nbsp;&nbsp;&nbsp;&nbsp;let l:ssl = \
&amp;shellslash<br>+&nbsp;&nbsp;&nbsp;&nbsp;try<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set \
shellslash<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;call system('mkdir \
&quot;'.a:dir.'&quot;')<br>+&nbsp;&nbsp;&nbsp;&nbsp;finally<br> \
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let &amp;shellslash = \
l:ssl<br>+&nbsp;&nbsp;&nbsp;&nbsp;endtry<br>+&nbsp;&nbsp;endif<br>+endfunction<br><br> \
function! s:HGInstallDocumentation(full_name, \
revision)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Name of the document path based on the \
system we use:<br>-&nbsp;&nbsp;&nbsp;&nbsp;if (has(&quot;unix&quot;)) \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; On UNIX like system, \
using forward slash:<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
l:slash_char = '/'<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
l:mkdir_cmd&nbsp;&nbsp;= ':silent !mkdir -p \
'<br>-&nbsp;&nbsp;&nbsp;&nbsp;else<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
On M$ system, use backslash. Also mkdir syntax is different. \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; This should only work on \
W2K and up.<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let l:slash_char = \
'\'<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let l:mkdir_cmd&nbsp;&nbsp;= \
':silent !mkdir '<br>-&nbsp;&nbsp;&nbsp;&nbsp;endif<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;let \
l:doc_path = l:slash_char . 'doc'<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:doc_home = \
l:slash_char . '.vim' . l:slash_char . 'doc' <br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
Figure out document path based on full name of this \
script:<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:vim_plugin_path = fnamemodify(a:full_name, \
':h')<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:vim_doc_path&nbsp;&nbsp;&nbsp;&nbsp;= \
fnamemodify(a:full_name, ':h:h') . l:doc_path <br>-&nbsp;&nbsp;&nbsp;&nbsp;if \
(!(filewritable(l:vim_doc_path) == \
2))<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg &quot;Doc path: \
&quot; . l:vim_doc_path<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;execute \
l:mkdir_cmd . '&quot;' . l:vim_doc_path . \
'&quot;'<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if \
(!(filewritable(l:vim_doc_path) == 2)) \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
Try a default configuration in user \
home:<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
l:vim_doc_path = expand(&quot;~&quot;) . \
l:doc_home<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if \
(!(filewritable(l:vim_doc_path) == \
2))<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;execute \
l:mkdir_cmd . '&quot;' . l:vim_doc_path . '&quot;' \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if \
(!(filewritable(l:vim_doc_path) == \
2))<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
Put a warning:<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg \
&quot;Unable to open documentation \
directory&quot;<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg \
&quot; type :help add-local-help for more informations.&quot; \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return \
0<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n \
bsp;&nbsp;&nbsp;endif<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endif<br>+&nbsp;&nbsp;&quot; \
Figure out document path based on full name of this script:<br>+&nbsp;&nbsp;let \
l:vim_plugin_path = fnamemodify(a:full_name, ':h')<br>+&nbsp;&nbsp;let \
l:vim_doc_path&nbsp;&nbsp;= fnamemodify(a:full_name, ':h:h') . &quot;/doc&quot; \
<br>+&nbsp;&nbsp;if filewritable(l:vim_doc_path) != \
2<br>+&nbsp;&nbsp;&nbsp;&nbsp;echomsg &quot;hgcommand: Trying to update docs at: \
&quot; . l:vim_doc_path<br>+&nbsp;&nbsp;&nbsp;&nbsp;silent! call \
&lt;SID&gt;HGFlexiMkdir(l:vim_doc_path)<br>+&nbsp;&nbsp;&nbsp;&nbsp;if \
filewritable(l:vim_doc_path) != 2 <br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; Try \
first item in 'runtimepath':<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let l:vimfiles = \
matchstr(&amp;runtimepath, '[^,]\+\ze,')<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
l:vim_doc_path = l:vimfiles . \
&quot;/doc&quot;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if \
filewritable(l:vim_doc_path) != 2 \
<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg &quot;hgcommand: Trying \
to update docs at: &quot; . \
l:vim_doc_path<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;silent! call \
&lt;SID&gt;HGFlexiMkdir(l:vim_doc_path)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if \
filewritable(l:vim_doc_path) != \
2<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot; Put a \
warning: <br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg \
&quot;Unable to open documentation \
directory&quot;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echomsg \
&quot; type `:help add-local-help' for more \
information.&quot;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return \
0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
                endif<br>-&nbsp;&nbsp;&nbsp;&nbsp;endif<br>-<br>
-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Exit if we have problem to access the document \
directory:<br>-&nbsp;&nbsp;&nbsp;&nbsp;if \
(!isdirectory(l:vim_plugin_path)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ \
|| !isdirectory(l:vim_doc_path)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ \
|| filewritable(l:vim_doc_path) != \
2)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0 \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;endif<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Full name \
of script and documentation file:<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:script_name = \
fnamemodify(a:full_name, ':t')<br>-&nbsp;&nbsp;&nbsp;&nbsp;let \
l:doc_name&nbsp;&nbsp;&nbsp;&nbsp;= fnamemodify(a:full_name, ':t:r') . \
'.txt'<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:plugin_file = l:vim_plugin_path . \
l:slash_char . l:script_name <br>-&nbsp;&nbsp;&nbsp;&nbsp;let \
l:doc_file&nbsp;&nbsp;&nbsp;&nbsp;= l:vim_doc_path&nbsp;&nbsp;&nbsp;&nbsp;. \
l:slash_char . l:doc_name<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Bail out if \
document file is still up to date:<br>-&nbsp;&nbsp;&nbsp;&nbsp;if \
(filereadable(l:doc_file)&nbsp;&nbsp;&amp;&amp;<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ \
getftime(l:plugin_file) &lt; getftime(l:doc_file)) \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return \
0<br>-&nbsp;&nbsp;&nbsp;&nbsp;endif<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Prepare \
window position restoring command:<br>-&nbsp;&nbsp;&nbsp;&nbsp;if \
(strlen(@%))<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let l:go_back = 'b ' \
. bufnr(&quot;%&quot;)<br>-&nbsp;&nbsp;&nbsp;&nbsp;else<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let \
l:go_back = 'enew!' <br>-&nbsp;&nbsp;&nbsp;&nbsp;endif<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
Create a new buffer &amp; read in the plugin file \
(me):<br>-&nbsp;&nbsp;&nbsp;&nbsp;setl nomodeline<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe \
'enew!'<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe 'r ' . \
l:plugin_file<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;setl \
modeline<br>-&nbsp;&nbsp;&nbsp;&nbsp;let l:buf = bufnr(&quot;%&quot;) \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;setl noswapfile \
modifiable<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;norm zR<br>-&nbsp;&nbsp;&nbsp;&nbsp;norm \
gg<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Delete from first line to a line starts \
with<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; === \
START_DOC<br>-&nbsp;&nbsp;&nbsp;&nbsp;1,/^=\{3,}\s\+START_DOC\C/ \
d<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Delete from a line starts with \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; === END_DOC<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; to \
the end of the documents:<br>-&nbsp;&nbsp;&nbsp;&nbsp;/^=\{3,}\s\+END_DOC\C/,$ \
d<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Remove fold \
marks:<br>-&nbsp;&nbsp;&nbsp;&nbsp;%s/{\{3}[1-9]/&nbsp;&nbsp;&nbsp;&nbsp;/<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; \
Add modeline for help doc: the modeline string is mangled intentionally \
<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; to avoid it be recognized by \
VIM:<br>-&nbsp;&nbsp;&nbsp;&nbsp;call append(line('$'), \
'')<br>-&nbsp;&nbsp;&nbsp;&nbsp;call append(line('$'), ' v' . \
'im:tw=78:ts=8:ft=help:norl:')<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Replace \
revision:<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe &quot;normal :1s/#version#/ v&quot; . \
a:revision . &quot;/\&lt;CR&gt;&quot; <br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Save \
the help document:<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe 'w! ' . \
l:doc_file<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe l:go_back<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe \
'bw ' . l:buf<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;&quot; Build help \
tags:<br>-&nbsp;&nbsp;&nbsp;&nbsp;exe 'helptags ' . \
l:vim_doc_path<br>-<br>-&nbsp;&nbsp;&nbsp;&nbsp;return 1 \
<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endif<br>+&nbsp;&nbsp;&nbsp;&nbsp;endif<br>+&nbsp;&nbsp;endif<br>+<br>+&nbsp;&nbsp;&quot; \
Full name of script and documentation file:<br>+&nbsp;&nbsp;let l:script_name = \
fnamemodify(a:full_name, ':t')<br>+&nbsp;&nbsp;let l:doc_name&nbsp;&nbsp;= \
fnamemodify(a:full_name, ':t:r') . '.txt' <br>+&nbsp;&nbsp;let \
l:doc_file&nbsp;&nbsp;= l:vim_doc_path . &quot;/&quot; . \
l:doc_name<br>+<br>+&nbsp;&nbsp;&quot; Bail out if document file is still up to \
date:<br>+&nbsp;&nbsp;if filereadable(l:doc_file)&nbsp;&nbsp;&amp;&amp; \
getftime(a:full_name) &lt; getftime(l:doc_file) <br>+&nbsp;&nbsp;&nbsp;&nbsp;return \
0<br>+&nbsp;&nbsp;endif<br>+<br>+&nbsp;&nbsp;&quot; Create a new buffer &amp; read in \
the plugin file (me):<br>+&nbsp;&nbsp;setl nomodeline<br>+&nbsp;&nbsp;1 \
new!<br>+&nbsp;&nbsp;setl noswapfile modifiable<br>+&nbsp;&nbsp;sil exe 'read ' . \
a:full_name<br>+<br>+&nbsp;&nbsp;setl modeline <br>+&nbsp;&nbsp;let l:buf = \
bufnr(&quot;%&quot;)<br>+<br>+&nbsp;&nbsp;norm zR<br>+&nbsp;&nbsp;norm \
gg<br>+<br>+&nbsp;&nbsp;&quot; Delete from first line to a line starts \
with<br>+&nbsp;&nbsp;&quot; === START_DOC<br>+&nbsp;&nbsp;sil \
1,/^=\{3,}\s\+START_DOC\C/ d<br>+<br>+&nbsp;&nbsp;&quot; Delete from a line starts \
with <br>+&nbsp;&nbsp;&quot; === END_DOC<br>+&nbsp;&nbsp;&quot; to the end of the \
documents:<br>+&nbsp;&nbsp;sil /^=\{3,}\s\+END_DOC\C/,$ d<br>+<br>+&nbsp;&nbsp;&quot; \
Remove fold marks:<br>+&nbsp;&nbsp;sil \
%s/{\{3}[1-9]/&nbsp;&nbsp;/e<br>+<br>+&nbsp;&nbsp;&quot; Add modeline for help doc: \
the modeline string is mangled intentionally <br>+&nbsp;&nbsp;&quot; to avoid it be \
recognized by VIM:<br>+&nbsp;&nbsp;call append(line('$'), '')<br>+&nbsp;&nbsp;call \
append(line('$'), ' v' . 'im:tw=78:ts=8:ft=help:norl:')<br>+<br>+&nbsp;&nbsp;&quot; \
Replace revision:<br>+&nbsp;&nbsp;sil exe &quot;normal :1s/#version#/ v&quot; . \
a:revision . &quot;/\&lt;CR&gt;&quot; <br>+<br>+&nbsp;&nbsp;&quot; Save the help \
document and wipe out buffer:<br>+&nbsp;&nbsp;sil exe 'wq! ' . l:doc_file . ' | bw ' \
. l:buf<br>+<br>+&nbsp;&nbsp;&quot; Build help tags:<br>+&nbsp;&nbsp;sil exe \
'helptags ' . l:vim_doc_path<br>+<br>+&nbsp;&nbsp;return 1<br> endfunction <br><br> \
&quot; Section: Public functions {{{1<br>@@ -1185,12 +1170,15 @@ endif<br> &quot; \
Section: Doc installation {{{1<br> &quot;<br>&nbsp;&nbsp; let \
s:revision=&quot;0.1&quot;<br>-&nbsp;&nbsp;silent! let s:install_status \
=<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ \
s:HGInstallDocumentation(expand('&lt;sfile&gt;:p'), s:revision) <br>-&nbsp;&nbsp;if \
(s:install_status == 1)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echom \
expand(&quot;&lt;sfile&gt;:t:r&quot;) . ' v' . s:revision \
.<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
\ ': Help-documentation installed.'<br>-&nbsp;&nbsp;endif<br>+&nbsp;&nbsp;if \
s:HGInstallDocumentation(escape(expand('&lt;sfile&gt;:p'), ' '), s:revision) \
<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echom expand('&lt;sfile&gt;:t:r') . ' v' . \
s:revision .<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\ \
': Help-documentation installed.'<br>+&nbsp;&nbsp;endif<br>+<br>+&nbsp;&nbsp;&quot; \
delete one-time vars and functions<br>+&nbsp;&nbsp;delfunction \
&lt;SID&gt;HGInstallDocumentation <br>+&nbsp;&nbsp;delfunction \
&lt;SID&gt;HGFlexiMkdir<br>+&nbsp;&nbsp;unlet s:revision<br><br><br> &quot; Section: \
Plugin completion {{{1<br>@@ -1638,7 +1626,7 @@ 5.5 HGCommand buffer \
management<br>&nbsp;&nbsp;&nbsp;&nbsp;status' will be invoked at each entry into a \
buffer (during the |BufEnter| \
<br>&nbsp;&nbsp;&nbsp;&nbsp;autocommand).<br><br>-&nbsp;&nbsp; This mode is enablmed \
by default.&nbsp;&nbsp;In order to disable it, set the<br>+&nbsp;&nbsp; This mode is \
enabled by default.&nbsp;&nbsp;In order to disable it, set \
the<br>&nbsp;&nbsp;&nbsp;&nbsp;|HGCommandEnableBufferSetup| variable to a false \
(zero) value.&nbsp;&nbsp;Enabling <br>&nbsp;&nbsp;&nbsp;&nbsp;this mode simply \
provides the buffer variables mentioned above.&nbsp;&nbsp;The \
user<br>&nbsp;&nbsp;&nbsp;&nbsp;must explicitly include those in the |'statusline'| \
option if they are to<br>



_______________________________________________
Mercurial mailing list
Mercurial@selenic.com
http://selenic.com/mailman/listinfo/mercurial


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic