annotate runtime/ftplugin/changelog.vim @ 7238:c8cdc5a88cda

Added tag v7.4.927 for changeset 2a95fa0a07b5158627e0ad2d3de23fe6ff4fe599
author Christian Brabandt <cb@256bit.org>
date Thu, 19 Nov 2015 19:45:04 +0100
parents 350272cbf1fd
children 17333ebd2bbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim filetype plugin file
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
2 " Language: generic Changelog file
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
5618
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5568
diff changeset
4 " Latest Revision: 2014-01-10
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " Variables:
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
6 " g:changelog_timeformat (deprecated: use g:changelog_dateformat instead) -
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
7 " description: the timeformat used in ChangeLog entries.
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
8 " default: "%Y-%m-%d".
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
9 " g:changelog_dateformat -
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
10 " description: the format sent to strftime() to generate a date string.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
11 " default: "%Y-%m-%d".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " g:changelog_username -
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
13 " description: the username to use in ChangeLog entries
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
14 " default: try to deduce it from environment variables and system files.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Local Mappings:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " <Leader>o -
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
17 " adds a new changelog entry for the current user for the current date.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " Global Mappings:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " <Leader>o -
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
20 " switches to the ChangeLog buffer opened for the current directory, or
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
21 " opens it in a new buffer if it exists in the current directory. Then
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
22 " it does the same as the local <Leader>o described above.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " Notes:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " run 'runtime ftplugin/changelog.vim' to enable the global mapping for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " changelog files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 " TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " should we perhaps open the ChangeLog file even if it doesn't exist already?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Problem is that you might end up with ChangeLog files all over the place.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " If 'filetype' isn't "changelog", we must have been to add ChangeLog opener
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
31 if &filetype == 'changelog'
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
32 if exists('b:did_ftplugin')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let b:did_ftplugin = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
37 let s:cpo_save = &cpo
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
38 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
40 " Set up the format used for dates.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
41 if !exists('g:changelog_dateformat')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
42 if exists('g:changelog_timeformat')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
43 let g:changelog_dateformat = g:changelog_timeformat
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
44 else
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
45 let g:changelog_dateformat = "%Y-%m-%d"
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
46 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
49 function! s:username()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
50 if exists('g:changelog_username')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
51 return g:changelog_username
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
52 elseif $EMAIL != ""
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
53 return $EMAIL
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
54 elseif $EMAIL_ADDRESS != ""
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
55 return $EMAIL_ADDRESS
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
56 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
57
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
58 let login = s:login()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
59 return printf('%s <%s@%s>', s:name(login), login, s:hostname())
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
60 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
61
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
62 function! s:login()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
63 return s:trimmed_system_with_default('whoami', 'unknown')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
64 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
65
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
66 function! s:trimmed_system_with_default(command, default)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
67 return s:first_line(s:system_with_default(a:command, a:default))
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
68 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
69
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
70 function! s:system_with_default(command, default)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
71 let output = system(a:command)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
72 if v:shell_error
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
73 return default
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
74 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
75 return output
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
76 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
77
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
78 function! s:first_line(string)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
79 return substitute(a:string, '\n.*$', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
80 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
82 function! s:name(login)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
83 for name in [s:gecos_name(a:login), $NAME, s:capitalize(a:login)]
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
84 if name != ""
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
85 return name
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 endif
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
87 endfor
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
88 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
89
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
90 function! s:gecos_name(login)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
91 for line in s:try_reading_file('/etc/passwd')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
92 if line =~ '^' . a:login . ':'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
93 return substitute(s:passwd_field(line, 5), '&', s:capitalize(a:login), "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
94 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
95 endfor
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
96 return ""
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
97 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
99 function! s:try_reading_file(path)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
100 try
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
101 return readfile(a:path)
2826
3c7da93eb7f9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2608
diff changeset
102 catch
3c7da93eb7f9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2608
diff changeset
103 return []
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
104 endtry
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
105 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
107 function! s:passwd_field(line, field)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
108 let fields = split(a:line, ':', 1)
3830
04592728474a Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2826
diff changeset
109 if len(fields) < a:field
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
110 return ""
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
111 endif
3830
04592728474a Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2826
diff changeset
112 return fields[a:field - 1]
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
113 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
115 function! s:capitalize(word)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
116 return toupper(a:word[0]) . strpart(a:word, 1)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
117 endfunction
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
118
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
119 function! s:hostname()
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
120 return s:trimmed_system_with_default('hostname', 'localhost')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
121 endfunction
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
123 " Format used for new date entries.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
124 if !exists('g:changelog_new_date_format')
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
125 let g:changelog_new_date_format = "%d %u\n\n\t* %p%c\n\n"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
128 " Format used for new entries to current date entry.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
129 if !exists('g:changelog_new_entry_format')
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
130 let g:changelog_new_entry_format = "\t* %p%c"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
133 " Regular expression used to find a given date entry.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
134 if !exists('g:changelog_date_entry_search')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 let g:changelog_date_entry_search = '^\s*%d\_s*%u'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
138 " Regular expression used to find the end of a date entry
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
139 if !exists('g:changelog_date_end_entry_search')
1621
82b5078be2dd updated for version 7.2a
vimboss
parents: 1213
diff changeset
140 let g:changelog_date_end_entry_search = '^\s*$'
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
141 endif
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
142
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
143
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
144 " Substitutes specific items in new date-entry formats and search strings.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
145 " Can be done with substitute of course, but unclean, and need \@! then.
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
146 function! s:substitute_items(str, date, user, prefix)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 let str = a:str
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
148 let middles = {'%': '%', 'd': a:date, 'u': a:user, 'p': a:prefix, 'c': '{cursor}'}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 let i = stridx(str, '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 while i != -1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
151 let inc = 0
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
152 if has_key(middles, str[i + 1])
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
153 let mid = middles[str[i + 1]]
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
154 let str = strpart(str, 0, i) . mid . strpart(str, i + 2)
5618
350272cbf1fd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5568
diff changeset
155 let inc = strlen(mid) - 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 endif
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
157 let i = stridx(str, '%', i + 1 + inc)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 return str
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
162 " Position the cursor once we've done all the funky substitution.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 function! s:position_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 if search('{cursor}') > 0
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
165 let lnum = line('.')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
166 let line = getline(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let cursor = stridx(line, '{cursor}')
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
168 call setline(lnum, substitute(line, '{cursor}', '', ''))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 startinsert!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
173 " Internal function to create a new entry in the ChangeLog.
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
174 function! s:new_changelog_entry(prefix)
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
175 " Deal with 'paste' option.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 let save_paste = &paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 let &paste = 1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
178 call cursor(1, 1)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
179 " Look for an entry for today by our user.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
180 let date = strftime(g:changelog_dateformat)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 let search = s:substitute_items(g:changelog_date_entry_search, date,
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
182 \ s:username(), a:prefix)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 if search(search) > 0
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
184 " Ok, now we look for the end of the date entry, and add an entry.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
185 call cursor(nextnonblank(line('.') + 1), 1)
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
186 if search(g:changelog_date_end_entry_search, 'W') > 0
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
187 let p = (line('.') == line('$')) ? line('.') : line('.') - 1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
188 else
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
189 let p = line('.')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
190 endif
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
191 let ls = split(s:substitute_items(g:changelog_new_entry_format, '', '', a:prefix),
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
192 \ '\n')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
193 call append(p, ls)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
194 call cursor(p + 1, 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 else
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
196 " Flag for removing empty lines at end of new ChangeLogs.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 let remove_empty = line('$') == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
199 " No entry today, so create a date-user header and insert an entry.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 let todays_entry = s:substitute_items(g:changelog_new_date_format,
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
201 \ date, s:username(), a:prefix)
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
202 " Make sure we have a cursor positioning.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 if stridx(todays_entry, '{cursor}') == -1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
204 let todays_entry = todays_entry . '{cursor}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
207 " Now do the work.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
208 call append(0, split(todays_entry, '\n'))
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
209
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
210 " Remove empty lines at end of file.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 if remove_empty
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
212 $-/^\s*$/-1,$delete
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
215 " Reposition cursor once we're done.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
216 call cursor(1, 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 call s:position_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 " And reset 'paste' option
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 let &paste = save_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 if exists(":NewChangelogEntry") != 2
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
226 noremap <buffer> <silent> <Leader>o <Esc>:call <SID>new_changelog_entry('')<CR>
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
227 command! -nargs=0 NewChangelogEntry call s:new_changelog_entry('')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
230 let b:undo_ftplugin = "setl com< fo< et< ai<"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 setlocal comments=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 setlocal formatoptions+=t
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 setlocal noexpandtab
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
235 setlocal autoindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
237 if &textwidth == 0
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
238 setlocal textwidth=78
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
239 let b:undo_ftplugin .= " tw<"
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
240 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
241
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
242 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
243 unlet s:cpo_save
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 else
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
245 let s:cpo_save = &cpo
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
246 set cpo&vim
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
247
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 " Add the Changelog opening mapping
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
249 nnoremap <silent> <Leader>o :call <SID>open_changelog()<CR>
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 function! s:open_changelog()
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
252 let path = expand('%:p:h')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
253 if exists('b:changelog_path')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
254 let changelog = b:changelog_path
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
255 else
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
256 if exists('b:changelog_name')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
257 let name = b:changelog_name
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
258 else
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
259 let name = 'ChangeLog'
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
260 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
261 while isdirectory(path)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
262 let changelog = path . '/' . name
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
263 if filereadable(changelog)
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
264 break
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
265 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
266 let parent = substitute(path, '/\+[^/]*$', "", "")
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
267 if path == parent
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
268 break
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
269 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
270 let path = parent
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
271 endwhile
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
272 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
273 if !filereadable(changelog)
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
274 return
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
275 endif
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
276
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
277 if exists('b:changelog_entry_prefix')
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
278 let prefix = call(b:changelog_entry_prefix, [])
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
279 else
5568
2f856c7c1d43 Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents: 3830
diff changeset
280 let prefix = substitute(strpart(expand('%:p'), strlen(path)), '^/\+', "", "")
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
281 endif
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
282
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
283 let buf = bufnr(changelog)
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
284 if buf != -1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
285 if bufwinnr(buf) != -1
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
286 execute bufwinnr(buf) . 'wincmd w'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 else
1213
8906c10ecbb0 updated for version 7.1b
vimboss
parents: 839
diff changeset
288 execute 'sbuffer' buf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 endif
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
290 else
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
291 execute 'split' fnameescape(changelog)
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
292 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
294 call s:new_changelog_entry(prefix)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 endfunction
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
296
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
297 let &cpo = s:cpo_save
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1621
diff changeset
298 unlet s:cpo_save
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 endif