Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created February 17, 2010 08:38
Show Gist options
  • Save mmisono/306433 to your computer and use it in GitHub Desktop.
Save mmisono/306433 to your computer and use it in GitHub Desktop.
--- changelog.vim.old 2010-02-17 17:10:26.000000000 +0900
+++ changelog.vim.new 2010-02-17 17:32:43.000000000 +0900
@@ -121,12 +121,12 @@
" Format used for new date entries.
if !exists('g:changelog_new_date_format')
- let g:changelog_new_date_format = "%d %u\n\n\t* %c\n\n"
+ let g:changelog_new_date_format = "%d %u\n\n\t*%p %c\n\n"
endif
" Format used for new entries to current date entry.
if !exists('g:changelog_new_entry_format')
- let g:changelog_new_entry_format = "\t* %c"
+ let g:changelog_new_entry_format = "\t*%p %c"
endif
" Regular expression used to find a given date entry.
@@ -142,9 +142,9 @@
" Substitutes specific items in new date-entry formats and search strings.
" Can be done with substitute of course, but unclean, and need \@! then.
- function! s:substitute_items(str, date, user)
+ function! s:substitute_items(str, date, user, prefix)
let str = a:str
- let middles = {'%': '%', 'd': a:date, 'u': a:user, 'c': '{cursor}'}
+ let middles = {'%': '%', 'd': a:date, 'u': a:user, 'c': '{cursor}', 'p': a:prefix}
let i = stridx(str, '%')
while i != -1
let inc = 0
@@ -170,7 +170,8 @@
endfunction
" Internal function to create a new entry in the ChangeLog.
- function! s:new_changelog_entry()
+ function! s:new_changelog_entry(...)
+ let prefix = a:0 >= 1 ? a:1 : ''
" Deal with 'paste' option.
let save_paste = &paste
let &paste = 1
@@ -178,7 +179,7 @@
" Look for an entry for today by our user.
let date = strftime(g:changelog_dateformat)
let search = s:substitute_items(g:changelog_date_entry_search, date,
- \ g:changelog_username)
+ \ g:changelog_username, prefix)
if search(search) > 0
" Ok, now we look for the end of the date entry, and add an entry.
call cursor(nextnonblank(line('.') + 1), 1)
@@ -187,7 +188,7 @@
else
let p = line('.')
endif
- let ls = split(s:substitute_items(g:changelog_new_entry_format, '', ''),
+ let ls = split(s:substitute_items(g:changelog_new_entry_format, '', '', prefix),
\ '\n')
call append(p, ls)
call cursor(p + 1, 1)
@@ -197,7 +198,7 @@
" No entry today, so create a date-user header and insert an entry.
let todays_entry = s:substitute_items(g:changelog_new_date_format,
- \ date, g:changelog_username)
+ \ date, g:changelog_username, prefix)
" Make sure we have a cursor positioning.
if stridx(todays_entry, '{cursor}') == -1
let todays_entry = todays_entry . '{cursor}'
@@ -270,13 +271,17 @@
endwhile
endif
if !filereadable(changelog)
- return
+ let changelog = '/Users/mfumi/memo/changelog.diary'
endif
if exists('b:changelog_entry_prefix')
let prefix = call(b:changelog_entry_prefix, [])
else
- let prefix = substitute(strpart(expand('%:p'), strlen(path)), '^/\+', "", "") . ':'
+ if !(changelog == '/Users/mfumi/memo/changelog.diary')
+ let prefix = substitute(strpart(expand('%:p'), strlen(path)), '^/\+', "", "") . ':'
+ else
+ let prefix = ''
+ endif
endif
if !empty(prefix)
let prefix = ' ' . prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment