diff --git a/ftplugin/timesheet.vim b/ftplugin/timesheet.vim index 49f2928..0e032e2 100644 --- a/ftplugin/timesheet.vim +++ b/ftplugin/timesheet.vim @@ -1,26 +1,24 @@ -" Create a new entry. -" followed_by: string to append after the timestamp -" optional parameter: set to false (e.g. 0) to _not_ go into insert mode -" afterwards -function! s:NewTimesheetEntry(followed_by, ...) - let l:insertmode = get(a:, 1, 1) +" Create a new timestamp entry at the end of the file. +function! s:NewTimesheetEntry() " Go to the end of the file, because that's the only place where " inserting a new timestamped item makes sense. - normal G + call cursor(line('$'), 0) " Look backwards for a date. let l:dateline = search('\v^\d{4}-\d{2}-\d{2}:$', 'bcnw') " If there's none or it's not the current day, create one. if !l:dateline || getline(l:dateline) != strftime("%Y-%m-%d:") - execute "normal o\n" . strftime("%Y-%m-%d:") + call append(line('$'), '') + call append(line('$'), strftime("%Y-%m-%d:")) endif " Insert the timestamp and start insert mode. - execute "normal o" . strftime("%H%M") . a:followed_by - if l:insertmode - startinsert! - endif + call append(line('$'), strftime("%H%M")) endfunction +nnoremap (Timesheet) :call NewTimesheetEntry() + " Some mappings to insert a timestamped new line. -nnoremap n :call NewTimesheetEntry(' ') -nnoremap s :call NewTimesheetEntry('.', 0) -nnoremap c :call NewTimesheetEntry('^', 0) +if !hasmapto('(Timesheet)') + nmap n (Timesheet)GA + nmap s (Timesheet)GA. + nmap c (Timesheet)GA^ +endif