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