annotate runtime/ftplugin/changelog.vim @ 19940:724417668d42 v8.2.0526

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