├── README.md └── plugin └── php-doc.vim /README.md: -------------------------------------------------------------------------------- 1 | # PHP-Doc-Modded 2 | 3 | The original plugin (information below) was **wonderful**.. unfortunately it has some issues but is no longer supported by the original developer. 4 | 5 | Here's my modified version. :kthxbye: 6 | 7 | 8 | Below is the original README information from http://www.vim.org/scripts/script.php?script_id=1355 9 | ------------------- 10 | 11 | PDV (phpDocumentor for Vim) 12 | ======================== 13 | 14 | Version: 1.0.0 15 | 16 | Copyright 2005 by Tobias Schlitt 17 | Inspired by phpDoc script for Vim by Vidyut Luther (http://www.phpcult.com/). 18 | 19 | Provided under the GPL (http://www.gnu.org/copyleft/gpl.html). 20 | 21 | This script provides functions to generate phpDocumentor conform 22 | documentation blocks for your PHP code. The script currently 23 | documents: 24 | 25 | - Classes 26 | - Methods/Functions 27 | - Attributes 28 | 29 | All of those supporting all PHP 4 and 5 syntax elements. 30 | 31 | Beside that it allows you to define default values for phpDocumentor tags 32 | like @version (I use $id$ here), @author, @license and so on. 33 | 34 | For function/method parameters and attributes, the script tries to guess the 35 | type as good as possible from PHP5 type hints or default values (array, bool, 36 | int, string...). 37 | 38 | You can use this script by mapping the function PhpDoc() to any 39 | key combination. Hit this on the line where the element to document 40 | resides and the doc block will be created directly above that line. 41 | 42 | Changelog 43 | ========= 44 | 45 | Version 1.0.0 46 | ------------------- 47 | 48 | * Created the initial version of this script while playing around with VIM 49 | scripting the first time and trying to fix Vidyut's solution, which 50 | resulted in a complete rewrite. 51 | 52 | install details 53 | Installation 54 | ========= 55 | 56 | For example include into your .vimrc: 57 | 58 | source ~/.vim/php-doc.vim 59 | inoremap :call PhpDocSingle()i 60 | nnoremap :call PhpDocSingle() 61 | vnoremap :call PhpDocRange() 62 | 63 | This includes the script and maps the combination +p 64 | to the doc functions. 65 | -------------------------------------------------------------------------------- /plugin/php-doc.vim: -------------------------------------------------------------------------------- 1 | " PDV (phpDocumentor for Vim) 2 | " =========================== 3 | " 4 | " Version: 1.1.4 5 | " 6 | " Copyright 2005 by Tobias Schlitt 7 | " Inspired by phpDoc script for Vim by Vidyut Luther (http://www.phpcult.com/). 8 | " 9 | " modified by kevin olson (acidjazz@gmail.com) 10 | " 11 | " FURTHER modified by Trevor Suarez (Rican7) 12 | 13 | 14 | " Provided under the GPL (http://www.gnu.org/copyleft/gpl.html). 15 | " 16 | " This script provides functions to generate phpDocumentor conform 17 | " documentation blocks for your PHP code. The script currently 18 | " documents: 19 | " 20 | " - Classes 21 | " - Methods/Functions 22 | " - Attributes 23 | " 24 | " All of those supporting all PHP 4 and 5 syntax elements. 25 | " 26 | " Beside that it allows you to define default values for phpDocumentor tags 27 | " like @version (I use $id$ here), @author, @license and so on. 28 | " 29 | " For function/method parameters and attributes, the script tries to guess the 30 | " type as good as possible from PHP5 type hints or default values (array, bool, 31 | " int, string...). 32 | " 33 | " You can use this script by mapping the function PhpDoc() to any 34 | " key combination. Hit this on the line where the element to document 35 | " resides and the doc block will be created directly above that line. 36 | " 37 | " Installation 38 | " ============ 39 | " 40 | " For example include into your .vimrc: 41 | " 42 | " source ~/.vim/php-doc.vim 43 | " imap :set paste:exe PhpDoc():set nopastei 44 | " 45 | " This includes the script and maps the combination +o (only in 46 | " insert mode) to the doc function. 47 | " 48 | " Changelog 49 | " ========= 50 | " 51 | " Version 1.1.4 52 | " ------------- 53 | " - added folding support 03/19/2008 54 | " - fixed all the variable type regex - booleans and integers properly work now 2/28/2010 55 | " 56 | " Version 1.0.0 57 | " ------------- 58 | " 59 | " * Created the initial version of this script while playing around with VIM 60 | " scripting the first time and trying to fix Vidyut's solution, which 61 | " resulted in a complete rewrite. 62 | " 63 | " Version 1.0.1 64 | " ------------- 65 | " * Fixed issues when using tabs instead of spaces. 66 | " * Fixed some parsing bugs when using a different coding style. 67 | " * Fixed bug with call-by-reference parameters. 68 | " * ATTENTION: This version already has code for the next version 1.1.0, 69 | " which is propably not working! 70 | " 71 | " Version 1.1.0 (preview) 72 | " ------------- 73 | " * Added foldmarker generation. 74 | " 75 | 76 | " Version 1.1.2 77 | " ------------- 78 | " * Completed foldmarker commenting for functions 79 | " 80 | 81 | 82 | 83 | " {{{ Globals 84 | 85 | " After phpDoc standard 86 | if !exists('g:pdv_cfg_CommentHead') | let g:pdv_cfg_CommentHead = "/**" | endif 87 | if !exists('g:pdv_cfg_Comment1') | let g:pdv_cfg_Comment1 = " * " | endif 88 | if !exists('g:pdv_cfg_Commentn') | let g:pdv_cfg_Commentn = " * " | endif 89 | if !exists('g:pdv_cfg_CommentBlank') | let g:pdv_cfg_CommentBlank = " *" | endif 90 | if !exists('g:pdv_cfg_CommentTail') | let g:pdv_cfg_CommentTail = " */" | endif 91 | if !exists('g:pdv_cfg_CommentSingle') | let g:pdv_cfg_CommentSingle = "//" | endif 92 | if !exists('g:pdv_cfg_FuncCommentEnd') | let g:pdv_cfg_FuncCommentEnd = " // End function" | endif 93 | if !exists('g:pdv_cfg_ClassCommentEnd') | let g:pdv_cfg_ClassCommentEnd = " // End" | endif 94 | if !exists('g:pdv_cfg_VariableTypeTag') | let g:pdv_cfg_VariableTypeTag = "@var" | endif 95 | 96 | " Default values 97 | if !exists('g:pdv_cfg_Type') | let g:pdv_cfg_Type = "mixed" | endif 98 | if !exists('g:pdv_cfg_Package') | let g:pdv_cfg_Package = "" | endif 99 | if !exists('g:pdv_cfg_Version') | let g:pdv_cfg_Version = "$id$" | endif 100 | if !exists('g:pdv_cfg_Author') | let g:pdv_cfg_Author = "Trevor Suarez " | endif 101 | if !exists('g:pdv_cfg_Copyright') | let g:pdv_cfg_Copyright = strftime('%Y') . " Blennd" | endif 102 | if !exists('g:pdv_cfg_License') | let g:pdv_cfg_License = "PHP Version 5.4 {@link http://www.php.net/license/}" | endif 103 | 104 | if !exists('g:pdv_cfg_ReturnVal') | let g:pdv_cfg_ReturnVal = "void" | endif 105 | 106 | " Wether to create tags for class docs or not 107 | if !exists('g:pdv_cfg_createClassTags') | let g:pdv_cfg_createClassTags = 1 | endif 108 | 109 | " Wether to create @uses tags for implementation of interfaces and inheritance 110 | if !exists('g:pdv_cfg_Uses') | let g:pdv_cfg_Uses = 1 | endif 111 | 112 | " Options 113 | " Whether or not to automatically add the function end comment (1|0) 114 | if !exists('g:pdv_cfg_autoEndFunction') | let g:pdv_cfg_autoEndFunction = 1 | endif 115 | 116 | " Whether or not to automatically add the class end comment (1|0) 117 | if !exists('g:pdv_cfg_autoEndClass') | let g:pdv_cfg_autoEndClass = 1 | endif 118 | 119 | " :set paste before documenting (1|0)? Recommended. 120 | if !exists('g:pdv_cfg_paste') | let g:pdv_cfg_paste = 1 | endif 121 | 122 | " Wether for PHP5 code PHP4 tags should be set, like @access,... (1|0)? 123 | if !exists('g:pdv_cfg_php4always') | let g:pdv_cfg_php4always = 1 | endif 124 | 125 | " Wether to guess scopes after PEAR coding standards: 126 | " $_foo/_bar() == (1|0)? 127 | if !exists('g:pdv_cfg_php4guess') | let g:pdv_cfg_php4guess = 1 | endif 128 | 129 | " If you selected 1 for the last value, this scope identifier will be used for 130 | " the identifiers having an _ in the first place. 131 | if !exists('g:pdv_cfg_php4guessval') | let g:pdv_cfg_php4guessval = "protected" | endif 132 | 133 | " Whether to generate the following annotations: 134 | if !exists('g:pdv_cfg_annotation_Package') | let g:pdv_cfg_annotation_Package = 1 | endif 135 | if !exists('g:pdv_cfg_annotation_Version') | let g:pdv_cfg_annotation_Version = 1 | endif 136 | if !exists('g:pdv_cfg_annotation_Author') | let g:pdv_cfg_annotation_Author = 1 | endif 137 | if !exists('g:pdv_cfg_annotation_Copyright') | let g:pdv_cfg_annotation_Copyright = 1 | endif 138 | if !exists('g:pdv_cfg_annotation_License') | let g:pdv_cfg_annotation_License = 1 | endif 139 | 140 | " 141 | " Regular expressions 142 | " 143 | 144 | let g:pdv_re_comment = ' *\*/ *' 145 | 146 | " (private|protected|public) 147 | let g:pdv_re_scope = '\(private\|protected\|public\)' 148 | " (static) 149 | let g:pdv_re_static = '\(static\)' 150 | " (abstract) 151 | let g:pdv_re_abstract = '\(abstract\)' 152 | " (final) 153 | let g:pdv_re_final = '\(final\)' 154 | 155 | " [:space:]*(private|protected|public|static|abstract)*[:space:]+[:identifier:]+\([:params:]\)[:space:]*:[:space:]*[:return_type:]+ 156 | let g:pdv_re_func = '^\s*\([a-zA-Z ]*\)function\s\+\([^ (]\+\)\s*(\_s*\(\%([^)]\|\_s\)*\)\_s*)\s*:\?\s*\([^ {]*\)\s*[{;]\?}\?$' 157 | let g:pdv_re_func_sigstart = '^\s*\%([a-zA-Z ]*\)function\s\+\%([^ (]\+\)\s*(' 158 | let g:pdv_re_func_sigend = '[{;]}\?$' 159 | let g:pdv_re_funcend = '^\s*}$' 160 | " [:typehint:]*[:space:]*$[:identifier]\([:space:]*=[:space:]*[:value:]\)? 161 | let g:pdv_re_param = ' *\([^ &]*\) *&\?\$\([A-Za-z_][A-Za-z0-9_]*\) *=\? *\(.*\)\?$' 162 | 163 | " [:space:]*(private|protected|public\)[:space:]*$[:identifier:]+\([:space:]*=[:space:]*[:value:]+\)*; 164 | let g:pdv_re_attribute = '^\s*\(\(private\|public\|protected\|var\|static\)\+\)\s*\$\([^ ;=]\+\)[ =]*\(.*\);\?$' 165 | let g:pdv_re_const = '^\s*\(\(const\)\+\)\s*\([^ ;=]\+\)[ =]*\(.*\);\?$' 166 | 167 | " [:spacce:]*(abstract|final|)[:space:]*(class|interface|trait)+[:space:]+\(extends ([:identifier:])\)?[:space:]*\(implements ([:identifier:][, ]*)+\)? 168 | let g:pdv_re_class = '^\s*\([a-zA-Z]*\)\s*\(interface\|class\|trait\)\s*\([^ ]\+\)\s*\(extends\)\?\s*\([a-zA-Z0-9_]*\)\?\s*\(implements*\)\? *\([a-zA-Z0-9_ ,]*\)\?.*$' 169 | 170 | let g:pdv_re_array = '^\(array *(.*\|\[ *\]\)' 171 | let g:pdv_re_int = '^[0-9]\+' 172 | let g:pdv_re_float = '^\d\+\.\d\+' 173 | let g:pdv_re_string = "['\"].*" 174 | let g:pdv_re_bool = '\(true\|false\)' 175 | 176 | 177 | let g:pdv_re_indent = '^\s*' 178 | 179 | " Shortcuts for editing the text: 180 | let g:pdv_cfg_BOL = "norm! o" 181 | let g:pdv_cfg_EOL = "" 182 | 183 | " }}} 184 | 185 | " {{{ PhpDocSingle() 186 | " Document a single line of code ( does not check if doc block already exists ) 187 | 188 | func! PhpDocSingle() 189 | let l:endline = line(".") + 1 190 | call PhpDoc() 191 | exe "norm! " . l:endline . "G$" 192 | endfunc 193 | 194 | " }}} 195 | " {{{ PhpDocRange() 196 | " Documents a whole range of code lines ( does not add defualt doc block to 197 | " unknown types of lines ). Skips elements where a docblock is already 198 | " present. 199 | func! PhpDocRange() range 200 | let l:line = a:firstline 201 | let l:endLine = a:lastline 202 | let l:elementName = "" 203 | while l:line <= l:endLine 204 | " TODO: Replace regex check for existing doc with check more lines 205 | " above... 206 | 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 207 | let l:docLines = 0 208 | " Ensure we are on the correct line to run PhpDoc() 209 | exe "norm! " . l:line . "G$" 210 | " No matter what, this returns the element name 211 | let l:elementName = PhpDoc() 212 | let l:endLine = l:endLine + (line(".") - l:line) + 1 213 | let l:line = line(".") + 1 214 | endif 215 | let l:line = l:line + 1 216 | endwhile 217 | endfunc 218 | 219 | " }}} 220 | " {{{ PhpDocFold() 221 | 222 | " func! PhpDocFold(name) 223 | " let l:startline = line(".") 224 | " let l:currentLine = l:startLine 225 | " let l:commentHead = escape(g:pdv_cfg_CommentHead, "*."); 226 | " let l:txtBOL = g:pdv_cfg_BOL . matchstr(l:name, '^\s*') 227 | " " Search above for comment start 228 | " while (l:currentLine > 1) 229 | " if (matchstr(l:commentHead, getline(l:currentLine))) 230 | " break; 231 | " endif 232 | " let l:currentLine = l:currentLine + 1 233 | " endwhile 234 | " " Goto 1 line above and open a newline 235 | " exe "norm! " . (l:currentLine - 1) . "Go\" 236 | " " Write the fold comment 237 | " exe l:txtBOL . g:pdv_cfg_CommentSingle . " {"."{{ " . a:name . g:pdv_cfg_EOL 238 | " " Add another newline below that 239 | " exe "norm! o\" 240 | " " Search for our comment line 241 | " let l:currentLine = line(".") 242 | " while (l:currentLine <= line("$")) 243 | " " HERE!!!! 244 | " endwhile 245 | " 246 | " 247 | " endfunc 248 | 249 | 250 | " }}} 251 | 252 | " {{{ PhpDoc() 253 | 254 | func! PhpDoc() 255 | " Needed for my .vimrc: Switch off all other enhancements while generating docs 256 | let l:paste = &g:paste 257 | let &g:paste = g:pdv_cfg_paste == 1 ? 1 : &g:paste 258 | 259 | let l:line = getline(".") 260 | let l:func_term = search(g:pdv_re_func_sigend, 'n') 261 | let l:result = "" 262 | 263 | if l:line =~ g:pdv_re_func_sigstart 264 | let l:result = PhpDocFunc(l:func_term) 265 | 266 | elseif l:line =~ g:pdv_re_funcend 267 | let l:result = PhpDocFuncEnd() 268 | 269 | elseif l:line =~ g:pdv_re_attribute 270 | let l:result = PhpDocVar() 271 | 272 | elseif l:line =~ g:pdv_re_const 273 | let l:result = PhpDocConst() 274 | 275 | elseif l:line =~ g:pdv_re_class 276 | if g:pdv_cfg_createClassTags == 1 277 | let l:result = PhpDocClass() 278 | else 279 | let l:result = PhpDocDefault() 280 | endif 281 | 282 | else 283 | let l:result = PhpDocDefault() 284 | 285 | endif 286 | 287 | let &g:paste = l:paste 288 | 289 | return l:result 290 | endfunc 291 | 292 | " }}} 293 | 294 | " {{{ PhpDocFuncEnd() 295 | func! PhpDocFuncEnd() 296 | 297 | call setline(line('.'), getline('.') . g:pdv_cfg_FuncCommentEnd) 298 | endfunc 299 | " }}} 300 | " {{{ PhpDocFuncEndAuto() 301 | func! PhpDocFuncEndAuto(funcname) 302 | 303 | call search('{') 304 | call searchpair('{', '', '}') 305 | call setline(line('.'), getline('.') . g:pdv_cfg_FuncCommentEnd . ' ' . a:funcname) 306 | 307 | endfunc 308 | " }}} 309 | 310 | " {{{ PhpDocClassEnd() 311 | func! PhpDocClassEnd(classtype, classname) 312 | 313 | call setline(line('.'), getline('.') . g:pdv_cfg_ClassCommentEnd . ' ' . a:classtype . ' ' . a:classname) 314 | endfunc 315 | " }}} 316 | " {{{ PhpDocClassEndAuto() 317 | func! PhpDocClassEndAuto(classtype, classname) 318 | 319 | call search('{') 320 | call searchpair('{', '', '}') 321 | return PhpDocClassEnd(a:classtype, a:classname) 322 | 323 | endfunc 324 | " }}} 325 | 326 | " {{{ PhpDocFunc() 327 | 328 | func! PhpDocFunc(end_line) 329 | " Line for the comment to begin 330 | let commentline = line (".") - 1 331 | 332 | let l:line = getline(".") 333 | 334 | if 0 < a:end_line 335 | let l:line = join(getline(line('.'), a:end_line), ' ') 336 | endif 337 | 338 | let l:name = substitute (l:line, '^\(.*\)\/\/.*$', '\1', "") 339 | 340 | "exe g:pdv_cfg_BOL . "DEBUG:" . name. g:pdv_cfg_EOL 341 | 342 | " First some things to make it more easy for us: 343 | " tab -> space && space+ -> space 344 | " let l:name = substitute (l:name, '\t', ' ', "") 345 | " Orphan. We're now using \s everywhere... 346 | 347 | " Now we have to split DECL in three parts: 348 | " \[(skopemodifier\)]\(funcname\)\(parameters\) 349 | let l:indent = matchstr(l:name, g:pdv_re_indent) 350 | 351 | let l:modifier = substitute (l:name, g:pdv_re_func, '\1', "g") 352 | let l:funcname = substitute (l:name, g:pdv_re_func, '\2', "g") 353 | let l:funcname = substitute (l:funcname, '__construct', 'Constructor', "g") " Rename constructors 354 | let l:parameters = substitute (l:name, g:pdv_re_func, '\3', "g") . "," 355 | let l:params = substitute (l:name, g:pdv_re_func, '\3', "g") 356 | let l:params = substitute (l:params, '[$ ]', '', "g") 357 | let l:scope = PhpDocScope(l:modifier, l:funcname) 358 | let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" 359 | let l:abstract = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_abstract) : "" 360 | let l:final = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_final) : "" 361 | let l:returnType = substitute (l:name, g:pdv_re_func, '\4', "g") 362 | 363 | if l:returnType == "" 364 | let l:returnType = g:pdv_cfg_ReturnVal 365 | endif 366 | 367 | exe "norm! " . commentline . "G$" 368 | 369 | " Local indent 370 | let l:txtBOL = g:pdv_cfg_BOL . l:indent 371 | 372 | " exec l:txtBOL . "// " . l:scope ." ". funcname . "(" . l:params . ") {{" . "{ " . g:pdv_cfg_EOL 373 | 374 | exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL 375 | " added folding 376 | exe l:txtBOL . g:pdv_cfg_Comment1 . funcname . g:pdv_cfg_EOL 377 | exe l:txtBOL . g:pdv_cfg_CommentBlank . g:pdv_cfg_EOL 378 | 379 | while (l:parameters != ",") && (l:parameters != "") 380 | " Save 1st parameter 381 | let _p = substitute (l:parameters, '\([^,]*\) *, *\(.*\)', '\1', "") 382 | " Remove this one from list 383 | let l:parameters = substitute (l:parameters, '\([^,]*\) *, *\(.*\)', '\2', "") 384 | " PHP5 type hint? 385 | let l:paramtype = substitute (_p, g:pdv_re_param, '\1', "") 386 | " Parameter name 387 | let l:paramname = substitute (_p, g:pdv_re_param, '\2', "") 388 | " Parameter default 389 | let l:paramdefault = substitute (_p, g:pdv_re_param, '\3', "") 390 | 391 | if l:paramtype == "" 392 | let l:paramtype = PhpDocType(l:paramdefault) 393 | endif 394 | 395 | if l:paramtype != "" 396 | let l:paramtype = " " . l:paramtype 397 | endif 398 | exe l:txtBOL . g:pdv_cfg_Commentn . "@param" . l:paramtype . " $" . l:paramname . "" . g:pdv_cfg_EOL 399 | endwhile 400 | 401 | if l:static != "" 402 | exe l:txtBOL . g:pdv_cfg_Commentn . "@static" . g:pdv_cfg_EOL 403 | endif 404 | if l:abstract != "" 405 | exe l:txtBOL . g:pdv_cfg_Commentn . "@abstract" . g:pdv_cfg_EOL 406 | endif 407 | if l:final != "" 408 | exe l:txtBOL . g:pdv_cfg_Commentn . "@final" . g:pdv_cfg_EOL 409 | endif 410 | if l:scope != "" 411 | exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL 412 | endif 413 | if l:funcname != "Constructor" 414 | exe l:txtBOL . g:pdv_cfg_Commentn . "@return " . l:returnType . g:pdv_cfg_EOL 415 | endif 416 | 417 | " Close the comment block. 418 | exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL 419 | 420 | if g:pdv_cfg_autoEndFunction == 1 421 | return l:modifier ." ". l:funcname . PhpDocFuncEndAuto(l:funcname) 422 | else 423 | return l:modifier ." ". l:funcname 424 | endif 425 | endfunc 426 | 427 | " }}} 428 | " {{{ PhpDocVar() 429 | 430 | func! PhpDocVar() 431 | " Line for the comment to begin 432 | let commentline = line (".") - 1 433 | 434 | let l:name = substitute (getline ("."), '^\(.*\)\/\/.*$', '\1', "") 435 | 436 | " Now we have to split DECL in three parts: 437 | " \[(skopemodifier\)]\(funcname\)\(parameters\) 438 | " let l:name = substitute (l:name, '\t', ' ', "") 439 | " Orphan. We're now using \s everywhere... 440 | 441 | let l:indent = matchstr(l:name, g:pdv_re_indent) 442 | 443 | let l:modifier = substitute (l:name, g:pdv_re_attribute, '\1', "g") 444 | let l:varname = substitute (l:name, g:pdv_re_attribute, '\3', "g") 445 | let l:default = substitute (l:name, g:pdv_re_attribute, '\4', "g") 446 | let l:scope = PhpDocScope(l:modifier, l:varname) 447 | 448 | let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" 449 | 450 | let l:type = PhpDocType(l:default) 451 | 452 | exe "norm! " . commentline . "G$" 453 | 454 | " Local indent 455 | let l:txtBOL = g:pdv_cfg_BOL . l:indent 456 | 457 | exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL 458 | exe l:txtBOL . g:pdv_cfg_Comment1 . l:varname . " " . g:pdv_cfg_EOL 459 | exe l:txtBOL . g:pdv_cfg_CommentBlank . g:pdv_cfg_EOL 460 | if l:static != "" 461 | exe l:txtBOL . g:pdv_cfg_Commentn . "@static" . g:pdv_cfg_EOL 462 | endif 463 | exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_VariableTypeTag . " " . l:type . g:pdv_cfg_EOL 464 | if l:scope != "" 465 | exe l:txtBOL . g:pdv_cfg_Commentn . "@access " . l:scope . g:pdv_cfg_EOL 466 | endif 467 | 468 | " Close the comment block. 469 | exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL 470 | return l:modifier ." ". l:varname 471 | endfunc 472 | 473 | " }}} 474 | " {{{ PhpDocConst() 475 | 476 | func! PhpDocConst() 477 | " Line for the comment to begin 478 | let commentline = line (".") - 1 479 | 480 | let l:name = substitute (getline ("."), '^\(.*\)\/\/.*$', '\1', "") 481 | 482 | " Now we have to split DECL in three parts: 483 | " \[(skopemodifier\)]\(funcname\)\(parameters\) 484 | " let l:name = substitute (l:name, '\t', ' ', "") 485 | " Orphan. We're now using \s everywhere... 486 | 487 | let l:indent = matchstr(l:name, g:pdv_re_indent) 488 | 489 | let l:modifier = substitute (l:name, g:pdv_re_const, '\1', "g") 490 | let l:varname = substitute (l:name, g:pdv_re_const, '\3', "g") 491 | let l:default = substitute (l:name, g:pdv_re_const, '\4', "g") 492 | let l:scope = PhpDocScope(l:modifier, l:varname) 493 | 494 | let l:static = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_static) : "" 495 | 496 | let l:type = PhpDocType(l:default) 497 | 498 | exe "norm! " . commentline . "G$" 499 | 500 | " Local indent 501 | let l:txtBOL = g:pdv_cfg_BOL . l:indent 502 | 503 | exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL 504 | exe l:txtBOL . g:pdv_cfg_Comment1 . l:varname . " " . g:pdv_cfg_EOL 505 | exe l:txtBOL . g:pdv_cfg_CommentBlank . g:pdv_cfg_EOL 506 | exe l:txtBOL . g:pdv_cfg_Commentn . g:pdv_cfg_VariableTypeTag . " " . l:type . g:pdv_cfg_EOL 507 | 508 | " Close the comment block. 509 | exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL 510 | return l:modifier ." ". l:varname 511 | endfunc 512 | 513 | " }}} 514 | " {{{ PhpDocClass() 515 | 516 | func! PhpDocClass() 517 | " Line for the comment to begin 518 | let commentline = line (".") - 1 519 | 520 | let l:name = substitute (getline ("."), '^\(.*\)\/\/.*$', '\1', "") 521 | 522 | "exe g:pdv_cfg_BOL . "DEBUG:" . name. g:pdv_cfg_EOL 523 | 524 | " First some things to make it more easy for us: 525 | " tab -> space && space+ -> space 526 | " let l:name = substitute (l:name, '\t', ' ', "") 527 | " Orphan. We're now using \s everywhere... 528 | 529 | " Now we have to split DECL in three parts: 530 | " \[(skopemodifier\)]\(classname\)\(parameters\) 531 | let l:indent = matchstr(l:name, g:pdv_re_indent) 532 | 533 | let l:modifier = substitute (l:name, g:pdv_re_class, '\1', "g") 534 | let l:classtype = substitute (l:name, g:pdv_re_class, '\2', "g") 535 | let l:classname = substitute (l:name, g:pdv_re_class, '\3', "g") 536 | let l:extends = g:pdv_cfg_Uses == 1 ? substitute (l:name, g:pdv_re_class, '\5', "g") : "" 537 | let l:interfaces = g:pdv_cfg_Uses == 1 ? substitute (l:name, g:pdv_re_class, '\7', "g") . "," : "" 538 | 539 | let l:abstract = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_abstract) : "" 540 | let l:final = g:pdv_cfg_php4always == 1 ? matchstr(l:modifier, g:pdv_re_final) : "" 541 | 542 | exe "norm! " . commentline . "G$" 543 | 544 | " Local indent 545 | let l:txtBOL = g:pdv_cfg_BOL . l:indent 546 | 547 | exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL 548 | exe l:txtBOL . g:pdv_cfg_Comment1 . l:classname . g:pdv_cfg_EOL 549 | exe l:txtBOL . g:pdv_cfg_CommentBlank . g:pdv_cfg_EOL 550 | if l:extends != "" && l:extends != "implements" 551 | exe l:txtBOL . g:pdv_cfg_Commentn . "@uses " . l:extends . g:pdv_cfg_EOL 552 | endif 553 | 554 | while (l:interfaces != ",") && (l:interfaces != "") 555 | " Save 1st parameter 556 | let interface = substitute (l:interfaces, '\([^, ]*\) *, *\(.*\)', '\1', "") 557 | " Remove this one from list 558 | let l:interfaces = substitute (l:interfaces, '\([^, ]*\) *, *\(.*\)', '\2', "") 559 | exe l:txtBOL . g:pdv_cfg_Commentn . "@uses " . l:interface . g:pdv_cfg_EOL 560 | endwhile 561 | 562 | if l:abstract != "" 563 | exe l:txtBOL . g:pdv_cfg_Commentn . "@abstract" . g:pdv_cfg_EOL 564 | endif 565 | if l:final != "" 566 | exe l:txtBOL . g:pdv_cfg_Commentn . "@final" . g:pdv_cfg_EOL 567 | endif 568 | if g:pdv_cfg_annotation_Package == 1 569 | exe l:txtBOL . g:pdv_cfg_Commentn . "@package " . g:pdv_cfg_Package . g:pdv_cfg_EOL 570 | endif 571 | if g:pdv_cfg_annotation_Version == 1 572 | exe l:txtBOL . g:pdv_cfg_Commentn . "@version " . g:pdv_cfg_Version . g:pdv_cfg_EOL 573 | endif 574 | if g:pdv_cfg_annotation_Copyright == 1 575 | exe l:txtBOL . g:pdv_cfg_Commentn . "@copyright " . g:pdv_cfg_Copyright . g:pdv_cfg_EOL 576 | endif 577 | if g:pdv_cfg_annotation_Author == 1 578 | exe l:txtBOL . g:pdv_cfg_Commentn . "@author " . g:pdv_cfg_Author . g:pdv_cfg_EOL 579 | endif 580 | if g:pdv_cfg_annotation_License == 1 581 | exe l:txtBOL . g:pdv_cfg_Commentn . "@license " . g:pdv_cfg_License . g:pdv_cfg_EOL 582 | endif 583 | 584 | " Close the comment block. 585 | exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL 586 | 587 | if g:pdv_cfg_autoEndClass == 1 588 | return l:modifier ." ". l:classname . PhpDocClassEndAuto(l:classtype, l:classname) 589 | else 590 | return l:modifier ." ". l:classname 591 | endif 592 | endfunc 593 | 594 | " }}} 595 | " {{{ PhpDocScope() 596 | 597 | func! PhpDocScope(modifiers, identifier) 598 | " exe g:pdv_cfg_BOL . DEBUG: . a:modifiers . g:pdv_cfg_EOL 599 | let l:scope = "" 600 | if matchstr (a:modifiers, g:pdv_re_scope) != "" 601 | if g:pdv_cfg_php4always == 1 602 | let l:scope = matchstr (a:modifiers, g:pdv_re_scope) 603 | else 604 | let l:scope = "x" 605 | endif 606 | endif 607 | if l:scope =~ "^\s*$" && g:pdv_cfg_php4guess 608 | if a:identifier[0] == "_" 609 | let l:scope = g:pdv_cfg_php4guessval 610 | else 611 | let l:scope = "public" 612 | endif 613 | endif 614 | return l:scope != "x" ? l:scope : "" 615 | endfunc 616 | 617 | " }}} 618 | " {{{ PhpDocType() 619 | 620 | func! PhpDocType(typeString) 621 | let l:type = "" 622 | if a:typeString =~ g:pdv_re_array 623 | let l:type = "array" 624 | endif 625 | if a:typeString =~ g:pdv_re_int 626 | let l:type = "int" 627 | endif 628 | if a:typeString =~ g:pdv_re_float 629 | let l:type = "float" 630 | endif 631 | if a:typeString =~ g:pdv_re_string 632 | let l:type = "string" 633 | endif 634 | if a:typeString =~ g:pdv_re_bool 635 | let l:type = "bool" 636 | endif 637 | if l:type == "" 638 | let l:type = g:pdv_cfg_Type 639 | endif 640 | return l:type 641 | endfunc 642 | 643 | " }}} 644 | " {{{ PhpDocDefault() 645 | 646 | func! PhpDocDefault() 647 | " Line for the comment to begin 648 | let commentline = line (".") - 1 649 | 650 | let l:indent = matchstr(getline("."), '^\ *') 651 | 652 | exe "norm! " . commentline . "G$" 653 | 654 | " Local indent 655 | let l:txtBOL = g:pdv_cfg_BOL . indent 656 | 657 | exe l:txtBOL . g:pdv_cfg_CommentHead . g:pdv_cfg_EOL 658 | exe l:txtBOL . g:pdv_cfg_CommentBlank . " " . g:pdv_cfg_EOL 659 | 660 | " Close the comment block. 661 | exe l:txtBOL . g:pdv_cfg_CommentTail . g:pdv_cfg_EOL 662 | endfunc 663 | 664 | " }}} 665 | --------------------------------------------------------------------------------