diff options
author | Teddy Wing | 2021-10-06 19:20:25 +0200 |
---|---|---|
committer | Teddy Wing | 2021-10-06 20:33:36 +0200 |
commit | 5292cf4d78fdd39743518ad83e264e7e3cc0686d (patch) | |
tree | 45ffd799b2771fe11dbad5aad5d3e00f6f682d24 /projects | |
parent | 1e97570f54c86a9238baf4bb4eb3a82e6f3874a9 (diff) | |
download | dotvim-5292cf4d78fdd39743518ad83e264e7e3cc0686d.tar.bz2 |
projects/aodocs.vim: Make `s:TodoCopyLast()` work for second entry
When only a single TODO day entry exists in a file, this function would
fail with a "pattern not found" error because the copy pattern expects
at least two entries in a file. Alter the function so that it also works
when only one entry is present in the file.
Diffstat (limited to 'projects')
-rw-r--r-- | projects/aodocs.vim | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/projects/aodocs.vim b/projects/aodocs.vim index b965ce4..971d3c8 100644 --- a/projects/aodocs.vim +++ b/projects/aodocs.vim @@ -90,13 +90,24 @@ endfunction function! s:TodoCopyLast() - " Copy the last entry to the bottom - ?\n\n\d?,$t$ - - " Move to date line - ?\n\n\zs\d? - - " Increment day, then put the current entry at the top of the window - call setline('.', strftime('%Y.%m.%d:')) - execute "normal! zt2\<C-e>" + try + " Copy the last entry to the bottom + ?\n\n\d?,$t$ + + " We only have a single entry (pattern not found error). + catch /^Vim\%((\a\+)\)\?:E486: .*\\n\\n\\d/ + " Add two lines to the end of the file. + call append('$', ['', '']) + + " Copy the only entry to the bottom. + 0,$-2t$ + + finally + " Move to date line + ?\n\n\zs\d? + + " Increment day, then put the current entry at the top of the window + call setline('.', strftime('%Y.%m.%d:')) + execute "normal! zt2\<C-e>" + endtry endfunction |