forked from tpope/vim-pathogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.vim
116 lines (100 loc) · 3.95 KB
/
header.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
" Originally found at: http://www.phpcult.com (by Jay)
" ------------------------------------------------------------------------------
" Document Header Creator for vim
" Copyright (c) 2003 Vidyut Luther
" A GnomeDoc function document headers looks like this:
" /**
" * func_name:
" * @arg1:
" *
" * [Description]
" *
" * Return value:
" **/
if has ("user_commands")
func! CreateHeader()
" Shortcuts for editing the text:
let txtBOL = "norm! o"
let txtEOL = "
n some VI variables that I do not know you might have
" to change these...
" txtCommentHead Start the comment block
" txtComment1 Line used for first comment line
" txtCommentn Line used for following comment lines
" txtCommentTail End of the comment block
if b:current_syntax == "php"
" ... PHP doesn't either
let txtCommentHead = "/**"
let txtComment1 = " * "
let txtCommentn = "* "
let txtCommentTail = "**/"
else
if b:current_syntax == "java"
let txtCommaentHead = "/**"
let txtComment1 = " * "
let txtCommentn = "* "
let txtCommentTail = "**/"
else
if b:current_syntax == "c++"
let txtCommaentHead = "/**"
let txtComment1 = " * "
let txtCommentn = "* "
let txtCommentTail = "**/"
else
if b:current_syntax == "c"
let txtCommaentHead = "/**"
let txtComment1 = " * "
let txtCommentn = "* "
let txtCommentTail = "**/"
else
" Most other languages use # for comments
" NOTE: This is just an extra option. The code is written for
" PHP, C, C++, and Java files, nothing else!
let txtCommentHead = "##"
let txtComment1 = "# "
let txtCommentn = "# "
let txtCommentTail = "##"
endif
endif
endif
endif
let LineToEndOn = line(".")
" Go to the beginning of the file
"exe "norm! [["
let lastline = line (".") - 1
" Find the previous blank line and assume the function starts there
exe "norm! {"
let firstline = line (".") + 1
let i = firstline
let name = ""
while i <= lastline
" Remove "//" comments directly
let name = name . " " . substitute (getline (i), '\(.*\)\/\/.*', '\1', "")
let i = i + 1
endwhile
" First some things to make it more easy for us:
" tab -> space && space+ -> space
let name = substitute (name, '\t', ' ', "")
let name = substitute (name, ' *', ' ', "")
" Now we have to split DECL in three parts:
" \(return type\)\(funcname\)\(parameters\)
exe txtBOL . txtCommentHead . txtEOL
exe txtBOL . txtCommentn . "+------------------------------------------------------------------------------+" . txtEOL
exe txtBOL . txtCommentn . "| $Workfile: $ |" . txtEOL
exe txtBOL . txtCommentn . "+------------------------------------------------------------------------------+" . txtEOL
exe txtBOL . txtCommentn . "| $Revision: $ (PHP5) |" . txtEOL
exe txtBOL . txtCommentn . "+------------------------------------------------------------------------------+" . txtEOL
exe txtBOL . txtCommentn . "| Copyright (c) 2003-2006 JETLib |" . txtEOL
exe txtBOL . txtCommentn . "+------------------------------------------------------------------------------+" . txtEOL
exe txtBOL . txtCommentn . "| Author: Jay E. Taylor <jtaylor@jetlib.com |" . txtEOL
exe txtBOL . txtCommentn . "+------------------------------------------------------------------------------+" . txtEOL
exe txtBOL . txtCommentn . txtEOL
exe txtBOL . txtCommentn . "$Header: $"
let LineToEndOn = line(".")
" Close the comment block.
exe txtBOL . txtCommentTail . txtEOL
" Let the editor go to the right line so the user can start editing
" right away.
return "norm! " . LineToEndOn . "G$"
endfunc
endif " user_commands