diff --git a/README b/README deleted file mode 100644 index 22f74bd..0000000 --- a/README +++ /dev/null @@ -1,42 +0,0 @@ -This is a mirror of http://www.vim.org/scripts/script.php?script_id=1355 - -PDV (phpDocumentor for Vim) -======================== - -Version: 1.0.0 - -Copyright 2005 by Tobias Schlitt -Inspired by phpDoc script for Vim by Vidyut Luther (http://www.phpcult.com/). - -Provided under the GPL (http://www.gnu.org/copyleft/gpl.html). - -This script provides functions to generate phpDocumentor conform -documentation blocks for your PHP code. The script currently -documents: - -- Classes -- Methods/Functions -- Attributes - -All of those supporting all PHP 4 and 5 syntax elements. - -Beside that it allows you to define default values for phpDocumentor tags -like @version (I use $id$ here), @author, @license and so on. - -For function/method parameters and attributes, the script tries to guess the -type as good as possible from PHP5 type hints or default values (array, bool, -int, string...). - -You can use this script by mapping the function PhpDoc() to any -key combination. Hit this on the line where the element to document -resides and the doc block will be created directly above that line. - -Changelog -========= - -Version 1.0.0 -------------------- - -* Created the initial version of this script while playing around with VIM - scripting the first time and trying to fix Vidyut's solution, which - resulted in a complete rewrite. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5ce369 --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +PDV (phpDocumentor for Vim) +======================== + +Forked From https://github.com/vim-scripts/PDV--phpDocumentor-for-Vim + +本项目从 `vim-scripts/PDV--phpDocumentor-for-Vim` 修改,新增支持PHP7版本 + + + +## Install + +### Pathogen + +Clone the repository under your `~/.vim/bundle/` directory: + + +``` + cd ~/.vim/bundle + git clone git://github.com/shawncplus/phpcomplete.vim.git +``` + +### Vundle + +1. Install and configure the [Vundle](https://github.com/gmarik/vundle) plugin manager, [follow the instructions here](https://github.com/gmarik/vundle#quick-start) + +2. Add the following line to your `.vimrc`: + + ``` + Plugin 'liulipeng/PDV--phpDocumentor-for-Vim' + ``` + +3. Source your `.vimrc` with `:so %` or otherwise reload your vim + +4. Run the `:PluginInstall` commmand + +## Usage + +``` sh +" 设置版本、作者、版权等信息 +let g:pdv_cfg_type="mixed" +let g:pdv_cfg_package="1.0" +let g:pdv_cfg_version="1.0" +let g:pdv_cfg_author="Lipeng Liu " +let g:pdv_cfg_copyright="1997-2017 the xxx group" +let g:pdv_cfg_license="php version 7.1" + +" 注释结束设置 +let g:pdv_cfg_eol="" +" 是否显示继承 +let g:pdv_cfg_uses=0 + +nnoremap doc :call phpdocsingle() +vnoremap doc :call phpdocrange() +``` + + + +Beside that it allows you to define default values for phpDocumentor tags +like @version (I use $id$ here), @author, @license and so on. + +For function/method parameters and attributes, the script tries to guess the +type as good as possible from PHP5 type hints or default values (array, bool, +int, string...). + +You can use this script by mapping the function PhpDoc() to any +key combination. Hit this on the line where the element to document +resides and the doc block will be created directly above that line. \ No newline at end of file diff --git a/plugin/php-doc.vim b/plugin/php-doc.vim index 1db8429..dbc632b 100644 --- a/plugin/php-doc.vim +++ b/plugin/php-doc.vim @@ -2,7 +2,7 @@ " =========================== " " Version: 1.0.1 -" +" " Copyright 2005 by Tobias Schlitt " Inspired by phpDoc script for Vim by Vidyut Luther (http://www.phpcult.com/). " @@ -11,34 +11,34 @@ " This script provides functions to generate phpDocumentor conform " documentation blocks for your PHP code. The script currently " documents: -" +" " - Classes " - Methods/Functions " - Attributes " -" All of those supporting all PHP 4 and 5 syntax elements. +" All of those supporting all PHP 4 and 5 syntax elements. " -" Beside that it allows you to define default values for phpDocumentor tags -" like @version (I use $id$ here), @author, @license and so on. +" Beside that it allows you to define default values for phpDocumentor tags +" like @version (I use $id$ here), @author, @license and so on. " -" For function/method parameters and attributes, the script tries to guess the -" type as good as possible from PHP5 type hints or default values (array, bool, +" For function/method parameters and attributes, the script tries to guess the +" type as good as possible from PHP5 type hints or default values (array, bool, " int, string...). " " You can use this script by mapping the function PhpDoc() to any " key combination. Hit this on the line where the element to document " resides and the doc block will be created directly above that line. -" +" " Installation " ============ -" +" " For example include into your .vimrc: -" +" " source ~/.vim/php-doc.vim " imap :set paste:exe PhpDoc():set nopastei " " This includes the script and maps the combination +o (only in -" insert mode) to the doc function. +" insert mode) to the doc function. " " Changelog " ========= @@ -54,14 +54,14 @@ " ------------- " * Fixed issues when using tabs instead of spaces. " * Fixed some parsing bugs when using a different coding style. -" * Fixed bug with call-by-reference parameters. +" * Fixed bug with call-by-reference parameters. " * ATTENTION: This version already has code for the next version 1.1.0, " which is propably not working! " " Version 1.1.0 (preview) " ------------- " * Added foldmarker generation. -" +" if has ("user_commands") @@ -76,16 +76,27 @@ let g:pdv_cfg_CommentSingle = "//" " Default values let g:pdv_cfg_Type = "mixed" -let g:pdv_cfg_Package = "" -let g:pdv_cfg_Version = "$id$" -let g:pdv_cfg_Author = "Tobias Schlitt " -let g:pdv_cfg_Copyright = "1997-2005 The PHP Group" -let g:pdv_cfg_License = "PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}" + +let g:pdv_cfg_Package = get(g:, + \ 'pdv_cfg_Package', "") + +let g:pdv_cfg_Version = get(g:, + \ 'pdv_cfg_Version', "$id$") + +let g:pdv_cfg_Author = get(g:, + \ 'pdv_cfg_Author', "Tobias Schlitt ") + +let g:pdv_cfg_Copyright = get(g:, + \ 'pdv_cfg_Copyright', '1997-2005 The PHP Group') + +let g:pdv_cfg_License = get(g:, + \ 'pdv_cfg_License', 'PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}') let g:pdv_cfg_ReturnVal = "void" " Wether to create @uses tags for implementation of interfaces and inheritance -let g:pdv_cfg_Uses = 1 +let g:pdv_cfg_Uses = get(g:, + \ 'pdv_cfg_Uses', 1) " Options " :set paste before documenting (1|0)? Recommended. @@ -93,7 +104,7 @@ let g:pdv_cfg_paste = 1 " Wether for PHP5 code PHP4 tags should be set, like @access,... (1|0)? let g:pdv_cfg_php4always = 1 - + " Wether to guess scopes after PEAR coding standards: " $_foo/_bar() == (1|0)? let g:pdv_cfg_php4guess = 1 @@ -103,8 +114,8 @@ let g:pdv_cfg_php4guess = 1 let g:pdv_cfg_php4guessval = "protected" " -" Regular expressions -" +" Regular expressions +" let g:pdv_re_comment = ' *\*/ *' @@ -118,7 +129,7 @@ let g:pdv_re_abstract = '\(abstract\)' let g:pdv_re_final = '\(final\)' " [:space:]*(private|protected|public|static|abstract)*[:space:]+[:identifier:]+\([:params:]\) -let g:pdv_re_func = '^\s*\([a-zA-Z ]*\)function\s\+\([^ (]\+\)\s*(\s*\(.*\)\s*)\s*[{;]\?$' +let g:pdv_re_func = '^\s*\([a-zA-Z ]*\)function\s\+\([^ (]\+\)\s*(\s*\(.*\)\s*)\(\s*:\s*[a-zA-Z]*\)\?\s*[{;]\?$' " [:typehint:]*[:space:]*$[:identifier]\([:space:]*=[:space:]*[:value:]\)? let g:pdv_re_param = ' *\([^ &]*\) *&\?\$\([A-Za-z_][A-Za-z0-9_]*\) *=\? *\(.*\)\?$' @@ -129,6 +140,7 @@ let g:pdv_re_attribute = '^\s*\(\(private\|public\|protected\|var\|static\)\+\)\ let g:pdv_re_class = '^\s*\([a-zA-Z]*\)\s*\(interface\|class\)\s*\([^ ]\+\)\s*\(extends\)\?\s*\([a-zA-Z0-9]*\)\?\s*\(implements*\)\? *\([a-zA-Z0-9_ ,]*\)\?.*$' let g:pdv_re_array = "^array *(.*" +let g:pdv_re_array_simple = "^[.*" let g:pdv_re_float = '^[0-9.]\+' let g:pdv_re_int = '^[0-9]\+$' let g:pdv_re_string = "['\"].*" @@ -138,9 +150,10 @@ let g:pdv_re_indent = '^\s*' " Shortcuts for editing the text: let g:pdv_cfg_BOL = "norm! o" -let g:pdv_cfg_EOL = "" +let g:pdv_cfg_EOL = get(g:, + \ 'pdv_cfg_EOL', " ") -" }}} +" }}} " {{{ PhpDocSingle() " Document a single line of code ( does not check if doc block already exists ) @@ -164,13 +177,13 @@ func! PhpDocRange() range " TODO: Replace regex check for existing doc with check more lines " above... if (getline(l:line) =~ g:pdv_re_func || getline(l:line) =~ g:pdv_re_attribute || getline(l:line) =~ g:pdv_re_class) && getline(l:line - 1) !~ g:pdv_re_comment - let l:docLines = 0 - " Ensure we are on the correct line to run PhpDoc() + let l:docLines = 0 + " Ensure we are on the correct line to run PhpDoc() exe "norm! " . l:line . "G$" " No matter what, this returns the element name let l:elementName = PhpDoc() let l:endLine = l:endLine + (line(".") - l:line) + 1 - let l:line = line(".") + 1 + let l:line = line(".") + 1 endif let l:line = l:line + 1 endwhile @@ -202,8 +215,8 @@ endfunc " while (l:currentLine <= line("$")) " " HERE!!!! " endwhile -" -" +" +" " endfunc @@ -215,7 +228,7 @@ func! PhpDoc() " Needed for my .vimrc: Switch off all other enhancements while generating docs let l:paste = &g:paste let &g:paste = g:pdv_cfg_paste == 1 ? 1 : &g:paste - + let l:line = getline(".") let l:result = "" @@ -243,7 +256,7 @@ func! PhpDoc() endfunc " }}} -" {{{ PhpDocFunc() +" {{{ PhpDocFunc() func! PhpDocFunc() " Line for the comment to begin @@ -260,23 +273,25 @@ func! PhpDocFunc() " Now we have to split DECL in three parts: " \[(skopemodifier\)]\(funcname\)\(parameters\) - let l:indent = matchstr(l:name, g:pdv_re_indent) - + let l:indent = matchstr(l:name, g:pdv_re_indent) + let l:modifier = substitute (l:name, g:pdv_re_func, '\1', "g") let l:funcname = substitute (l:name, g:pdv_re_func, '\2', "g") let l:parameters = substitute (l:name, g:pdv_re_func, '\3', "g") . "," - let l:scope = PhpDocScope(l:modifier, l:funcname) - let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" + let _return = substitute (l:name, g:pdv_re_func, '\4', "g") + let l:return = substitute (_return, '\s*:\s*\([a-zA-Z]*\)', '\1', "") + let l:scope = PhpDocScope(l:modifier, l:funcname) + let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" let l:abstract = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_abstract) : "" let l:final = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_final) : "" - + exe "norm! " . commentline . "G$" - + " Local indent let l:txtBOL = g:pdv_cfg_BOL . l:indent - + exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Comment1 . funcname . " " . g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Comment1 . funcname . g:pdv_cfg_EOL exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL while (l:parameters != ",") && (l:parameters != "") @@ -291,37 +306,41 @@ func! PhpDocFunc() " Parameter default let l:paramdefault = substitute (_p, g:pdv_re_param, '\3', "") - if l:paramtype == "" - let l:paramtype = PhpDocType(l:paramdefault) - endif - - if l:paramtype != "" - let l:paramtype = " " . l:paramtype - endif - exe l:txtBOL . g:pdv_cfg_Commentn . "@param" . l:paramtype . " $" . l:paramname . " " . g:pdv_cfg_EOL + if l:paramtype == "" + let l:paramtype = PhpDocType(l:paramdefault) + endif + + if l:paramtype != "" + let l:paramtype = " " . l:paramtype + endif + exe l:txtBOL . g:pdv_cfg_Commentn . "@param" . l:paramtype . " $" . l:paramname . g:pdv_cfg_EOL endwhile if l:static != "" exe l:txtBOL . g:pdv_cfg_Commentn . "@static" . g:pdv_cfg_EOL - endif + endif if l:abstract != "" exe l:txtBOL . g:pdv_cfg_Commentn . "@abstract" . g:pdv_cfg_EOL - endif + endif if l:final != "" exe l:txtBOL . g:pdv_cfg_Commentn . "@final" . g:pdv_cfg_EOL - endif - if l:scope != "" - exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL - endif - exe l:txtBOL . g:pdv_cfg_Commentn . "@return " . g:pdv_cfg_ReturnVal . g:pdv_cfg_EOL + endif + if l:scope != "" + exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL + endif + if l:return != "" + exe l:txtBOL . g:pdv_cfg_Commentn . "@return " . l:return . g:pdv_cfg_EOL + else + exe l:txtBOL . g:pdv_cfg_Commentn . "@return " . g:pdv_cfg_ReturnVal . g:pdv_cfg_EOL + endif " Close the comment block. exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL - return l:modifier ." ". l:funcname + return l:modifier ." ". l:funcname endfunc -" }}} - " {{{ PhpDocVar() +" }}} + " {{{ PhpDocVar() func! PhpDocVar() " Line for the comment to begin @@ -334,33 +353,33 @@ func! PhpDocVar() " let l:name = substitute (l:name, '\t', ' ', "") " Orphan. We're now using \s everywhere... - let l:indent = matchstr(l:name, g:pdv_re_indent) + let l:indent = matchstr(l:name, g:pdv_re_indent) let l:modifier = substitute (l:name, g:pdv_re_attribute, '\1', "g") let l:varname = substitute (l:name, g:pdv_re_attribute, '\3', "g") let l:default = substitute (l:name, g:pdv_re_attribute, '\4', "g") - let l:scope = PhpDocScope(l:modifier, l:varname) + let l:scope = PhpDocScope(l:modifier, l:varname) - let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" + let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" + + let l:type = PhpDocType(l:default) + + exe "norm! " . commentline . "G$" + + " Local indent + let l:txtBOL = g:pdv_cfg_BOL . l:indent + + exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Comment1 . l:varname . g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL + if l:static != "" + exe l:txtBOL . g:pdv_cfg_Commentn . "@static" . g:pdv_cfg_EOL + endif + exe l:txtBOL . g:pdv_cfg_Commentn . "@var " . l:type . g:pdv_cfg_EOL + if l:scope != "" + exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL + endif - let l:type = PhpDocType(l:default) - - exe "norm! " . commentline . "G$" - - " Local indent - let l:txtBOL = g:pdv_cfg_BOL . l:indent - - exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Comment1 . l:varname . " " . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL - if l:static != "" - exe l:txtBOL . g:pdv_cfg_Commentn . "@static" . g:pdv_cfg_EOL - endif - exe l:txtBOL . g:pdv_cfg_Commentn . "@var " . l:type . g:pdv_cfg_EOL - if l:scope != "" - exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL - endif - " Close the comment block. exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL return l:modifier ." ". l:varname @@ -375,7 +394,7 @@ func! PhpDocClass() let l:name = substitute (getline ("."), '^\(.*\)\/\/.*$', '\1', "") - "exe g:pdv_cfg_BOL . "DEBUG:" . name. g:pdv_cfg_EOL + "exe g:pdv_cfg_BOL . "DEBUG:" . name. g:pdv_cfg_EOL " First some things to make it more easy for us: " tab -> space && space+ -> space @@ -384,8 +403,8 @@ func! PhpDocClass() " Now we have to split DECL in three parts: " \[(skopemodifier\)]\(classname\)\(parameters\) - let l:indent = matchstr(l:name, g:pdv_re_indent) - + let l:indent = matchstr(l:name, g:pdv_re_indent) + let l:modifier = substitute (l:name, g:pdv_re_class, '\1', "g") let l:classname = substitute (l:name, g:pdv_re_class, '\3', "g") let l:extends = g:pdv_cfg_Uses == 1 ? substitute (l:name, g:pdv_re_class, '\5', "g") : "" @@ -393,18 +412,18 @@ func! PhpDocClass() let l:abstract = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_abstract) : "" let l:final = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_final) : "" - - exe "norm! " . commentline . "G$" - - " Local indent - let l:txtBOL = g:pdv_cfg_BOL . l:indent - - exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Comment1 . l:classname . " " . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL - if l:extends != "" && l:extends != "implements" - exe l:txtBOL . g:pdv_cfg_Commentn . "@uses " . l:extends . g:pdv_cfg_EOL - endif + + exe "norm! " . commentline . "G$" + + " Local indent + let l:txtBOL = g:pdv_cfg_BOL . l:indent + + exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Comment1 . l:classname . g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL + if l:extends != "" && l:extends != "implements" + exe l:txtBOL . g:pdv_cfg_Commentn . "@uses " . l:extends . g:pdv_cfg_EOL + endif while (l:interfaces != ",") && (l:interfaces != "") " Save 1st parameter @@ -415,15 +434,15 @@ func! PhpDocClass() endwhile if l:abstract != "" - exe l:txtBOL . g:pdv_cfg_Commentn . "@abstract" . g:pdv_cfg_EOL - endif + exe l:txtBOL . g:pdv_cfg_Commentn . "@abstract" . g:pdv_cfg_EOL + endif if l:final != "" - exe l:txtBOL . g:pdv_cfg_Commentn . "@final" . g:pdv_cfg_EOL - endif + exe l:txtBOL . g:pdv_cfg_Commentn . "@final" . g:pdv_cfg_EOL + endif exe l:txtBOL . g:pdv_cfg_Commentn . "@package " . g:pdv_cfg_Package . g:pdv_cfg_EOL exe l:txtBOL . g:pdv_cfg_Commentn . "@version " . g:pdv_cfg_Version . g:pdv_cfg_EOL exe l:txtBOL . g:pdv_cfg_Commentn . "@copyright " . g:pdv_cfg_Copyright . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Commentn . "@author " . g:pdv_cfg_Author g:pdv_cfg_EOL + exe l:txtBOL . g:pdv_cfg_Commentn . "@author " . g:pdv_cfg_Author . g:pdv_cfg_EOL exe l:txtBOL . g:pdv_cfg_Commentn . "@license " . g:pdv_cfg_License . g:pdv_cfg_EOL " Close the comment block. @@ -431,13 +450,13 @@ func! PhpDocClass() return l:modifier ." ". l:classname endfunc -" }}} -" {{{ PhpDocScope() +" }}} +" {{{ PhpDocScope() func! PhpDocScope(modifiers, identifier) " exe g:pdv_cfg_BOL . DEBUG: . a:modifiers . g:pdv_cfg_EOL let l:scope = "" - if matchstr (a:modifiers, g:pdv_re_scope) != "" + if matchstr (a:modifiers, g:pdv_re_scope) != "" if g:pdv_cfg_php4always == 1 let l:scope = matchstr (a:modifiers, g:pdv_re_scope) else @@ -459,13 +478,16 @@ endfunc func! PhpDocType(typeString) let l:type = "" - if a:typeString =~ g:pdv_re_array + if a:typeString =~ g:pdv_re_array let l:type = "array" endif - if a:typeString =~ g:pdv_re_float + if a:typeString =~ g:pdv_re_array_simple + let l:type = "array" + endif + if a:typeString =~ g:pdv_re_float let l:type = "float" endif - if a:typeString =~ g:pdv_re_int + if a:typeString =~ g:pdv_re_int let l:type = "int" endif if a:typeString =~ g:pdv_re_string @@ -479,24 +501,24 @@ func! PhpDocType(typeString) endif return l:type endfunc - -" }}} + +" }}} " {{{ PhpDocDefault() func! PhpDocDefault() " Line for the comment to begin let commentline = line (".") - 1 - + let l:indent = matchstr(getline("."), '^\ *') - + exe "norm! " . commentline . "G$" - + " Local indent let l:txtBOL = g:pdv_cfg_BOL . indent exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL - exe l:txtBOL . g:pdv_cfg_Commentn . " " . g:pdv_cfg_EOL - + exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_EOL + " Close the comment block. exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL endfunc