annotate runtime/ftplugin/changelog.vim @ 1051:e14d0a530351 v7.0.177

updated for version 7.0-177
author vimboss
date Tue, 05 Dec 2006 20:43:17 +0000
parents 1f3b1021f002
children 8906c10ecbb0
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>
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
4 " Latest Revision: 2006-04-19
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 " Try to figure out a reasonable username of the form:
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
50 " Full Name <user@host>.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
51 if !exists('g:changelog_username')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
52 if exists('$EMAIL') && $EMAIL != ''
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
53 let g:changelog_username = $EMAIL
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
54 elseif exists('$EMAIL_ADDRESS') && $EMAIL_ADDRESS != ''
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
55 " This is some Debian junk if I remember correctly.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let g:changelog_username = $EMAIL_ADDRESS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 else
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
58 " Get the users login name.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 let login = system('whoami')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 if v:shell_error
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
61 let login = 'unknown'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 else
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
63 let newline = stridx(login, "\n")
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
64 if newline != -1
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
65 let login = strpart(login, 0, newline)
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
66 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
69 " Try to get the full name from gecos field in /etc/passwd.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 if filereadable('/etc/passwd')
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
71 for line in readfile('/etc/passwd')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
72 if line =~ '^' . login
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
73 let name = substitute(line,'^\%([^:]*:\)\{4}\([^:]*\):.*$','\1','')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
74 " Only keep stuff before the first comma.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
75 let comma = stridx(name, ',')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
76 if comma != -1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
77 let name = strpart(name, 0, comma)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
78 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
79 " And substitute & in the real name with the login of our user.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
80 let amp = stridx(name, '&')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
81 if amp != -1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
82 let name = strpart(name, 0, amp) . toupper(login[0]) .
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
83 \ strpart(login, 1) . strpart(name, amp + 1)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
84 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
85 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
86 endfor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
89 " If we haven't found a name, try to gather it from other places.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
90 if !exists('name')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
91 " Maybe the environment has something of interest.
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
92 if exists("$NAME")
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
93 let name = $NAME
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
94 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
95 " No? well, use the login name and capitalize first
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
96 " character.
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
97 let name = toupper(login[0]) . strpart(login, 1)
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
98 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
101 " Get our hostname.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
102 let hostname = system('hostname')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 if v:shell_error
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
104 let hostname = 'localhost'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 else
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
106 let newline = stridx(hostname, "\n")
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
107 if newline != -1
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
108 let hostname = strpart(hostname, 0, newline)
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
109 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
112 " And finally set the username.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
113 let g:changelog_username = name . ' <' . login . '@' . hostname . '>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
117 " Format used for new date entries.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
118 if !exists('g:changelog_new_date_format')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 let g:changelog_new_date_format = "%d %u\n\n\t* %c\n\n"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
122 " Format used for new entries to current date entry.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
123 if !exists('g:changelog_new_entry_format')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 let g:changelog_new_entry_format = "\t* %c"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
127 " Regular expression used to find a given date entry.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
128 if !exists('g:changelog_date_entry_search')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 let g:changelog_date_entry_search = '^\s*%d\_s*%u'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
132 " Substitutes specific items in new date-entry formats and search strings.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
133 " Can be done with substitute of course, but unclean, and need \@! then.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 function! s:substitute_items(str, date, user)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 let str = a:str
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
136 let middles = {'%': '%', 'd': a:date, 'u': a:user, 'c': '{cursor}'}
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 let i = stridx(str, '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 while i != -1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
139 let inc = 0
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
140 if has_key(middles, str[i + 1])
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
141 let mid = middles[str[i + 1]]
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
142 let str = strpart(str, 0, i) . mid . strpart(str, i + 2)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
143 let inc = strlen(mid)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 endif
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
145 let i = stridx(str, '%', i + 1 + inc)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 return str
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
150 " Position the cursor once we've done all the funky substitution.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 function! s:position_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 if search('{cursor}') > 0
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
153 let lnum = line('.')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
154 let line = getline(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 let cursor = stridx(line, '{cursor}')
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
156 call setline(lnum, substitute(line, '{cursor}', '', ''))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 startinsert!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
161 " Internal function to create a new entry in the ChangeLog.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 function! s:new_changelog_entry()
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
163 " Deal with 'paste' option.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 let save_paste = &paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 let &paste = 1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
166 call cursor(1, 1)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
167 " Look for an entry for today by our user.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
168 let date = strftime(g:changelog_dateformat)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 let search = s:substitute_items(g:changelog_date_entry_search, date,
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
170 \ g:changelog_username)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 if search(search) > 0
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
172 " 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
173 call cursor(nextnonblank(line('.') + 1), 1)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
174 if search('^\s*$', 'W') > 0
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
175 let p = line('.') - 1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
176 else
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
177 let p = line('.')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
178 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
179 let ls = split(s:substitute_items(g:changelog_new_entry_format, '', ''),
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
180 \ '\n')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
181 call append(p, ls)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
182 call cursor(p + 1, 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 else
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
184 " Flag for removing empty lines at end of new ChangeLogs.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 let remove_empty = line('$') == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
187 " No entry today, so create a date-user header and insert an entry.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 let todays_entry = s:substitute_items(g:changelog_new_date_format,
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
189 \ date, g:changelog_username)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
190 " Make sure we have a cursor positioning.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 if stridx(todays_entry, '{cursor}') == -1
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
192 let todays_entry = todays_entry . '{cursor}'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
195 " Now do the work.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
196 call append(0, split(todays_entry, '\n'))
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
197
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
198 " Remove empty lines at end of file.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 if remove_empty
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
200 $-/^\s*$/-1,$delete
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
203 " Reposition cursor once we're done.
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
204 call cursor(1, 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 call s:position_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 " And reset 'paste' option
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 let &paste = save_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 if exists(":NewChangelogEntry") != 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 map <buffer> <silent> <Leader>o <Esc>:call <SID>new_changelog_entry()<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 command! -nargs=0 NewChangelogEntry call s:new_changelog_entry()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
218 let b:undo_ftplugin = "setl com< fo< et< ai<"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 setlocal comments=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 setlocal formatoptions+=t
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 setlocal noexpandtab
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
223 setlocal autoindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
225 if &textwidth == 0
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
226 setlocal textwidth=78
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
227 let b:undo_ftplugin .= " tw<"
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
228 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
229
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
230 let &cpo = s:cpo_save
f14cbd913415 updated for version 7.0097
vimboss
parents: 233
diff changeset
231 unlet s:cpo_save
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 " Add the Changelog opening mapping
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 nmap <silent> <Leader>o :call <SID>open_changelog()<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 function! s:open_changelog()
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
237 if !filereadable('ChangeLog')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
238 return
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
239 endif
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
240 let buf = bufnr('ChangeLog')
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
241 if buf != -1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
242 if bufwinnr(buf) != -1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
243 execute buf . 'wincmd w'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 else
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
245 execute 'bsplit' buf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 endif
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
247 else
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
248 split ChangeLog
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
249 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
251 call s:new_changelog_entry()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 endif